-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
142 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Checkbox, FormControlLabel, FormGroup, Typography } from '@mui/material' | ||
import { InputWrapper } from 'components/ui/Inputs/styles' | ||
import React, { useEffect, useState } from 'react' | ||
import { LabelObject } from 'types/searchCriterias' | ||
import { isChecked, toggleFilter } from 'utils/filters' | ||
|
||
type CheckboxGroupProps<T> = { | ||
value: T[] | ||
label?: string | ||
disabled?: boolean | ||
options: LabelObject[] | ||
onChange: (value: T[]) => void | ||
} | ||
|
||
const CheckboxGroup = <T extends string>({ | ||
value, | ||
label, | ||
options, | ||
onChange, | ||
disabled = false | ||
}: CheckboxGroupProps<T>) => { | ||
const [inputs, setInputs] = useState(value) | ||
|
||
useEffect(() => { | ||
onChange(inputs) | ||
}, [inputs]) | ||
|
||
return ( | ||
<InputWrapper> | ||
{label && <Typography variant="h3">{label}</Typography>} | ||
<FormGroup | ||
row={true} | ||
onChange={(e) => setInputs(toggleFilter(inputs, (e.target as HTMLInputElement).value as T))} | ||
> | ||
<> | ||
{options.map((option) => ( | ||
<FormControlLabel | ||
key={option.id} | ||
disabled={disabled} | ||
checked={isChecked(option.id, inputs)} | ||
value={option.id} | ||
control={<Checkbox color="secondary" />} | ||
label={option.label} | ||
/> | ||
))} | ||
</> | ||
</FormGroup> | ||
</InputWrapper> | ||
) | ||
} | ||
|
||
export default CheckboxGroup |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Grid, TextField, Typography } from '@mui/material' | ||
import { InputWrapper } from 'components/ui/Inputs/styles' | ||
import { ErrorMessage } from 'components/ui/Inputs/Errors' | ||
import React, { useEffect, useState } from 'react' | ||
|
||
type TextInputProps = { | ||
value?: string | ||
label?: string | ||
placeholder?: string | ||
disabled?: boolean | ||
minLimit?: number | ||
maxLimit?: number | ||
onChange: (newInput: string) => void | ||
onError?: (isError: boolean) => void | ||
} | ||
|
||
const TextInput = ({ | ||
value = '', | ||
placeholder = '', | ||
label, | ||
disabled, | ||
minLimit, | ||
maxLimit, | ||
onChange, | ||
onError | ||
}: TextInputProps) => { | ||
const [input, setFiltersName] = useState(value) | ||
const [isError, setIsError] = useState({ min: false, max: false }) | ||
|
||
useEffect(() => { | ||
if (onError) { | ||
onError(false) | ||
if (isError.min || isError.max) onError(true) | ||
} | ||
}, [isError]) | ||
|
||
useEffect(() => { | ||
let min = false | ||
let max = false | ||
if (maxLimit && input.length > maxLimit) max = true | ||
else if (minLimit && input.length < minLimit) min = true | ||
onChange(input) | ||
setIsError({ min, max }) | ||
}, [input]) | ||
|
||
return ( | ||
<> | ||
<InputWrapper> | ||
{label && <Typography variant="h3">{label}</Typography>} | ||
<TextField | ||
margin="normal" | ||
fullWidth | ||
autoFocus | ||
disabled={disabled} | ||
value={input} | ||
placeholder={placeholder || 'Non renseigné'} | ||
onChange={(event) => setFiltersName(event.target.value)} | ||
/> | ||
</InputWrapper> | ||
{isError.max && ( | ||
<Grid> | ||
<ErrorMessage>Le champ dépasse la limite de {maxLimit} caractères.</ErrorMessage> | ||
</Grid> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default TextInput |
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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