mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-11 00:33:04 +00:00
migration vers typescript + refonte total de l'app
This commit is contained in:
52
components/selector.tsx
Normal file
52
components/selector.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import { MutableRefObject, useState } from "react";
|
||||
|
||||
interface SelectorProps {
|
||||
name: string;
|
||||
label?: string;
|
||||
labelComponent?: JSX.Element;
|
||||
innerRef?: MutableRefObject<any>;
|
||||
fieldClass?: string;
|
||||
value?: string | number;
|
||||
onChangeCallback: ({ target }, value) => void;
|
||||
children?: any;
|
||||
}
|
||||
|
||||
export default function Selector({
|
||||
name,
|
||||
label,
|
||||
labelComponent,
|
||||
innerRef = null,
|
||||
fieldClass = '',
|
||||
value,
|
||||
onChangeCallback,
|
||||
children
|
||||
}: SelectorProps): JSX.Element {
|
||||
const [inputValue, setInputValue] = useState<string | number>(value);
|
||||
|
||||
function onChange({ target }) {
|
||||
setInputValue(target.value);
|
||||
onChangeCallback({ target }, 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>
|
||||
)}
|
||||
<select
|
||||
id={name}
|
||||
name={name}
|
||||
onChange={onChange}
|
||||
value={inputValue}
|
||||
ref={innerRef}
|
||||
>
|
||||
{children}
|
||||
</select>
|
||||
</div>);
|
||||
}
|
||||
Reference in New Issue
Block a user