-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(libs/form-builder): add conditional fields (#36)
- Loading branch information
Showing
20 changed files
with
726 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
apps/demo/src/app/examples/with-material-ui/dictionary/checkBox.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as React from 'react'; | ||
import { Ref, useMemo } from 'react'; | ||
import { FieldErrors } from 'react-hook-form'; | ||
|
||
import FormGroup from '@mui/material/FormGroup'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import MUICheckbox from '@mui/material/Checkbox'; | ||
import Box from '@mui/material/Box'; | ||
|
||
export const Checkbox = ({ | ||
'data-testid': dataTestId, | ||
errorMessage, | ||
errors, | ||
id, | ||
label, | ||
name, | ||
onBlur, | ||
onChange, | ||
optionalText, | ||
propRef, | ||
value | ||
}: { | ||
'data-testid': string; | ||
errorMessage: string; | ||
errors: FieldErrors; | ||
id: string; | ||
label: string; | ||
name: string; | ||
onBlur: (event: any) => void; | ||
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void; | ||
optionalText?: string; | ||
propRef: Ref<any>; | ||
type?: string; | ||
value?: boolean; | ||
}) => { | ||
const inputProps = useMemo( | ||
() => ({ ref: propRef, 'aria-label': 'controlled' }), | ||
[propRef] | ||
); | ||
const error = errors && errors.type && errorMessage; | ||
|
||
return ( | ||
<Box sx={{ m: 2 }}> | ||
<FormGroup> | ||
<FormControlLabel | ||
label={label} | ||
control={ | ||
<MUICheckbox | ||
checked={!!value} | ||
id={id} | ||
name={name} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
inputProps={inputProps} | ||
data-testid={dataTestId} | ||
/> | ||
} | ||
/> | ||
</FormGroup> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
apps/demo/src/app/examples/with-styled-components/dictionary/checkBox.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const Checkbox = ({ | ||
onChange, | ||
value, | ||
label, | ||
...props | ||
}: { | ||
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void; | ||
value: boolean; | ||
label: string; | ||
}) => { | ||
return ( | ||
<div> | ||
<label>{label}</label> | ||
<input type="checkbox" checked={value} onChange={onChange} /> | ||
</div> | ||
); | ||
}; |
Empty file.
28 changes: 28 additions & 0 deletions
28
apps/demo/src/app/examples/with-styled-components/dictionary/select.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export const Select = ({ | ||
onChange, | ||
value, | ||
label, | ||
choices, | ||
multiple | ||
}: { | ||
onChange: (event: React.ChangeEvent<HTMLSelectElement>) => void; | ||
value: string | number; | ||
label: string; | ||
choices: string[] | number[]; | ||
multiple?: boolean; | ||
}) => { | ||
return ( | ||
<div style={{ margin: '24px' }}> | ||
<label> | ||
{label} | ||
<select multiple={multiple} value={value} onChange={onChange}> | ||
{choices.map((choice) => ( | ||
<option key={choice} value={choice}> | ||
{choice} | ||
</option> | ||
))} | ||
</select> | ||
</label> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.