MCPcopy Create free account
hub / github.com/developmentseed/stac-react / Checkbox

Function Checkbox

example/src/components/form/Checkbox.jsx:5–43  ·  view source on GitHub ↗
({ label, name, options, values, onChange })

Source from the content-addressed store, hash-verified

3import Legend from './Legend';
4
5function Checkbox({ label, name, options, values, onChange }) {
6 const handleChange = useCallback(
7 (event) => {
8 const { value } = event.target;
9
10 const nextValues = values.includes(value)
11 ? values.filter((v) => v !== value)
12 : [...values, value];
13
14 onChange(nextValues);
15 },
16 [values, onChange]
17 );
18
19 return (
20 <fieldset>
21 <Legend>{label}</Legend>
22 {options.map(({ value, label: optionLabel }) => {
23 const fieldId = `${name}-${value}`;
24
25 return (
26 <div className="block" key={fieldId}>
27 <input
28 id={fieldId}
29 name={name}
30 value={value}
31 type="checkbox"
32 onChange={handleChange}
33 checked={values.includes(value)}
34 />
35 <label htmlFor={fieldId} className="ml-2">
36 {optionLabel}
37 </label>
38 </div>
39 );
40 })}
41 </fieldset>
42 );
43}
44
45Checkbox.propTypes = {
46 label: T.string.isRequired,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected