import React, { useState } from 'react'; export interface SelectMultiProps { choices: string[]; label?: string; default?: string | string[]; onchange: (value: string | string[]) => void; } export const SelectMulti: React.FC = ({ choices, label = '', default: initial, onchange }) => { const [value, setValue] = useState( Array.isArray(initial) ? initial : (initial ? [initial] : []) ); const handleChange = (e: React.ChangeEvent) => { const choice = e.target.value; let newValue: string[]; if (e.target.checked) { newValue = [...value, choice]; } else { newValue = value.filter(v => v !== choice); } setValue(newValue); onchange(newValue); }; return (
{label &&
{label}
}
{choices.map((choice) => ( ))}
); };