mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
- Ajout création, édition, suppression catégories & liens - Ajout auth google - Ajout/modification style pour catégories & liens - Ajout component générique pour bouton, inputs, checkbox & selector - Gestion des messages d'erreur/succès/infos via component dédié - Ajout component FormLayout pour les pages création, édition, suppression catégories & liens - Page custom 404, 500 & signin - Modification schéma DB
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { MutableRefObject, useState } from 'react';
|
|
|
|
interface SelectorProps {
|
|
name: string;
|
|
label?: string;
|
|
labelComponent?: JSX.Element;
|
|
disabled?: boolean;
|
|
innerRef?: MutableRefObject<any>;
|
|
placeholder?: string;
|
|
fieldClass?: string;
|
|
isChecked?: boolean;
|
|
onChangeCallback?: (value, { target }) => void;
|
|
}
|
|
|
|
export default function Selector({
|
|
name,
|
|
label,
|
|
labelComponent,
|
|
disabled = false,
|
|
innerRef = null,
|
|
fieldClass = '',
|
|
placeholder = 'Type something...',
|
|
isChecked,
|
|
onChangeCallback
|
|
}: SelectorProps): JSX.Element {
|
|
const [checkboxValue, setCheckboxValue] = useState<boolean>(isChecked);
|
|
|
|
function onChange({ target }) {
|
|
setCheckboxValue(!checkboxValue);
|
|
if (onChangeCallback) {
|
|
onChangeCallback(!checkboxValue, { target });
|
|
}
|
|
}
|
|
|
|
return (<div className={`checkbox-field ${fieldClass}`}>
|
|
{label && (
|
|
<label htmlFor={name} title={`${name} field`}>
|
|
{label}
|
|
</label>
|
|
)}
|
|
{labelComponent && (
|
|
<label htmlFor={name} title={`${name} field`}>
|
|
{labelComponent}
|
|
</label>
|
|
)}
|
|
<input
|
|
type='checkbox'
|
|
id={name}
|
|
name={name}
|
|
onChange={onChange}
|
|
checked={checkboxValue}
|
|
placeholder={placeholder}
|
|
ref={innerRef}
|
|
disabled={disabled}
|
|
/>
|
|
</div>);
|
|
} |