Download frontend/src/components/DomainMultiSelect.tsx from Smart-Slate/Systematic-tool-review: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/components/DomainMultiSelect.tsx
- Command line
-
hf download hf://spaces/Smart-Slate/Systematic-tool-review/frontend/src/components/DomainMultiSelect.tsx
-
curl -L -o DomainMultiSelect.tsx https://huggingface.co/spaces/Smart-Slate/Systematic-tool-review/resolve/main/frontend/src/components/DomainMultiSelect.tsx
2.27 kB
| import type { ReviewDomain } from "../types"; | |
| interface DomainOption { | |
| value: ReviewDomain; | |
| label: string; | |
| } | |
| interface DomainMultiSelectProps { | |
| options: DomainOption[]; | |
| value: ReviewDomain[]; | |
| onChange: (value: ReviewDomain[]) => void; | |
| } | |
| /** Checkbox panel for choosing one or more review domains. Selected values are | |
| * always kept in the order of the options, so the same choice never looks like | |
| * a change just because it was ticked in a different order. */ | |
| export function DomainMultiSelect({ options, value, onChange }: DomainMultiSelectProps) { | |
| const allSelected = options.length > 0 && value.length === options.length; | |
| function commit(next: ReviewDomain[]) { | |
| onChange(options.filter((o) => next.includes(o.value)).map((o) => o.value)); | |
| } | |
| function toggle(domain: ReviewDomain) { | |
| commit(value.includes(domain) ? value.filter((v) => v !== domain) : [...value, domain]); | |
| } | |
| const summary = | |
| value.length === 0 | |
| ? "Choose review domain(s)" | |
| : allSelected | |
| ? "All domains selected" | |
| : `${value.length} selected`; | |
| const chosenLabels = options.filter((o) => value.includes(o.value)).map((o) => o.label); | |
| return ( | |
| <details className="domain-multiselect"> | |
| <summary>{summary}</summary> | |
| <div className="domain-multiselect-actions"> | |
| <button | |
| type="button" | |
| className="change-btn" | |
| disabled={allSelected || options.length === 0} | |
| onClick={() => commit(options.map((o) => o.value))} | |
| > | |
| Select all | |
| </button> | |
| <button | |
| type="button" | |
| className="change-btn" | |
| disabled={value.length === 0} | |
| onClick={() => commit([])} | |
| > | |
| Clear | |
| </button> | |
| </div> | |
| <div className="domain-multiselect-list"> | |
| {options.map((o) => ( | |
| <label key={o.value} className="source-checkbox"> | |
| <input | |
| type="checkbox" | |
| checked={value.includes(o.value)} | |
| onChange={() => toggle(o.value)} | |
| /> | |
| {o.label} | |
| </label> | |
| ))} | |
| </div> | |
| {chosenLabels.length > 0 && !allSelected && ( | |
| <div className="form-hint">{chosenLabels.join(", ")}</div> | |
| )} | |
| </details> | |
| ); | |
| } | |