mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-30 08:04:18 +00:00
94 lines
1.7 KiB
TypeScript
94 lines
1.7 KiB
TypeScript
import * as React from "react"
|
|
import {
|
|
Combobox,
|
|
ComboboxChip,
|
|
ComboboxChips,
|
|
ComboboxChipsInput,
|
|
ComboboxContent,
|
|
ComboboxEmpty,
|
|
ComboboxItem,
|
|
ComboboxList,
|
|
ComboboxValue,
|
|
useComboboxAnchor,
|
|
} from "@/examples/base/ui/combobox"
|
|
import { Select } from "@/examples/base/ui/select"
|
|
|
|
const frameworks = [
|
|
"Next.js",
|
|
"SvelteKit",
|
|
"Nuxt.js",
|
|
"Remix",
|
|
"Astro",
|
|
] as const
|
|
|
|
const items = [
|
|
{
|
|
label: "Select a framework",
|
|
value: null,
|
|
},
|
|
{
|
|
label: "React",
|
|
value: "react",
|
|
},
|
|
{
|
|
label: "Vue",
|
|
value: "vue",
|
|
},
|
|
{
|
|
label: "Angular",
|
|
value: "angular",
|
|
},
|
|
{
|
|
label: "Svelte",
|
|
value: "svelte",
|
|
},
|
|
{
|
|
label: "Solid",
|
|
value: "solid",
|
|
},
|
|
{
|
|
label: "Preact",
|
|
value: "preact",
|
|
},
|
|
{
|
|
label: "Next.js",
|
|
value: "next.js",
|
|
},
|
|
]
|
|
|
|
export function ComboboxMultiple() {
|
|
const anchor = useComboboxAnchor()
|
|
|
|
return (
|
|
<Combobox
|
|
multiple
|
|
autoHighlight
|
|
items={frameworks}
|
|
defaultValue={[frameworks[0]]}
|
|
>
|
|
<ComboboxChips ref={anchor}>
|
|
<ComboboxValue>
|
|
{(values) => (
|
|
<React.Fragment>
|
|
{values.map((value: string) => (
|
|
<ComboboxChip key={value}>{value}</ComboboxChip>
|
|
))}
|
|
<ComboboxChipsInput />
|
|
</React.Fragment>
|
|
)}
|
|
</ComboboxValue>
|
|
</ComboboxChips>
|
|
<ComboboxContent anchor={anchor}>
|
|
<ComboboxEmpty>No items found.</ComboboxEmpty>
|
|
<ComboboxList>
|
|
{(item) => (
|
|
<ComboboxItem key={item} value={item}>
|
|
{item}
|
|
</ComboboxItem>
|
|
)}
|
|
</ComboboxList>
|
|
</ComboboxContent>
|
|
</Combobox>
|
|
)
|
|
}
|