blob: 2b1756c893027e552f47fa0f58f812a22738b694 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import { useSelectorOptions } from "@/utilities";
import { FunctionComponent } from "react";
import { MultiSelector, MultiSelectorProps } from "./Selector";
export type ChipInputProps = Omit<
MultiSelectorProps<string>,
| "searchable"
| "creatable"
| "getCreateLabel"
| "onCreate"
| "options"
| "getkey"
>;
const ChipInput: FunctionComponent<ChipInputProps> = ({ ...props }) => {
const { value, onChange } = props;
const options = useSelectorOptions(value ?? [], (v) => v);
return (
<MultiSelector
{...props}
{...options}
creatable
searchable
getCreateLabel={(query) => `Add "${query}"`}
onCreate={(query) => {
onChange?.([...(value ?? []), query]);
return query;
}}
></MultiSelector>
);
};
export default ChipInput;
|