1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2025-01-10 17:47:41 +01:00
smov/src/components/text-inputs/TextInputControl.tsx
2023-08-20 17:59:46 +02:00

45 lines
859 B
TypeScript

export interface TextInputControlPropsNoLabel {
onChange?: (data: string) => void;
onUnFocus?: () => void;
onFocus?: () => void;
value?: string;
placeholder?: string;
className?: string;
}
export interface TextInputControlProps extends TextInputControlPropsNoLabel {
label?: string;
}
export function TextInputControl({
onChange,
onUnFocus,
value,
label,
className,
placeholder,
onFocus,
}: TextInputControlProps) {
const input = (
<input
type="text"
className={className}
placeholder={placeholder}
onChange={(e) => onChange && onChange(e.target.value)}
value={value}
onBlur={() => onUnFocus && onUnFocus()}
onFocus={() => onFocus?.()}
/>
);
if (label) {
return (
<label>
<span>{label}</span>
{input}
</label>
);
}
return input;
}