mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +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
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { MutableRefObject, useState } from 'react';
|
|
|
|
interface InputProps {
|
|
name: string;
|
|
label?: string;
|
|
labelComponent?: JSX.Element;
|
|
disabled?: boolean;
|
|
type?: string;
|
|
multiple?: boolean;
|
|
innerRef?: MutableRefObject<any>;
|
|
placeholder?: string;
|
|
fieldClass?: string;
|
|
value?: string;
|
|
onChangeCallback?: (value) => void;
|
|
}
|
|
|
|
export default function TextBox({
|
|
name,
|
|
label,
|
|
labelComponent,
|
|
disabled = false,
|
|
type = 'text',
|
|
multiple = false,
|
|
innerRef = null,
|
|
placeholder = 'Type something...',
|
|
fieldClass = '',
|
|
value,
|
|
onChangeCallback
|
|
}: InputProps): JSX.Element {
|
|
const [inputValue, setInputValue] = useState<string>(value);
|
|
|
|
function onChange({ target }) {
|
|
setInputValue(target.value);
|
|
if (onChangeCallback) {
|
|
onChangeCallback(target.value);
|
|
}
|
|
}
|
|
|
|
return (<div className={`input-field ${fieldClass}`}>
|
|
{label && (
|
|
<label htmlFor={name} title={`${name} field`}>
|
|
{label}
|
|
</label>
|
|
)}
|
|
{labelComponent && (
|
|
<label htmlFor={name} title={`${name} field`}>
|
|
{labelComponent}
|
|
</label>
|
|
)}
|
|
<input
|
|
id={name}
|
|
name={name}
|
|
type={type}
|
|
onChange={onChange}
|
|
value={inputValue}
|
|
multiple={multiple}
|
|
placeholder={placeholder}
|
|
ref={innerRef}
|
|
disabled={disabled}
|
|
/>
|
|
</div>);
|
|
} |