| { | |
| "name": "combobox", | |
| "snippet": null, | |
| "examples": [ | |
| { | |
| "name": "combobox-autohighlight", | |
| "content": "\"use client\"\nexport const ComboboxAutoHighlight = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n inputBehavior=\"autohighlight\"\n width=\"320px\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-basic", | |
| "content": "\"use client\"\nexport const ComboboxBasic = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-color-picker", | |
| "content": "\"use client\"\nexport const ComboboxColorPicker = () => {\n const [selectedColor, setSelectedColor] = useState<ColorItem | null>(null)\n\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: colors,\n filter: contains,\n itemToValue: (item) => item.id,\n itemToString: (item) => item.name,\n })\n\n const handleValueChange = (details: Combobox.ValueChangeDetails) => {\n setSelectedColor(details.items[0] || null)\n }\n\n const handleInputValueChange = (\n details: Combobox.InputValueChangeDetails,\n ) => {\n filter(details.inputValue)\n }\n\n return (\n <Combobox.Root\n maxW=\"320px\"\n collection={collection}\n placeholder=\"Color\"\n onValueChange={handleValueChange}\n onInputValueChange={handleInputValueChange}\n >\n <Combobox.Label srOnly>Select Color</Combobox.Label>\n <Stack direction=\"row\" align=\"center\" gap={3}>\n <Combobox.Control>\n <Combobox.Input />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n {selectedColor && <ColorSwatch value={selectedColor.value} />}\n </Stack>\n\n <Combobox.Content>\n <Combobox.ItemGroup>\n <Combobox.ItemGroupLabel>Color</Combobox.ItemGroupLabel>\n {collection.items.map((color) => (\n <Combobox.Item item={color} key={color.id}>\n <HStack direction=\"row\" gap={3} align=\"center\">\n <ColorSwatch value={color.value} boxSize=\"6\" />\n <HStack gap=\"1\" flex=\"1\">\n <Text fontWeight=\"medium\">{color.name}</Text>\n <Text color=\"fg.muted\" textStyle=\"sm\">\n {color.value}\n </Text>\n </HStack>\n </HStack>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.ItemGroup>\n </Combobox.Content>\n </Combobox.Root>\n )\n}\n\ninterface ColorItem {\n id: string\n name: string\n value: string\n}\n\nconst colors: ColorItem[] = [\n { id: \"red\", name: \"Red\", value: \"#EF4444\" },\n { id: \"blue\", name: \"Blue\", value: \"#3B82F6\" },\n { id: \"green\", name: \"Green\", value: \"#10B981\" },\n { id: \"purple\", name: \"Purple\", value: \"#8B5CF6\" },\n { id: \"yellow\", name: \"Yellow\", value: \"#F59E0B\" },\n { id: \"pink\", name: \"Pink\", value: \"#EC4899\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n ColorSwatch,\n Combobox,\n HStack,\n Stack,\n Text,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useState } from \"react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-controlled", | |
| "content": "\"use client\"\nexport const ComboboxControlled = () => {\n const [value, setValue] = useState<string[]>([])\n\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n value={value}\n onValueChange={(e) => setValue(e.value)}\n width=\"320px\"\n >\n <HStack textStyle=\"sm\" mb=\"6\">\n Selected:\n <HStack>\n <For each={value} fallback=\"N/A\">\n {(v) => <Badge key={v}>{v}</Badge>}\n </For>\n </HStack>\n </HStack>\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Badge,\n Combobox,\n For,\n HStack,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useState } from \"react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-in-popover", | |
| "content": "\"use client\"\nexport const ComboboxInPopover = () => {\n return (\n <Popover.Root size=\"xs\">\n <Popover.Trigger asChild>\n <Button variant=\"outline\" size=\"sm\">\n Toggle popover\n </Button>\n </Popover.Trigger>\n <Portal>\n <Popover.Positioner>\n <Popover.Content>\n <Popover.Header>Select framework</Popover.Header>\n <Popover.Body>\n <ComboboxDemo />\n </Popover.Body>\n </Popover.Content>\n </Popover.Positioner>\n </Portal>\n </Popover.Root>\n )\n}\n\nconst ComboboxDemo = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n >\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Button,\n Combobox,\n Popover,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-min-character", | |
| "content": "\"use client\"\nexport const ComboboxMinCharacter = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n openOnChange={(e) => e.inputValue.length > 2}\n width=\"320px\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-open-controlled", | |
| "content": "\"use client\"\nexport const ComboboxOpenControlled = () => {\n const [open, setOpen] = useState(false)\n\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n open={open}\n onOpenChange={(e) => setOpen(e.open)}\n >\n <Combobox.Label>Combobox is {open ? \"open\" : \"closed\"}</Combobox.Label>\n\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useState } from \"react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-open-on-click", | |
| "content": "\"use client\"\nexport const ComboboxOpenOnClick = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n openOnClick\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-rehydrate-value", | |
| "content": "\"use client\"\nexport const ComboboxRehydrateValue = () => {\n const [inputValue, setInputValue] = useState(\"\")\n\n const { collection, set } = useListCollection<Character>({\n initialItems: [],\n itemToString: (item) => item.name,\n itemToValue: (item) => item.name,\n })\n\n const combobox = useCombobox({\n collection,\n defaultValue: [\"C-3PO\"],\n placeholder: \"Example: Dexter\",\n inputValue,\n onInputValueChange: (e) => setInputValue(e.inputValue),\n })\n\n const state = useAsync(async () => {\n const response = await fetch(\n `https://swapi.py4e.com/api/people/?search=${inputValue}`,\n )\n const data = await response.json()\n set(data.results)\n }, [inputValue, set])\n\n // Rehydrate the value\n const hydrated = useRef(false)\n if (combobox.value.length && collection.size && !hydrated.current) {\n combobox.syncSelectedItems()\n hydrated.current = true\n }\n\n return (\n <Combobox.RootProvider value={combobox} width=\"320px\">\n <Combobox.Label>Search Star Wars Characters</Combobox.Label>\n\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n {state.loading ? (\n <HStack p=\"2\">\n <Spinner size=\"xs\" />\n <Span>Loading...</Span>\n </HStack>\n ) : state.error ? (\n <Span p=\"2\" color=\"fg.error\">\n {state.error.message}\n </Span>\n ) : (\n <For\n each={collection.items}\n fallback={<Combobox.Empty>No items</Combobox.Empty>}\n >\n {(item) => (\n <Combobox.Item key={item.name} item={item}>\n <HStack justify=\"space-between\" textStyle=\"sm\">\n <Span fontWeight=\"medium\">{item.name}</Span>\n <Span color=\"fg.muted\">\n {item.height}cm / {item.mass}kg\n </Span>\n </HStack>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n )}\n </For>\n )}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.RootProvider>\n )\n}\n\ninterface Character {\n name: string\n height: string\n mass: string\n created: string\n edited: string\n url: string\n}\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n For,\n HStack,\n Portal,\n Span,\n Spinner,\n useCombobox,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useRef, useState } from \"react\"", | |
| "import { useAsync } from \"react-use\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"", | |
| "npmDependencies": [ | |
| "react-use" | |
| ] | |
| }, | |
| { | |
| "name": "combobox-virtualized", | |
| "content": "\"use client\"\nexport const ComboboxVirtualized = () => {\n const contentRef = useRef<HTMLDivElement>(null)\n\n const { startsWith } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter, reset } = useListCollection({\n initialItems: items,\n filter: startsWith,\n })\n\n const virtualizer = useVirtualizer({\n count: collection.size,\n getScrollElement: () => contentRef.current,\n estimateSize: () => 28,\n overscan: 10,\n scrollPaddingEnd: 32,\n })\n\n const handleScrollToIndexFn = (details: { index: number }) => {\n flushSync(() => {\n virtualizer.scrollToIndex(details.index, {\n align: \"center\",\n behavior: \"auto\",\n })\n })\n }\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n scrollToIndexFn={handleScrollToIndexFn}\n width=\"320px\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger onClick={reset} />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content ref={contentRef}>\n <div\n style={{\n height: `${virtualizer.getTotalSize()}px`,\n width: \"100%\",\n position: \"relative\",\n }}\n >\n {virtualizer.getVirtualItems().map((virtualItem) => {\n const item = collection.items[virtualItem.index]\n return (\n <Combobox.Item\n key={item.value}\n item={item}\n style={{\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n height: `${virtualItem.size}px`,\n transform: `translateY(${virtualItem.start}px)`,\n whiteSpace: \"nowrap\",\n overflow: \"hidden\",\n textOverflow: \"ellipsis\",\n }}\n >\n <Combobox.ItemText truncate>\n <span aria-hidden style={{ marginRight: 4 }}>\n {item.emoji}\n </span>\n {item.label}\n </Combobox.ItemText>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n )\n })}\n </div>\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nexport const items = [\n { value: \"AD\", label: \"Andorra\", emoji: \"🇦🇩\" },\n { value: \"AE\", label: \"United Arab Emirates\", emoji: \"🇦🇪\" },\n { value: \"AF\", label: \"Afghanistan\", emoji: \"🇦🇫\" },\n { value: \"AG\", label: \"Antigua and Barbuda\", emoji: \"🇦🇬\" },\n { value: \"AI\", label: \"Anguilla\", emoji: \"🇦🇮\" },\n { value: \"AL\", label: \"Albania\", emoji: \"🇦🇱\" },\n { value: \"AM\", label: \"Armenia\", emoji: \"🇦🇲\" },\n { value: \"AO\", label: \"Angola\", emoji: \"🇦🇴\" },\n { value: \"AQ\", label: \"Antarctica\", emoji: \"🇦🇶\" },\n { value: \"AR\", label: \"Argentina\", emoji: \"🇦🇷\" },\n { value: \"AS\", label: \"American Samoa\", emoji: \"🇦🇸\" },\n { value: \"AT\", label: \"Austria\", emoji: \"🇦🇹\" },\n { value: \"AU\", label: \"Australia\", emoji: \"🇦🇺\" },\n { value: \"AW\", label: \"Aruba\", emoji: \"🇦🇼\" },\n { value: \"AX\", label: \"Åland Islands\", emoji: \"🇦🇽\" },\n { value: \"AZ\", label: \"Azerbaijan\", emoji: \"🇦🇿\" },\n { value: \"BA\", label: \"Bosnia and Herzegovina\", emoji: \"🇧🇦\" },\n { value: \"BB\", label: \"Barbados\", emoji: \"🇧🇧\" },\n { value: \"BD\", label: \"Bangladesh\", emoji: \"🇧🇩\" },\n { value: \"BE\", label: \"Belgium\", emoji: \"🇧🇪\" },\n { value: \"BF\", label: \"Burkina Faso\", emoji: \"🇧🇫\" },\n { value: \"BG\", label: \"Bulgaria\", emoji: \"🇧🇬\" },\n { value: \"BH\", label: \"Bahrain\", emoji: \"🇧🇭\" },\n { value: \"BI\", label: \"Burundi\", emoji: \"🇧🇮\" },\n { value: \"BJ\", label: \"Benin\", emoji: \"🇧🇯\" },\n { value: \"BL\", label: \"Saint Barthélemy\", emoji: \"🇧🇱\" },\n { value: \"BM\", label: \"Bermuda\", emoji: \"🇧🇲\" },\n { value: \"BN\", label: \"Brunei Darussalam\", emoji: \"🇧🇳\" },\n { value: \"BO\", label: \"Bolivia, Plurinational State of\", emoji: \"🇧🇴\" },\n { value: \"BQ\", label: \"Bonaire, Sint Eustatius and Saba\", emoji: \"🇧🇶\" },\n { value: \"BR\", label: \"Brazil\", emoji: \"🇧🇷\" },\n { value: \"BS\", label: \"Bahamas\", emoji: \"🇧🇸\" },\n { value: \"BT\", label: \"Bhutan\", emoji: \"🇧🇹\" },\n { value: \"BV\", label: \"Bouvet Island\", emoji: \"🇧🇻\" },\n { value: \"BW\", label: \"Botswana\", emoji: \"🇧🇼\" },\n { value: \"BY\", label: \"Belarus\", emoji: \"🇧🇾\" },\n { value: \"BZ\", label: \"Belize\", emoji: \"🇧🇿\" },\n { value: \"CA\", label: \"Canada\", emoji: \"🇨🇦\" },\n { value: \"CC\", label: \"Cocos (Keeling) Islands\", emoji: \"🇨🇨\" },\n { value: \"CD\", label: \"Congo, Democratic Republic of the\", emoji: \"🇨🇩\" },\n { value: \"CF\", label: \"Central African Republic\", emoji: \"🇨🇫\" },\n { value: \"CG\", label: \"Congo\", emoji: \"🇨🇬\" },\n { value: \"CH\", label: \"Switzerland\", emoji: \"🇨🇭\" },\n { value: \"CI\", label: \"Côte d'Ivoire\", emoji: \"🇨🇮\" },\n { value: \"CK\", label: \"Cook Islands\", emoji: \"🇨🇰\" },\n { value: \"CL\", label: \"Chile\", emoji: \"🇨🇱\" },\n { value: \"CM\", label: \"Cameroon\", emoji: \"🇨🇲\" },\n { value: \"CN\", label: \"China\", emoji: \"🇨🇳\" },\n { value: \"CO\", label: \"Colombia\", emoji: \"🇨🇴\" },\n { value: \"CR\", label: \"Costa Rica\", emoji: \"🇨🇷\" },\n { value: \"CU\", label: \"Cuba\", emoji: \"🇨🇺\" },\n { value: \"CV\", label: \"Cabo Verde\", emoji: \"🇨🇻\" },\n { value: \"CW\", label: \"Curaçao\", emoji: \"🇨🇼\" },\n { value: \"CX\", label: \"Christmas Island\", emoji: \"🇨🇽\" },\n { value: \"CY\", label: \"Cyprus\", emoji: \"🇨🇾\" },\n { value: \"CZ\", label: \"Czechia\", emoji: \"🇨🇿\" },\n { value: \"DE\", label: \"Germany\", emoji: \"🇩🇪\" },\n { value: \"DJ\", label: \"Djibouti\", emoji: \"🇩🇯\" },\n { value: \"DK\", label: \"Denmark\", emoji: \"🇩🇰\" },\n { value: \"DM\", label: \"Dominica\", emoji: \"🇩🇲\" },\n { value: \"DO\", label: \"Dominican Republic\", emoji: \"🇩🇴\" },\n { value: \"DZ\", label: \"Algeria\", emoji: \"🇩🇿\" },\n { value: \"EC\", label: \"Ecuador\", emoji: \"🇪🇨\" },\n { value: \"EE\", label: \"Estonia\", emoji: \"🇪🇪\" },\n { value: \"EG\", label: \"Egypt\", emoji: \"🇪🇬\" },\n { value: \"EH\", label: \"Western Sahara\", emoji: \"🇪🇭\" },\n { value: \"ER\", label: \"Eritrea\", emoji: \"🇪🇷\" },\n { value: \"ES\", label: \"Spain\", emoji: \"🇪🇸\" },\n { value: \"ET\", label: \"Ethiopia\", emoji: \"🇪🇹\" },\n { value: \"FI\", label: \"Finland\", emoji: \"🇫🇮\" },\n { value: \"FJ\", label: \"Fiji\", emoji: \"🇫🇯\" },\n { value: \"FK\", label: \"Falkland Islands (Malvinas)\", emoji: \"🇫🇰\" },\n { value: \"FM\", label: \"Micronesia, Federated States of\", emoji: \"🇫🇲\" },\n { value: \"FO\", label: \"Faroe Islands\", emoji: \"🇫🇴\" },\n { value: \"FR\", label: \"France\", emoji: \"🇫🇷\" },\n { value: \"GA\", label: \"Gabon\", emoji: \"🇬🇦\" },\n {\n value: \"GB\",\n label: \"United Kingdom of Great Britain and Northern Ireland\",\n emoji: \"🇬🇧\",\n },\n { value: \"GD\", label: \"Grenada\", emoji: \"🇬🇩\" },\n { value: \"GE\", label: \"Georgia\", emoji: \"🇬🇪\" },\n { value: \"GF\", label: \"French Guiana\", emoji: \"🇬🇫\" },\n { value: \"GG\", label: \"Guernsey\", emoji: \"🇬🇬\" },\n { value: \"GH\", label: \"Ghana\", emoji: \"🇬🇭\" },\n { value: \"GI\", label: \"Gibraltar\", emoji: \"🇬🇮\" },\n { value: \"GL\", label: \"Greenland\", emoji: \"🇬🇱\" },\n { value: \"GM\", label: \"Gambia\", emoji: \"🇬🇲\" },\n { value: \"GN\", label: \"Guinea\", emoji: \"🇬🇳\" },\n { value: \"GP\", label: \"Guadeloupe\", emoji: \"🇬🇵\" },\n { value: \"GQ\", label: \"Equatorial Guinea\", emoji: \"🇬🇶\" },\n { value: \"GR\", label: \"Greece\", emoji: \"🇬🇷\" },\n {\n value: \"GS\",\n label: \"South Georgia and the South Sandwich Islands\",\n emoji: \"🇬🇸\",\n },\n { value: \"GT\", label: \"Guatemala\", emoji: \"🇬🇹\" },\n { value: \"GU\", label: \"Guam\", emoji: \"🇬🇺\" },\n { value: \"GW\", label: \"Guinea-Bissau\", emoji: \"🇬🇼\" },\n { value: \"GY\", label: \"Guyana\", emoji: \"🇬🇾\" },\n { value: \"HK\", label: \"Hong Kong\", emoji: \"🇭🇰\" },\n { value: \"HM\", label: \"Heard Island and McDonald Islands\", emoji: \"🇭🇲\" },\n { value: \"HN\", label: \"Honduras\", emoji: \"🇭🇳\" },\n { value: \"HR\", label: \"Croatia\", emoji: \"🇭🇷\" },\n { value: \"HT\", label: \"Haiti\", emoji: \"🇭🇹\" },\n { value: \"HU\", label: \"Hungary\", emoji: \"🇭🇺\" },\n { value: \"ID\", label: \"Indonesia\", emoji: \"🇮🇩\" },\n { value: \"IE\", label: \"Ireland\", emoji: \"🇮🇪\" },\n { value: \"IL\", label: \"Israel\", emoji: \"🇮🇱\" },\n { value: \"IM\", label: \"Isle of Man\", emoji: \"🇮🇲\" },\n { value: \"IN\", label: \"India\", emoji: \"🇮🇳\" },\n { value: \"IO\", label: \"British Indian Ocean Territory\", emoji: \"🇮🇴\" },\n { value: \"IQ\", label: \"Iraq\", emoji: \"🇮🇶\" },\n { value: \"IR\", label: \"Iran, Islamic Republic of\", emoji: \"🇮🇷\" },\n { value: \"IS\", label: \"Iceland\", emoji: \"🇮🇸\" },\n { value: \"IT\", label: \"Italy\", emoji: \"🇮🇹\" },\n { value: \"JE\", label: \"Jersey\", emoji: \"🇯🇪\" },\n { value: \"JM\", label: \"Jamaica\", emoji: \"🇯🇲\" },\n { value: \"JO\", label: \"Jordan\", emoji: \"🇯🇴\" },\n { value: \"JP\", label: \"Japan\", emoji: \"🇯🇵\" },\n { value: \"KE\", label: \"Kenya\", emoji: \"🇰🇪\" },\n { value: \"KG\", label: \"Kyrgyzstan\", emoji: \"🇰🇬\" },\n { value: \"KH\", label: \"Cambodia\", emoji: \"🇰🇭\" },\n { value: \"KI\", label: \"Kiribati\", emoji: \"🇰🇮\" },\n { value: \"KM\", label: \"Comoros\", emoji: \"🇰🇲\" },\n { value: \"KN\", label: \"Saint Kitts and Nevis\", emoji: \"🇰🇳\" },\n { value: \"KP\", label: \"Korea, Democratic People's Republic of\", emoji: \"🇰🇵\" },\n { value: \"KR\", label: \"Korea, Republic of\", emoji: \"🇰🇷\" },\n { value: \"KW\", label: \"Kuwait\", emoji: \"🇰🇼\" },\n { value: \"KY\", label: \"Cayman Islands\", emoji: \"🇰🇾\" },\n { value: \"KZ\", label: \"Kazakhstan\", emoji: \"🇰🇿\" },\n { value: \"LA\", label: \"Lao People's Democratic Republic\", emoji: \"🇱🇦\" },\n { value: \"LB\", label: \"Lebanon\", emoji: \"🇱🇧\" },\n { value: \"LC\", label: \"Saint Lucia\", emoji: \"🇱🇨\" },\n { value: \"LI\", label: \"Liechtenstein\", emoji: \"🇱🇮\" },\n { value: \"LK\", label: \"Sri Lanka\", emoji: \"🇱🇰\" },\n { value: \"LR\", label: \"Liberia\", emoji: \"🇱🇷\" },\n { value: \"LS\", label: \"Lesotho\", emoji: \"🇱🇸\" },\n { value: \"LT\", label: \"Lithuania\", emoji: \"🇱🇹\" },\n { value: \"LU\", label: \"Luxembourg\", emoji: \"🇱🇺\" },\n { value: \"LV\", label: \"Latvia\", emoji: \"🇱🇻\" },\n { value: \"LY\", label: \"Libya\", emoji: \"🇱🇾\" },\n { value: \"MA\", label: \"Morocco\", emoji: \"🇲🇦\" },\n { value: \"MC\", label: \"Monaco\", emoji: \"🇲🇨\" },\n { value: \"MD\", label: \"Moldova, Republic of\", emoji: \"🇲🇩\" },\n { value: \"ME\", label: \"Montenegro\", emoji: \"🇲🇪\" },\n { value: \"MF\", label: \"Saint Martin, (French part)\", emoji: \"🇲🇫\" },\n { value: \"MG\", label: \"Madagascar\", emoji: \"🇲🇬\" },\n { value: \"MH\", label: \"Marshall Islands\", emoji: \"🇲🇭\" },\n { value: \"MK\", label: \"North Macedonia\", emoji: \"🇲🇰\" },\n { value: \"ML\", label: \"Mali\", emoji: \"🇲🇱\" },\n { value: \"MM\", label: \"Myanmar\", emoji: \"🇲🇲\" },\n { value: \"MN\", label: \"Mongolia\", emoji: \"🇲🇳\" },\n { value: \"MO\", label: \"Macao\", emoji: \"🇲🇴\" },\n { value: \"MP\", label: \"Northern Mariana Islands\", emoji: \"🇲🇵\" },\n { value: \"MQ\", label: \"Martinique\", emoji: \"🇲🇶\" },\n { value: \"MR\", label: \"Mauritania\", emoji: \"🇲🇷\" },\n { value: \"MS\", label: \"Montserrat\", emoji: \"🇲🇸\" },\n { value: \"MT\", label: \"Malta\", emoji: \"🇲🇹\" },\n { value: \"MU\", label: \"Mauritius\", emoji: \"🇲🇺\" },\n { value: \"MV\", label: \"Maldives\", emoji: \"🇲🇻\" },\n { value: \"MW\", label: \"Malawi\", emoji: \"🇲🇼\" },\n { value: \"MX\", label: \"Mexico\", emoji: \"🇲🇽\" },\n { value: \"MY\", label: \"Malaysia\", emoji: \"🇲🇾\" },\n { value: \"MZ\", label: \"Mozambique\", emoji: \"🇲🇿\" },\n { value: \"NA\", label: \"Namibia\", emoji: \"🇳🇦\" },\n { value: \"NC\", label: \"New Caledonia\", emoji: \"🇳🇨\" },\n { value: \"NE\", label: \"Niger\", emoji: \"🇳🇪\" },\n { value: \"NF\", label: \"Norfolk Island\", emoji: \"🇳🇫\" },\n { value: \"NG\", label: \"Nigeria\", emoji: \"🇳🇬\" },\n { value: \"NI\", label: \"Nicaragua\", emoji: \"🇳🇮\" },\n { value: \"NL\", label: \"Netherlands\", emoji: \"🇳🇱\" },\n { value: \"NO\", label: \"Norway\", emoji: \"🇳🇴\" },\n { value: \"NP\", label: \"Nepal\", emoji: \"🇳🇵\" },\n { value: \"NR\", label: \"Nauru\", emoji: \"🇳🇷\" },\n { value: \"NU\", label: \"Niue\", emoji: \"🇳🇺\" },\n { value: \"NZ\", label: \"New Zealand\", emoji: \"🇳🇿\" },\n { value: \"OM\", label: \"Oman\", emoji: \"🇴🇲\" },\n { value: \"PA\", label: \"Panama\", emoji: \"🇵🇦\" },\n { value: \"PE\", label: \"Peru\", emoji: \"🇵🇪\" },\n { value: \"PF\", label: \"French Polynesia\", emoji: \"🇵🇫\" },\n { value: \"PG\", label: \"Papua New Guinea\", emoji: \"🇵🇬\" },\n { value: \"PH\", label: \"Philippines\", emoji: \"🇵🇭\" },\n { value: \"PK\", label: \"Pakistan\", emoji: \"🇵🇰\" },\n { value: \"PL\", label: \"Poland\", emoji: \"🇵🇱\" },\n { value: \"PM\", label: \"Saint Pierre and Miquelon\", emoji: \"🇵🇲\" },\n { value: \"PN\", label: \"Pitcairn\", emoji: \"🇵🇳\" },\n { value: \"PR\", label: \"Puerto Rico\", emoji: \"🇵🇷\" },\n { value: \"PS\", label: \"Palestine, State of\", emoji: \"🇵🇸\" },\n { value: \"PT\", label: \"Portugal\", emoji: \"🇵🇹\" },\n { value: \"PW\", label: \"Palau\", emoji: \"🇵🇼\" },\n { value: \"PY\", label: \"Paraguay\", emoji: \"🇵🇾\" },\n { value: \"QA\", label: \"Qatar\", emoji: \"🇶🇦\" },\n { value: \"RE\", label: \"Réunion\", emoji: \"🇷🇪\" },\n { value: \"RO\", label: \"Romania\", emoji: \"🇷🇴\" },\n { value: \"RS\", label: \"Serbia\", emoji: \"🇷🇸\" },\n { value: \"RU\", label: \"Russian Federation\", emoji: \"🇷🇺\" },\n { value: \"RW\", label: \"Rwanda\", emoji: \"🇷🇼\" },\n { value: \"SA\", label: \"Saudi Arabia\", emoji: \"🇸🇦\" },\n { value: \"SB\", label: \"Solomon Islands\", emoji: \"🇸🇧\" },\n { value: \"SC\", label: \"Seychelles\", emoji: \"🇸🇨\" },\n { value: \"SD\", label: \"Sudan\", emoji: \"🇸🇩\" },\n { value: \"SE\", label: \"Sweden\", emoji: \"🇸🇪\" },\n { value: \"SG\", label: \"Singapore\", emoji: \"🇸🇬\" },\n {\n value: \"SH\",\n label: \"Saint Helena, Ascension and Tristan da Cunha\",\n emoji: \"🇸🇭\",\n },\n { value: \"SI\", label: \"Slovenia\", emoji: \"🇸🇮\" },\n { value: \"SJ\", label: \"Svalbard and Jan Mayen\", emoji: \"🇸🇯\" },\n { value: \"SK\", label: \"Slovakia\", emoji: \"🇸🇰\" },\n { value: \"SL\", label: \"Sierra Leone\", emoji: \"🇸🇱\" },\n { value: \"SM\", label: \"San Marino\", emoji: \"🇸🇲\" },\n { value: \"SN\", label: \"Senegal\", emoji: \"🇸🇳\" },\n { value: \"SO\", label: \"Somalia\", emoji: \"🇸🇴\" },\n { value: \"SR\", label: \"Suriname\", emoji: \"🇸🇷\" },\n { value: \"SS\", label: \"South Sudan\", emoji: \"🇸🇸\" },\n { value: \"ST\", label: \"Sao Tome and Principe\", emoji: \"🇸🇹\" },\n { value: \"SV\", label: \"El Salvador\", emoji: \"🇸🇻\" },\n { value: \"SX\", label: \"Sint Maarten, (Dutch part)\", emoji: \"🇸🇽\" },\n { value: \"SY\", label: \"Syrian Arab Republic\", emoji: \"🇸🇾\" },\n { value: \"SZ\", label: \"Eswatini\", emoji: \"🇸🇿\" },\n { value: \"TC\", label: \"Turks and Caicos Islands\", emoji: \"🇹🇨\" },\n { value: \"TD\", label: \"Chad\", emoji: \"🇹🇩\" },\n { value: \"TF\", label: \"French Southern Territories\", emoji: \"🇹🇫\" },\n { value: \"TG\", label: \"Togo\", emoji: \"🇹🇬\" },\n { value: \"TH\", label: \"Thailand\", emoji: \"🇹🇭\" },\n { value: \"TJ\", label: \"Tajikistan\", emoji: \"🇹🇯\" },\n { value: \"TK\", label: \"Tokelau\", emoji: \"🇹🇰\" },\n { value: \"TL\", label: \"Timor-Leste\", emoji: \"🇹🇱\" },\n { value: \"TM\", label: \"Turkmenistan\", emoji: \"🇹🇲\" },\n { value: \"TN\", label: \"Tunisia\", emoji: \"🇹🇳\" },\n { value: \"TO\", label: \"Tonga\", emoji: \"🇹🇴\" },\n { value: \"TR\", label: \"Türkiye\", emoji: \"🇹🇷\" },\n { value: \"TT\", label: \"Trinidad and Tobago\", emoji: \"🇹🇹\" },\n { value: \"TV\", label: \"Tuvalu\", emoji: \"🇹🇻\" },\n { value: \"TW\", label: \"Taiwan, Province of China\", emoji: \"🇹🇼\" },\n { value: \"TZ\", label: \"Tanzania, United Republic of\", emoji: \"🇹🇿\" },\n { value: \"UA\", label: \"Ukraine\", emoji: \"🇺🇦\" },\n { value: \"UG\", label: \"Uganda\", emoji: \"🇺🇬\" },\n { value: \"UM\", label: \"United States Minor Outlying Islands\", emoji: \"🇺🇲\" },\n { value: \"US\", label: \"United States of America\", emoji: \"🇺🇸\" },\n { value: \"UY\", label: \"Uruguay\", emoji: \"🇺🇾\" },\n { value: \"UZ\", label: \"Uzbekistan\", emoji: \"🇺🇿\" },\n { value: \"VA\", label: \"Holy See\", emoji: \"🇻🇦\" },\n { value: \"VC\", label: \"Saint Vincent and the Grenadines\", emoji: \"🇻🇨\" },\n { value: \"VE\", label: \"Venezuela, Bolivarian Republic of\", emoji: \"🇻🇪\" },\n { value: \"VG\", label: \"Virgin Islands, British\", emoji: \"🇻🇬\" },\n { value: \"VI\", label: \"Virgin Islands, U.S.\", emoji: \"🇻🇮\" },\n { value: \"VN\", label: \"Viet Nam\", emoji: \"🇻🇳\" },\n { value: \"VU\", label: \"Vanuatu\", emoji: \"🇻🇺\" },\n { value: \"WF\", label: \"Wallis and Futuna\", emoji: \"🇼🇫\" },\n { value: \"WS\", label: \"Samoa\", emoji: \"🇼🇸\" },\n { value: \"YE\", label: \"Yemen\", emoji: \"🇾🇪\" },\n { value: \"YT\", label: \"Mayotte\", emoji: \"🇾🇹\" },\n { value: \"ZA\", label: \"South Africa\", emoji: \"🇿🇦\" },\n { value: \"ZM\", label: \"Zambia\", emoji: \"🇿🇲\" },\n { value: \"ZW\", label: \"Zimbabwe\", emoji: \"🇿🇼\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useVirtualizer } from \"@tanstack/react-virtual\"", | |
| "import { useRef } from \"react\"", | |
| "import { flushSync } from \"react-dom\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"", | |
| "npmDependencies": [ | |
| "@tanstack/react-virtual" | |
| ] | |
| }, | |
| { | |
| "name": "combobox-with-async-content", | |
| "content": "\"use client\"\nexport const ComboboxWithAsyncContent = () => {\n const [inputValue, setInputValue] = useState(\"\")\n\n const { collection, set } = useListCollection<Character>({\n initialItems: [],\n itemToString: (item) => item.name,\n itemToValue: (item) => item.name,\n })\n\n const state = useAsync(async () => {\n const response = await fetch(\n `https://swapi.py4e.com/api/people/?search=${inputValue}`,\n )\n const data = await response.json()\n set(data.results)\n }, [inputValue, set])\n\n return (\n <Combobox.Root\n width=\"320px\"\n collection={collection}\n placeholder=\"Example: C-3PO\"\n onInputValueChange={(e) => setInputValue(e.inputValue)}\n positioning={{ sameWidth: false, placement: \"bottom-start\" }}\n >\n <Combobox.Label>Search Star Wars Characters</Combobox.Label>\n\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content minW=\"sm\">\n {state.loading ? (\n <HStack p=\"2\">\n <Spinner size=\"xs\" borderWidth=\"1px\" />\n <Span>Loading...</Span>\n </HStack>\n ) : state.error ? (\n <Span p=\"2\" color=\"fg.error\">\n Error fetching\n </Span>\n ) : (\n collection.items?.map((character) => (\n <Combobox.Item key={character.name} item={character}>\n <HStack justify=\"space-between\" textStyle=\"sm\">\n <Span fontWeight=\"medium\" truncate>\n {character.name}\n </Span>\n <Span color=\"fg.muted\" truncate>\n {character.height}cm / {character.mass}kg\n </Span>\n </HStack>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))\n )}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\ninterface Character {\n name: string\n height: string\n mass: string\n created: string\n edited: string\n url: string\n}\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n HStack,\n Portal,\n Span,\n Spinner,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useState } from \"react\"", | |
| "import { useAsync } from \"react-use\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"", | |
| "npmDependencies": [ | |
| "react-use" | |
| ] | |
| }, | |
| { | |
| "name": "combobox-with-createable-options", | |
| "content": "\"use client\"\n\ninterface Tag {\n id: string\n name: string\n custom?: boolean\n}\n\nconst defaultTags: Tag[] = [\n { id: \"react\", name: \"react\" },\n { id: \"typescript\", name: \"typescript\" },\n { id: \"javascript\", name: \"javascript\" },\n { id: \"nextjs\", name: \"nextjs\" },\n]\n\nexport const ComboboxWithCreateableOptions = () => {\n const [tags, setTags] = useState<Tag[]>(defaultTags)\n const [inputValue, setInputValue] = useState(\"\")\n const [value, setValue] = useState<string[]>([])\n\n const collection = useMemo(\n () =>\n createListCollection({\n items: tags,\n itemToString: (item) => item.name,\n itemToValue: (item) => item.id,\n }),\n [tags],\n )\n\n const handleValueChange = (details: Combobox.ValueChangeDetails) => {\n const selectedValue = details.value[0]\n\n const selectedTag = collection.find(selectedValue)\n\n const tempTags = tags.map((tag) => {\n if (tag.id === \"custom\" && selectedTag) {\n return { id: selectedTag.name, name: selectedTag.name, custom: true }\n }\n\n return tag\n })\n\n setValue(\n selectedValue === \"custom\" && selectedTag\n ? [selectedTag?.name]\n : details.value,\n )\n setTags(tempTags)\n\n setInputValue(selectedTag?.name ?? \"\")\n }\n\n const handleInputChange = (details: Combobox.InputValueChangeDetails) => {\n const value = details.inputValue\n\n if (!value) {\n return\n }\n\n const newTag: Tag = {\n id: \"custom\",\n name: value,\n }\n\n setTags((prev) => {\n if (collection.has(\"custom\")) {\n return prev.map((tag) => {\n if (tag.id === \"custom\") {\n return newTag\n }\n return tag\n })\n }\n\n return [newTag, ...prev]\n })\n\n setInputValue(value)\n }\n\n return (\n <Stack gap={4} maxW=\"320px\">\n <Combobox.Root\n allowCustomValue\n value={value}\n collection={collection}\n inputValue={inputValue}\n selectionBehavior=\"preserve\"\n placeholder=\"Type to search or create...\"\n onValueChange={handleValueChange}\n onInputValueChange={handleInputChange}\n >\n <Combobox.Label>Add Tags</Combobox.Label>\n\n <Combobox.Control>\n <Combobox.Input />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n {collection.items.map((tag) => {\n if (tag.id === \"custom\") {\n return (\n <Combobox.Item item={tag} key={tag.id}>\n <Stack direction=\"row\" align=\"center\" gap={2}>\n <Icon asChild fontSize={16} color=\"blue.500\">\n <svg\n width=\"24\"\n height=\"24\"\n fill=\"none\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M5 12h14\" />\n <path d=\"M12 5v14\" />\n </svg>\n </Icon>\n <Text>Create "{inputValue}"</Text>\n </Stack>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n )\n }\n\n return (\n <Combobox.Item key={tag.id} item={tag}>\n <HStack\n direction=\"row\"\n justify=\"space-between\"\n align=\"center\"\n >\n <Stack direction=\"row\" align=\"center\" gap={2}>\n <Text fontWeight=\"medium\">{tag.name}</Text>\n {tag.custom && (\n <Text\n fontSize=\"xs\"\n color=\"blue.500\"\n fontWeight=\"medium\"\n >\n CUSTOM\n </Text>\n )}\n </Stack>\n </HStack>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n )\n })}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n\n <Stack>\n <Text fontWeight=\"medium\">Current Tags:</Text>\n <Stack direction=\"row\" flexWrap=\"wrap\" gap={2}>\n {tags.map((tag) => (\n <Text\n key={tag.id}\n px={2}\n py={1}\n fontSize=\"sm\"\n borderRadius=\"md\"\n backgroundColor={tag.custom ? \"blue.100\" : \"gray.100\"}\n >\n {tag.name}\n </Text>\n ))}\n </Stack>\n </Stack>\n </Stack>\n )\n}\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n HStack,\n Icon,\n Portal,\n Stack,\n Text,\n createListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useMemo, useState } from \"react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-custom-animation", | |
| "content": "\"use client\"\nexport const ComboboxWithCustomAnimation = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n positioning={{ flip: false, gutter: 2 }}\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content\n _open={{ animationStyle: \"scale-fade-in\" }}\n _closed={{\n animationStyle: \"scale-fade-out\",\n animationDuration: \"fast\",\n }}\n >\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-custom-filter", | |
| "content": "\"use client\"\nexport const ComboboxWithCustomFilter = () => {\n const { collection, set } = useListCollection({\n initialItems: people,\n itemToString: (item) => item.name,\n itemToValue: (item) => item.id.toString(),\n })\n\n const handleInputChange = (details: Combobox.InputValueChangeDetails) => {\n const filteredItems = people.filter((item) => {\n const searchLower = details.inputValue.toLowerCase()\n const nameParts = item.name.toLowerCase().split(\" \")\n const emailParts = item.email.toLowerCase().split(\"@\")[0].split(\".\")\n\n return (\n item.name.toLowerCase().includes(searchLower) ||\n nameParts.some((part) => part.includes(searchLower)) ||\n emailParts.some((part) => part.includes(searchLower)) ||\n item.role.toLowerCase().includes(searchLower)\n )\n })\n set(filteredItems)\n }\n\n return (\n <Combobox.Root\n width=\"320px\"\n collection={collection}\n inputBehavior=\"autocomplete\"\n placeholder=\"Search by name, email, or role...\"\n onInputValueChange={handleInputChange}\n >\n <Combobox.Label>Select Person</Combobox.Label>\n\n <Combobox.Control>\n <Combobox.Input />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No matches found</Combobox.Empty>\n {collection.items.map((person) => (\n <Combobox.Item item={person} key={person.id}>\n <Stack gap={0}>\n <Span textStyle=\"sm\" fontWeight=\"medium\">\n {person.name}\n </Span>\n <Span textStyle=\"xs\" color=\"fg.muted\">\n {person.email}\n </Span>\n </Stack>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst people = [\n {\n id: 1,\n name: \"John Smith\",\n email: \"john@example.com\",\n role: \"Sales Manager\",\n },\n {\n id: 2,\n name: \"Sarah Johnson\",\n email: \"sarah@example.com\",\n role: \"UI Designer\",\n },\n {\n id: 3,\n name: \"Michael Brown\",\n email: \"michael@example.com\",\n role: \"Software Engineer\",\n },\n {\n id: 4,\n name: \"Emily Davis\",\n email: \"emily@example.com\",\n role: \"AI Engineer\",\n },\n {\n id: 5,\n name: \"James Wilson\",\n email: \"james@example.com\",\n role: \"Chief Executive Officer\",\n },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n Span,\n Stack,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-custom-item", | |
| "content": "\"use client\"\n\nfunction ComboboxValue() {\n const combobox = useComboboxContext()\n const selectedItems = combobox.selectedItems as (typeof items)[number][]\n return (\n <Stack mt=\"2\">\n {selectedItems.map((item) => (\n <HStack key={item.value} textStyle=\"sm\" p=\"1\" borderWidth=\"1px\">\n <Image\n boxSize=\"10\"\n p=\"2\"\n src={item.logo}\n alt={item.label + \" logo\"}\n />\n <span>{item.label}</span>\n </HStack>\n ))}\n </Stack>\n )\n}\n\nexport const ComboboxWithCustomItem = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: items,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n placeholder=\"Example: Audi\"\n multiple\n closeOnSelect\n >\n <Combobox.Label>Search and select car brands</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input />\n <Combobox.IndicatorGroup>\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <ComboboxValue />\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n <Image boxSize=\"5\" src={item.logo} alt={item.label + \" logo\"} />\n <Span flex=\"1\">{item.label}</Span>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nexport const items = [\n {\n label: \"Audi\",\n value: \"audi\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/audi-logo.png\",\n },\n {\n label: \"BMW\",\n value: \"bmw\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/bmw-logo.png\",\n },\n {\n label: \"Citroen\",\n value: \"citroen\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/citroen-logo.png\",\n },\n {\n label: \"Dacia\",\n value: \"dacia\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/dacia-logo.png\",\n },\n {\n label: \"Fiat\",\n value: \"fiat\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/fiat-logo.png\",\n },\n {\n label: \"Ford\",\n value: \"ford\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/ford-logo.png\",\n },\n {\n label: \"Ferrari\",\n value: \"ferrari\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/ferrari-logo.png\",\n },\n {\n label: \"Honda\",\n value: \"honda\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/honda-logo.png\",\n },\n {\n label: \"Hyundai\",\n value: \"hyundai\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/hyundai-logo.png\",\n },\n {\n label: \"Jaguar\",\n value: \"jaguar\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/jaguar-logo.png\",\n },\n {\n label: \"Jeep\",\n value: \"jeep\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/jeep-logo.png\",\n },\n {\n label: \"Kia\",\n value: \"kia\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/kia-logo.png\",\n },\n {\n label: \"Land Rover\",\n value: \"land rover\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/land-rover-logo.png\",\n },\n {\n label: \"Mazda\",\n value: \"mazda\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/mazda-logo.png\",\n },\n {\n label: \"Mercedes\",\n value: \"mercedes\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/mercedes-logo.png\",\n },\n {\n label: \"Mini\",\n value: \"mini\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/mini-logo.png\",\n },\n {\n label: \"Mitsubishi\",\n value: \"mitsubishi\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/mitsubishi-logo.png\",\n },\n {\n label: \"Nissan\",\n value: \"nissan\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/nissan-logo.png\",\n },\n {\n label: \"Opel\",\n value: \"opel\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/opel-logo.png\",\n },\n {\n label: \"Peugeot\",\n value: \"peugeot\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/peugeot-logo.png\",\n },\n {\n label: \"Porsche\",\n value: \"porsche\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/porsche-logo.png\",\n },\n {\n label: \"Renault\",\n value: \"renault\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/renault-logo.png\",\n },\n {\n label: \"Saab\",\n value: \"saab\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/saab-logo.png\",\n },\n {\n label: \"Skoda\",\n value: \"skoda\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/skoda-logo.png\",\n },\n {\n label: \"Subaru\",\n value: \"subaru\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/subaru-logo.png\",\n },\n {\n label: \"Suzuki\",\n value: \"suzuki\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/suzuki-logo.png\",\n },\n {\n label: \"Toyota\",\n value: \"toyota\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/toyota-logo.png\",\n },\n {\n label: \"Volkswagen\",\n value: \"volkswagen\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/volkswagen-logo.png\",\n },\n {\n label: \"Volvo\",\n value: \"volvo\",\n logo: \"https://s3.amazonaws.com/cdn.formk.it/example-assets/car-brands/volvo-logo.png\",\n },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n HStack,\n Image,\n Portal,\n Span,\n Stack,\n useComboboxContext,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-custom-object", | |
| "content": "\"use client\"\nexport const ComboboxWithCustomObject = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: countries,\n itemToString: (item) => item.country,\n itemToValue: (item) => item.code,\n filter: contains,\n })\n\n const handleInputChange = (details: Combobox.InputValueChangeDetails) => {\n filter(details.inputValue)\n }\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={handleInputChange}\n >\n <Combobox.Label>Search Countries</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"e.g. United States\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n\n {collection.items.map((item) => (\n <Combobox.Item key={item.code} item={item}>\n {item.country}\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst countries = [\n { country: \"United States\", code: \"US\", flag: \"🇺🇸\" },\n { country: \"Canada\", code: \"CA\", flag: \"🇨🇦\" },\n { country: \"Australia\", code: \"AU\", flag: \"🇦🇺\" },\n { country: \"United Kingdom\", code: \"UK\", flag: \"🇬🇧\" },\n { country: \"New Zealand\", code: \"NZ\", flag: \"🇳🇿\" },\n { country: \"South Africa\", code: \"ZA\", flag: \"🇿🇦\" },\n { country: \"India\", code: \"IN\", flag: \"🇮🇳\" },\n { country: \"China\", code: \"CN\", flag: \"🇨🇳\" },\n { country: \"Japan\", code: \"JP\", flag: \"🇯🇵\" },\n { country: \"Korea\", code: \"KR\", flag: \"🇰🇷\" },\n { country: \"Vietnam\", code: \"VN\", flag: \"🇻🇳\" },\n { country: \"Thailand\", code: \"TH\", flag: \"🇹🇭\" },\n { country: \"Malaysia\", code: \"MY\", flag: \"🇲🇾\" },\n { country: \"Indonesia\", code: \"ID\", flag: \"🇮🇩\" },\n { country: \"Philippines\", code: \"PH\", flag: \"🇵🇭\" },\n { country: \"Singapore\", code: \"SG\", flag: \"🇸🇬\" },\n { country: \"Hong Kong\", code: \"HK\", flag: \"🇭🇰\" },\n { country: \"Macau\", code: \"MO\", flag: \"🇲🇴\" },\n { country: \"Taiwan\", code: \"TW\", flag: \"🇹🇼\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-disabled-item", | |
| "content": "\"use client\"\nexport const ComboboxWithDisabledItem = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: companies,\n filter: contains,\n itemToValue: (item) => item.id,\n itemToString: (item) => item.name,\n isItemDisabled: (item) => !!item.disabled,\n })\n\n const handleInputChange = (details: Combobox.InputValueChangeDetails) => {\n filter(details.inputValue)\n }\n\n return (\n <Combobox.Root\n width=\"320px\"\n collection={collection}\n placeholder=\"Type to search companies\"\n onInputValueChange={handleInputChange}\n >\n <Combobox.Label>Select a Company</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.ItemGroup>\n <Combobox.ItemGroupLabel>Companies</Combobox.ItemGroupLabel>\n {collection.items.map((country) => {\n return (\n <Combobox.Item item={country} key={country.id}>\n <HStack gap=\"3\">\n <Icon>{country.logo}</Icon>\n <Span fontWeight=\"medium\">{country.name}</Span>\n </HStack>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n )\n })}\n </Combobox.ItemGroup>\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\ninterface Company {\n id: string\n name: string\n logo: React.ReactElement\n disabled?: boolean\n}\n\nconst companies: Company[] = [\n {\n id: \"airbnb\",\n name: \"Airbnb\",\n logo: (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 18 18\">\n <g clipPath=\"url(#airbnb)\">\n <path fill=\"#EB4C60\" d=\"M0 0h18v18H0V0Z\" />\n <path\n fill=\"#fff\"\n d=\"m13.565 10.777.051.123c.133.372.173.724.092 1.076a2.142 2.142 0 0 1-1.33 1.672 2.095 2.095 0 0 1-1.096.141 2.737 2.737 0 0 1-1.023-.342c-.41-.231-.819-.564-1.269-1.047-.45.483-.85.816-1.27 1.047a2.73 2.73 0 0 1-1.29.362c-.286 0-.562-.05-.828-.16a2.146 2.146 0 0 1-1.33-1.673 2.211 2.211 0 0 1 .122-1.087c.051-.13.103-.252.153-.362l.112-.242.124-.271.011-.02a115.31 115.31 0 0 1 2.261-4.552l.03-.061c.083-.151.165-.312.246-.473a3.45 3.45 0 0 1 .37-.553 1.725 1.725 0 0 1 1.31-.605c.501 0 .972.221 1.299.625.15.167.25.342.344.51l.025.043c.081.161.163.322.246.473l.03.061a104.224 104.224 0 0 1 2.262 4.552l.01.01.124.271.112.242c.034.073.067.156.102.24Zm-5.6-1.227c.123.544.482 1.188 1.035 1.873.552-.695.911-1.339 1.034-1.873.05-.201.06-.41.03-.615a.968.968 0 0 0-.163-.422C9.715 8.232 9.379 8.07 9 8.07a1.092 1.092 0 0 0-.9.443.968.968 0 0 0-.165.423c-.03.205-.019.414.031.615l-.001-.001Zm4.187 3.524c.503-.201.86-.654.932-1.178.037-.26.013-.526-.071-.775a1.97 1.97 0 0 0-.088-.216 5.032 5.032 0 0 1-.046-.107 7.415 7.415 0 0 1-.118-.251 5.735 5.735 0 0 0-.117-.252v-.01a132.7 132.7 0 0 0-2.242-4.53l-.03-.061-.123-.232-.123-.232a2.211 2.211 0 0 0-.287-.443 1.078 1.078 0 0 0-.819-.372 1.078 1.078 0 0 0-.818.372c-.113.136-.21.284-.287.443-.042.077-.083.155-.123.232-.04.079-.082.157-.123.232l-.03.06a109.354 109.354 0 0 0-2.253 4.521l-.01.02a20.74 20.74 0 0 0-.281.61 1.951 1.951 0 0 0-.087.216 1.639 1.639 0 0 0-.092.785 1.5 1.5 0 0 0 .931 1.178c.235.09.502.13.778.1.257-.03.512-.11.778-.26.369-.202.748-.515 1.167-.978-.665-.816-1.084-1.57-1.239-2.235a2.058 2.058 0 0 1-.051-.855c.041-.253.134-.484.277-.685.317-.443.85-.716 1.442-.716.595 0 1.127.263 1.444.716.143.2.235.432.276.685.031.261.021.543-.051.855-.153.665-.563 1.41-1.239 2.225.43.464.8.776 1.167.977.266.15.522.231.778.262.267.03.533 0 .778-.101Z\"\n />\n </g>\n <defs>\n <clipPath id=\"airbnb\">\n <path fill=\"#fff\" d=\"M0 0h18v18H0z\" />\n </clipPath>\n </defs>\n </svg>\n ),\n },\n {\n id: \"tesla\",\n disabled: true,\n logo: (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 18 18\">\n <g clipPath=\"url(#tesla)\">\n <path fill=\"#E31937\" d=\"M0 0h18v18H0V0Z\" />\n <path\n fill=\"#fff\"\n d=\"m9 15 1.5-8c1.334 0 1.654.272 1.715.872 0 0 .894-.335 1.346-1.016C11.8 6.037 10 6 10 6L9 7.25 8 6s-1.8.037-3.56.856c.45.68 1.345 1.016 1.345 1.016.061-.6.39-.871 1.715-.872L9 15Z\"\n />\n <path\n fill=\"#fff\"\n d=\"M9 5.608a11.35 11.35 0 0 1 4.688.955C13.91 6.16 14 6 14 6c-1.823-.724-3.53-.994-5-1-1.47.006-3.177.276-5 1 0 0 .114.2.313.563A11.348 11.348 0 0 1 9 5.608Z\"\n />\n </g>\n <defs>\n <clipPath id=\"tesla\">\n <path fill=\"#fff\" d=\"M0 0h18v18H0z\" />\n </clipPath>\n </defs>\n </svg>\n ),\n name: \"Tesla\",\n },\n {\n logo: (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 18 18\">\n <g clipPath=\"url(#nvidia-a)\">\n <path fill=\"url(#nvidia-b)\" d=\"M0 0h18v18H0V0Z\" />\n <path\n fill=\"#fff\"\n d=\"M7.601 7.57v-.656c.065-.004.13-.008.195-.008 1.797-.057 2.975 1.547 2.975 1.547S9.5 10.218 8.136 10.218c-.183 0-.36-.029-.53-.085V8.14c.7.085.841.393 1.258 1.093l.936-.786s-.685-.894-1.834-.894a2.745 2.745 0 0 0-.365.016Zm0-2.17v.98l.195-.012c2.497-.086 4.13 2.048 4.13 2.048s-1.871 2.275-3.819 2.275c-.17 0-.336-.016-.502-.044v.607c.138.016.28.029.417.029 1.814 0 3.126-.928 4.397-2.02.21.17 1.073.578 1.251.756-1.206 1.012-4.02 1.826-5.615 1.826-.154 0-.3-.008-.446-.024v.854H14.5V5.4H7.601Zm0 4.733v.518c-1.676-.3-2.141-2.045-2.141-2.045s.805-.89 2.141-1.036v.567h-.004c-.7-.085-1.25.57-1.25.57s.31 1.106 1.254 1.426Zm-2.975-1.6s.991-1.465 2.98-1.619V6.38C5.402 6.558 3.5 8.42 3.5 8.42s1.077 3.118 4.101 3.401v-.567c-2.218-.275-2.975-2.72-2.975-2.72Z\"\n />\n </g>\n <defs>\n <linearGradient\n id=\"nvidia-b\"\n x1=\"16\"\n x2=\"5.5\"\n y1=\"-.5\"\n y2=\"18\"\n gradientUnits=\"userSpaceOnUse\"\n >\n <stop stopColor=\"#85B737\" />\n <stop offset=\"1\" stopColor=\"#597B20\" />\n </linearGradient>\n <clipPath id=\"nvidia-a\">\n <path fill=\"#fff\" d=\"M0 0h18v18H0z\" />\n </clipPath>\n </defs>\n </svg>\n ),\n id: \"nvida\",\n name: \"NVIDA\",\n },\n {\n id: \"amazon\",\n name: \"Amazon\",\n logo: (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 18 18\">\n <g clipPath=\"url(#amazon)\">\n <path d=\"M0 0h18v18H0V0Z\" />\n <path\n fill=\"#fff\"\n d=\"M12.237 10.734c-.259-.327-.458-.56-.458-1.189V7.46c0-.88-.06-1.703-.708-2.306-.519-.478-1.373-.654-2.047-.654-1.425 0-2.698.58-3.01 2.137-.026.177.104.252.207.278l1.351.123c.13 0 .208-.125.234-.25.104-.529.572-.972 1.09-.972.285 0 .848.287.848.89v.754c-.83 0-1.757.056-2.483.357-.855.353-1.586 1.028-1.586 2.11 0 1.382 1.064 2.137 2.204 2.137.96 0 1.482-.25 2.232-.979.235.352.38.603.82.979.105.051.234.051.31-.024.26-.228.712-.703.996-.929.13-.102.104-.252 0-.377ZM9.744 8.775c0 .502-.098 1.756-1.368 1.756-.653 0-.666-.769-.666-.769 0-.988 1.049-1.317 2.034-1.317v.33Z\"\n />\n <path\n fill=\"#FFB300\"\n d=\"M12.917 12.952C11.862 13.601 10.284 14 9.005 14a7.818 7.818 0 0 1-4.713-1.551c-.101-.084 0-.168.1-.126 1.432.685 3 1.036 4.587 1.026 1.154 0 2.609-.209 3.787-.628.174-.042.325.126.15.231Zm.376-.44c-.125-.147-.878-.063-1.204-.043-.101 0-.125-.062-.025-.125.576-.357 1.554-.252 1.655-.126.1.126-.026.943-.577 1.32-.076.064-.176.021-.126-.04.126-.253.402-.84.276-.987Z\"\n />\n </g>\n <defs>\n <clipPath id=\"amazon\">\n <path fill=\"#fff\" d=\"M0 0h18v18H0z\" />\n </clipPath>\n </defs>\n </svg>\n ),\n },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n HStack,\n Icon,\n Portal,\n Span,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-disabled", | |
| "content": "\"use client\"\nexport const ComboboxWithDisabled = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n disabled\n width=\"320px\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-field", | |
| "content": "\"use client\"\nexport const ComboboxWithField = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Field.Root width=\"320px\">\n <Field.Label>Select framework</Field.Label>\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n >\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Field.HelperText>The framework you love to use</Field.HelperText>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n </Field.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Field,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-highlight", | |
| "content": "\"use client\"\nexport const ComboboxWithHighlight = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <ComboboxItem item={item} key={item.value} />\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nfunction ComboboxItem(props: { item: { label: string; value: string } }) {\n const { item } = props\n const combobox = useComboboxContext()\n return (\n <Combobox.Item item={item} key={item.value}>\n <Combobox.ItemText>\n <Highlight\n ignoreCase\n query={combobox.inputValue}\n styles={{ bg: \"yellow.emphasized\", fontWeight: \"medium\" }}\n >\n {item.label}\n </Highlight>\n </Combobox.ItemText>\n </Combobox.Item>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Highlight,\n Portal,\n useComboboxContext,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-input-group", | |
| "content": "\"use client\"\nexport const ComboboxWithInputGroup = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <InputGroup startElement={<LuCode />}>\n <Combobox.Input placeholder=\"Type to search\" />\n </InputGroup>\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n InputGroup,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { LuCode } from \"react-icons/lu\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"", | |
| "npmDependencies": [ | |
| "react-icons" | |
| ] | |
| }, | |
| { | |
| "name": "combobox-with-input-in-content", | |
| "content": "\"use client\"\nexport const ComboboxWithInputInContent = () => {\n const [selected, setSelected] = useState<SelectedState>({\n value: [],\n items: [],\n })\n\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { filter, collection } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n const handleInputChange = (details: Combobox.InputValueChangeDetails) => {\n filter(details.inputValue)\n }\n\n const handleValueChange = (details: Combobox.ValueChangeDetails<Item>) => {\n setSelected(details)\n }\n\n return (\n <Combobox.Root\n width=\"200px\"\n collection={collection}\n selectionBehavior=\"clear\"\n inputBehavior=\"autohighlight\"\n onValueChange={handleValueChange}\n onInputValueChange={handleInputChange}\n >\n <Combobox.Control>\n <Combobox.Trigger focusable asChild>\n <Button variant=\"outline\" size=\"sm\" w=\"full\">\n <Span flex=\"1\" textAlign=\"start\">\n <Show when={selected.items.length > 0} fallback=\"Select status\">\n {selected.items.map((item) => item.label).join(\", \")}\n </Show>\n </Span>\n <LuChevronsUpDown />\n </Button>\n </Combobox.Trigger>\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content px=\"0\">\n <Combobox.Input\n mt=\"-1\"\n minH=\"8\"\n px=\"3\"\n border=\"none\"\n outline=\"none\"\n placeholder=\"Search status\"\n />\n <Combobox.ItemGroup borderTopWidth=\"1px\" pt=\"1\" px=\"1\">\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.ItemGroup>\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\ninterface SelectedState {\n value: string[]\n items: Item[]\n}\n\ninterface Item {\n label: string\n value: string\n}\n\nconst frameworks = [\n { label: \"Todo\", value: \"todo\" },\n { label: \"In Progress\", value: \"in-progress\" },\n { label: \"Done\", value: \"done\" },\n { label: \"Blocked\", value: \"blocked\" },\n { label: \"Review\", value: \"review\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Button,\n Combobox,\n Portal,\n Show,\n Span,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useState } from \"react\"", | |
| "import { LuChevronsUpDown } from \"react-icons/lu\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"", | |
| "npmDependencies": [ | |
| "react-icons" | |
| ] | |
| }, | |
| { | |
| "name": "combobox-with-invalid", | |
| "content": "\"use client\"\nexport const ComboboxWithInvalid = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n invalid\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-limit", | |
| "content": "\"use client\"\nexport const ComboboxWithLimit = () => {\n const contentRef = useRef<HTMLDivElement>(null)\n\n const { startsWith } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter, reset } = useListCollection({\n initialItems: items,\n filter: startsWith,\n limit: 10,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n openOnClick\n width=\"320px\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger onClick={reset} />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content ref={contentRef}>\n {collection.items.map((item) => (\n <Combobox.Item key={item.value} item={item}>\n <Combobox.ItemText truncate>\n <span aria-hidden style={{ marginRight: 4 }}>\n {item.emoji}\n </span>\n {item.label}\n </Combobox.ItemText>\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nexport const items = [\n { value: \"AD\", label: \"Andorra\", emoji: \"🇦🇩\" },\n { value: \"AE\", label: \"United Arab Emirates\", emoji: \"🇦🇪\" },\n { value: \"AF\", label: \"Afghanistan\", emoji: \"🇦🇫\" },\n { value: \"AG\", label: \"Antigua and Barbuda\", emoji: \"🇦🇬\" },\n { value: \"AI\", label: \"Anguilla\", emoji: \"🇦🇮\" },\n { value: \"AL\", label: \"Albania\", emoji: \"🇦🇱\" },\n { value: \"AM\", label: \"Armenia\", emoji: \"🇦🇲\" },\n { value: \"AO\", label: \"Angola\", emoji: \"🇦🇴\" },\n { value: \"AQ\", label: \"Antarctica\", emoji: \"🇦🇶\" },\n { value: \"AR\", label: \"Argentina\", emoji: \"🇦🇷\" },\n { value: \"AS\", label: \"American Samoa\", emoji: \"🇦🇸\" },\n { value: \"AT\", label: \"Austria\", emoji: \"🇦🇹\" },\n { value: \"AU\", label: \"Australia\", emoji: \"🇦🇺\" },\n { value: \"AW\", label: \"Aruba\", emoji: \"🇦🇼\" },\n { value: \"AX\", label: \"Åland Islands\", emoji: \"🇦🇽\" },\n { value: \"AZ\", label: \"Azerbaijan\", emoji: \"🇦🇿\" },\n { value: \"BA\", label: \"Bosnia and Herzegovina\", emoji: \"🇧🇦\" },\n { value: \"BB\", label: \"Barbados\", emoji: \"🇧🇧\" },\n { value: \"BD\", label: \"Bangladesh\", emoji: \"🇧🇩\" },\n { value: \"BE\", label: \"Belgium\", emoji: \"🇧🇪\" },\n { value: \"BF\", label: \"Burkina Faso\", emoji: \"🇧🇫\" },\n { value: \"BG\", label: \"Bulgaria\", emoji: \"🇧🇬\" },\n { value: \"BH\", label: \"Bahrain\", emoji: \"🇧🇭\" },\n { value: \"BI\", label: \"Burundi\", emoji: \"🇧🇮\" },\n { value: \"BJ\", label: \"Benin\", emoji: \"🇧🇯\" },\n { value: \"BL\", label: \"Saint Barthélemy\", emoji: \"🇧🇱\" },\n { value: \"BM\", label: \"Bermuda\", emoji: \"🇧🇲\" },\n { value: \"BN\", label: \"Brunei Darussalam\", emoji: \"🇧🇳\" },\n { value: \"BO\", label: \"Bolivia, Plurinational State of\", emoji: \"🇧🇴\" },\n { value: \"BQ\", label: \"Bonaire, Sint Eustatius and Saba\", emoji: \"🇧🇶\" },\n { value: \"BR\", label: \"Brazil\", emoji: \"🇧🇷\" },\n { value: \"BS\", label: \"Bahamas\", emoji: \"🇧🇸\" },\n { value: \"BT\", label: \"Bhutan\", emoji: \"🇧🇹\" },\n { value: \"BV\", label: \"Bouvet Island\", emoji: \"🇧🇻\" },\n { value: \"BW\", label: \"Botswana\", emoji: \"🇧🇼\" },\n { value: \"BY\", label: \"Belarus\", emoji: \"🇧🇾\" },\n { value: \"BZ\", label: \"Belize\", emoji: \"🇧🇿\" },\n { value: \"CA\", label: \"Canada\", emoji: \"🇨🇦\" },\n { value: \"CC\", label: \"Cocos (Keeling) Islands\", emoji: \"🇨🇨\" },\n { value: \"CD\", label: \"Congo, Democratic Republic of the\", emoji: \"🇨🇩\" },\n { value: \"CF\", label: \"Central African Republic\", emoji: \"🇨🇫\" },\n { value: \"CG\", label: \"Congo\", emoji: \"🇨🇬\" },\n { value: \"CH\", label: \"Switzerland\", emoji: \"🇨🇭\" },\n { value: \"CI\", label: \"Côte d'Ivoire\", emoji: \"🇨🇮\" },\n { value: \"CK\", label: \"Cook Islands\", emoji: \"🇨🇰\" },\n { value: \"CL\", label: \"Chile\", emoji: \"🇨🇱\" },\n { value: \"CM\", label: \"Cameroon\", emoji: \"🇨🇲\" },\n { value: \"CN\", label: \"China\", emoji: \"🇨🇳\" },\n { value: \"CO\", label: \"Colombia\", emoji: \"🇨🇴\" },\n { value: \"CR\", label: \"Costa Rica\", emoji: \"🇨🇷\" },\n { value: \"CU\", label: \"Cuba\", emoji: \"🇨🇺\" },\n { value: \"CV\", label: \"Cabo Verde\", emoji: \"🇨🇻\" },\n { value: \"CW\", label: \"Curaçao\", emoji: \"🇨🇼\" },\n { value: \"CX\", label: \"Christmas Island\", emoji: \"🇨🇽\" },\n { value: \"CY\", label: \"Cyprus\", emoji: \"🇨🇾\" },\n { value: \"CZ\", label: \"Czechia\", emoji: \"🇨🇿\" },\n { value: \"DE\", label: \"Germany\", emoji: \"🇩🇪\" },\n { value: \"DJ\", label: \"Djibouti\", emoji: \"🇩🇯\" },\n { value: \"DK\", label: \"Denmark\", emoji: \"🇩🇰\" },\n { value: \"DM\", label: \"Dominica\", emoji: \"🇩🇲\" },\n { value: \"DO\", label: \"Dominican Republic\", emoji: \"🇩🇴\" },\n { value: \"DZ\", label: \"Algeria\", emoji: \"🇩🇿\" },\n { value: \"EC\", label: \"Ecuador\", emoji: \"🇪🇨\" },\n { value: \"EE\", label: \"Estonia\", emoji: \"🇪🇪\" },\n { value: \"EG\", label: \"Egypt\", emoji: \"🇪🇬\" },\n { value: \"EH\", label: \"Western Sahara\", emoji: \"🇪🇭\" },\n { value: \"ER\", label: \"Eritrea\", emoji: \"🇪🇷\" },\n { value: \"ES\", label: \"Spain\", emoji: \"🇪🇸\" },\n { value: \"ET\", label: \"Ethiopia\", emoji: \"🇪🇹\" },\n { value: \"FI\", label: \"Finland\", emoji: \"🇫🇮\" },\n { value: \"FJ\", label: \"Fiji\", emoji: \"🇫🇯\" },\n { value: \"FK\", label: \"Falkland Islands (Malvinas)\", emoji: \"🇫🇰\" },\n { value: \"FM\", label: \"Micronesia, Federated States of\", emoji: \"🇫🇲\" },\n { value: \"FO\", label: \"Faroe Islands\", emoji: \"🇫🇴\" },\n { value: \"FR\", label: \"France\", emoji: \"🇫🇷\" },\n { value: \"GA\", label: \"Gabon\", emoji: \"🇬🇦\" },\n {\n value: \"GB\",\n label: \"United Kingdom of Great Britain and Northern Ireland\",\n emoji: \"🇬🇧\",\n },\n { value: \"GD\", label: \"Grenada\", emoji: \"🇬🇩\" },\n { value: \"GE\", label: \"Georgia\", emoji: \"🇬🇪\" },\n { value: \"GF\", label: \"French Guiana\", emoji: \"🇬🇫\" },\n { value: \"GG\", label: \"Guernsey\", emoji: \"🇬🇬\" },\n { value: \"GH\", label: \"Ghana\", emoji: \"🇬🇭\" },\n { value: \"GI\", label: \"Gibraltar\", emoji: \"🇬🇮\" },\n { value: \"GL\", label: \"Greenland\", emoji: \"🇬🇱\" },\n { value: \"GM\", label: \"Gambia\", emoji: \"🇬🇲\" },\n { value: \"GN\", label: \"Guinea\", emoji: \"🇬🇳\" },\n { value: \"GP\", label: \"Guadeloupe\", emoji: \"🇬🇵\" },\n { value: \"GQ\", label: \"Equatorial Guinea\", emoji: \"🇬🇶\" },\n { value: \"GR\", label: \"Greece\", emoji: \"🇬🇷\" },\n {\n value: \"GS\",\n label: \"South Georgia and the South Sandwich Islands\",\n emoji: \"🇬🇸\",\n },\n { value: \"GT\", label: \"Guatemala\", emoji: \"🇬🇹\" },\n { value: \"GU\", label: \"Guam\", emoji: \"🇬🇺\" },\n { value: \"GW\", label: \"Guinea-Bissau\", emoji: \"🇬🇼\" },\n { value: \"GY\", label: \"Guyana\", emoji: \"🇬🇾\" },\n { value: \"HK\", label: \"Hong Kong\", emoji: \"🇭🇰\" },\n { value: \"HM\", label: \"Heard Island and McDonald Islands\", emoji: \"🇭🇲\" },\n { value: \"HN\", label: \"Honduras\", emoji: \"🇭🇳\" },\n { value: \"HR\", label: \"Croatia\", emoji: \"🇭🇷\" },\n { value: \"HT\", label: \"Haiti\", emoji: \"🇭🇹\" },\n { value: \"HU\", label: \"Hungary\", emoji: \"🇭🇺\" },\n { value: \"ID\", label: \"Indonesia\", emoji: \"🇮🇩\" },\n { value: \"IE\", label: \"Ireland\", emoji: \"🇮🇪\" },\n { value: \"IL\", label: \"Israel\", emoji: \"🇮🇱\" },\n { value: \"IM\", label: \"Isle of Man\", emoji: \"🇮🇲\" },\n { value: \"IN\", label: \"India\", emoji: \"🇮🇳\" },\n { value: \"IO\", label: \"British Indian Ocean Territory\", emoji: \"🇮🇴\" },\n { value: \"IQ\", label: \"Iraq\", emoji: \"🇮🇶\" },\n { value: \"IR\", label: \"Iran, Islamic Republic of\", emoji: \"🇮🇷\" },\n { value: \"IS\", label: \"Iceland\", emoji: \"🇮🇸\" },\n { value: \"IT\", label: \"Italy\", emoji: \"🇮🇹\" },\n { value: \"JE\", label: \"Jersey\", emoji: \"🇯🇪\" },\n { value: \"JM\", label: \"Jamaica\", emoji: \"🇯🇲\" },\n { value: \"JO\", label: \"Jordan\", emoji: \"🇯🇴\" },\n { value: \"JP\", label: \"Japan\", emoji: \"🇯🇵\" },\n { value: \"KE\", label: \"Kenya\", emoji: \"🇰🇪\" },\n { value: \"KG\", label: \"Kyrgyzstan\", emoji: \"🇰🇬\" },\n { value: \"KH\", label: \"Cambodia\", emoji: \"🇰🇭\" },\n { value: \"KI\", label: \"Kiribati\", emoji: \"🇰🇮\" },\n { value: \"KM\", label: \"Comoros\", emoji: \"🇰🇲\" },\n { value: \"KN\", label: \"Saint Kitts and Nevis\", emoji: \"🇰🇳\" },\n { value: \"KP\", label: \"Korea, Democratic People's Republic of\", emoji: \"🇰🇵\" },\n { value: \"KR\", label: \"Korea, Republic of\", emoji: \"🇰🇷\" },\n { value: \"KW\", label: \"Kuwait\", emoji: \"🇰🇼\" },\n { value: \"KY\", label: \"Cayman Islands\", emoji: \"🇰🇾\" },\n { value: \"KZ\", label: \"Kazakhstan\", emoji: \"🇰🇿\" },\n { value: \"LA\", label: \"Lao People's Democratic Republic\", emoji: \"🇱🇦\" },\n { value: \"LB\", label: \"Lebanon\", emoji: \"🇱🇧\" },\n { value: \"LC\", label: \"Saint Lucia\", emoji: \"🇱🇨\" },\n { value: \"LI\", label: \"Liechtenstein\", emoji: \"🇱🇮\" },\n { value: \"LK\", label: \"Sri Lanka\", emoji: \"🇱🇰\" },\n { value: \"LR\", label: \"Liberia\", emoji: \"🇱🇷\" },\n { value: \"LS\", label: \"Lesotho\", emoji: \"🇱🇸\" },\n { value: \"LT\", label: \"Lithuania\", emoji: \"🇱🇹\" },\n { value: \"LU\", label: \"Luxembourg\", emoji: \"🇱🇺\" },\n { value: \"LV\", label: \"Latvia\", emoji: \"🇱🇻\" },\n { value: \"LY\", label: \"Libya\", emoji: \"🇱🇾\" },\n { value: \"MA\", label: \"Morocco\", emoji: \"🇲🇦\" },\n { value: \"MC\", label: \"Monaco\", emoji: \"🇲🇨\" },\n { value: \"MD\", label: \"Moldova, Republic of\", emoji: \"🇲🇩\" },\n { value: \"ME\", label: \"Montenegro\", emoji: \"🇲🇪\" },\n { value: \"MF\", label: \"Saint Martin, (French part)\", emoji: \"🇲🇫\" },\n { value: \"MG\", label: \"Madagascar\", emoji: \"🇲🇬\" },\n { value: \"MH\", label: \"Marshall Islands\", emoji: \"🇲🇭\" },\n { value: \"MK\", label: \"North Macedonia\", emoji: \"🇲🇰\" },\n { value: \"ML\", label: \"Mali\", emoji: \"🇲🇱\" },\n { value: \"MM\", label: \"Myanmar\", emoji: \"🇲🇲\" },\n { value: \"MN\", label: \"Mongolia\", emoji: \"🇲🇳\" },\n { value: \"MO\", label: \"Macao\", emoji: \"🇲🇴\" },\n { value: \"MP\", label: \"Northern Mariana Islands\", emoji: \"🇲🇵\" },\n { value: \"MQ\", label: \"Martinique\", emoji: \"🇲🇶\" },\n { value: \"MR\", label: \"Mauritania\", emoji: \"🇲🇷\" },\n { value: \"MS\", label: \"Montserrat\", emoji: \"🇲🇸\" },\n { value: \"MT\", label: \"Malta\", emoji: \"🇲🇹\" },\n { value: \"MU\", label: \"Mauritius\", emoji: \"🇲🇺\" },\n { value: \"MV\", label: \"Maldives\", emoji: \"🇲🇻\" },\n { value: \"MW\", label: \"Malawi\", emoji: \"🇲🇼\" },\n { value: \"MX\", label: \"Mexico\", emoji: \"🇲🇽\" },\n { value: \"MY\", label: \"Malaysia\", emoji: \"🇲🇾\" },\n { value: \"MZ\", label: \"Mozambique\", emoji: \"🇲🇿\" },\n { value: \"NA\", label: \"Namibia\", emoji: \"🇳🇦\" },\n { value: \"NC\", label: \"New Caledonia\", emoji: \"🇳🇨\" },\n { value: \"NE\", label: \"Niger\", emoji: \"🇳🇪\" },\n { value: \"NF\", label: \"Norfolk Island\", emoji: \"🇳🇫\" },\n { value: \"NG\", label: \"Nigeria\", emoji: \"🇳🇬\" },\n { value: \"NI\", label: \"Nicaragua\", emoji: \"🇳🇮\" },\n { value: \"NL\", label: \"Netherlands\", emoji: \"🇳🇱\" },\n { value: \"NO\", label: \"Norway\", emoji: \"🇳🇴\" },\n { value: \"NP\", label: \"Nepal\", emoji: \"🇳🇵\" },\n { value: \"NR\", label: \"Nauru\", emoji: \"🇳🇷\" },\n { value: \"NU\", label: \"Niue\", emoji: \"🇳🇺\" },\n { value: \"NZ\", label: \"New Zealand\", emoji: \"🇳🇿\" },\n { value: \"OM\", label: \"Oman\", emoji: \"🇴🇲\" },\n { value: \"PA\", label: \"Panama\", emoji: \"🇵🇦\" },\n { value: \"PE\", label: \"Peru\", emoji: \"🇵🇪\" },\n { value: \"PF\", label: \"French Polynesia\", emoji: \"🇵🇫\" },\n { value: \"PG\", label: \"Papua New Guinea\", emoji: \"🇵🇬\" },\n { value: \"PH\", label: \"Philippines\", emoji: \"🇵🇭\" },\n { value: \"PK\", label: \"Pakistan\", emoji: \"🇵🇰\" },\n { value: \"PL\", label: \"Poland\", emoji: \"🇵🇱\" },\n { value: \"PM\", label: \"Saint Pierre and Miquelon\", emoji: \"🇵🇲\" },\n { value: \"PN\", label: \"Pitcairn\", emoji: \"🇵🇳\" },\n { value: \"PR\", label: \"Puerto Rico\", emoji: \"🇵🇷\" },\n { value: \"PS\", label: \"Palestine, State of\", emoji: \"🇵🇸\" },\n { value: \"PT\", label: \"Portugal\", emoji: \"🇵🇹\" },\n { value: \"PW\", label: \"Palau\", emoji: \"🇵🇼\" },\n { value: \"PY\", label: \"Paraguay\", emoji: \"🇵🇾\" },\n { value: \"QA\", label: \"Qatar\", emoji: \"🇶🇦\" },\n { value: \"RE\", label: \"Réunion\", emoji: \"🇷🇪\" },\n { value: \"RO\", label: \"Romania\", emoji: \"🇷🇴\" },\n { value: \"RS\", label: \"Serbia\", emoji: \"🇷🇸\" },\n { value: \"RU\", label: \"Russian Federation\", emoji: \"🇷🇺\" },\n { value: \"RW\", label: \"Rwanda\", emoji: \"🇷🇼\" },\n { value: \"SA\", label: \"Saudi Arabia\", emoji: \"🇸🇦\" },\n { value: \"SB\", label: \"Solomon Islands\", emoji: \"🇸🇧\" },\n { value: \"SC\", label: \"Seychelles\", emoji: \"🇸🇨\" },\n { value: \"SD\", label: \"Sudan\", emoji: \"🇸🇩\" },\n { value: \"SE\", label: \"Sweden\", emoji: \"🇸🇪\" },\n { value: \"SG\", label: \"Singapore\", emoji: \"🇸🇬\" },\n {\n value: \"SH\",\n label: \"Saint Helena, Ascension and Tristan da Cunha\",\n emoji: \"🇸🇭\",\n },\n { value: \"SI\", label: \"Slovenia\", emoji: \"🇸🇮\" },\n { value: \"SJ\", label: \"Svalbard and Jan Mayen\", emoji: \"🇸🇯\" },\n { value: \"SK\", label: \"Slovakia\", emoji: \"🇸🇰\" },\n { value: \"SL\", label: \"Sierra Leone\", emoji: \"🇸🇱\" },\n { value: \"SM\", label: \"San Marino\", emoji: \"🇸🇲\" },\n { value: \"SN\", label: \"Senegal\", emoji: \"🇸🇳\" },\n { value: \"SO\", label: \"Somalia\", emoji: \"🇸🇴\" },\n { value: \"SR\", label: \"Suriname\", emoji: \"🇸🇷\" },\n { value: \"SS\", label: \"South Sudan\", emoji: \"🇸🇸\" },\n { value: \"ST\", label: \"Sao Tome and Principe\", emoji: \"🇸🇹\" },\n { value: \"SV\", label: \"El Salvador\", emoji: \"🇸🇻\" },\n { value: \"SX\", label: \"Sint Maarten, (Dutch part)\", emoji: \"🇸🇽\" },\n { value: \"SY\", label: \"Syrian Arab Republic\", emoji: \"🇸🇾\" },\n { value: \"SZ\", label: \"Eswatini\", emoji: \"🇸🇿\" },\n { value: \"TC\", label: \"Turks and Caicos Islands\", emoji: \"🇹🇨\" },\n { value: \"TD\", label: \"Chad\", emoji: \"🇹🇩\" },\n { value: \"TF\", label: \"French Southern Territories\", emoji: \"🇹🇫\" },\n { value: \"TG\", label: \"Togo\", emoji: \"🇹🇬\" },\n { value: \"TH\", label: \"Thailand\", emoji: \"🇹🇭\" },\n { value: \"TJ\", label: \"Tajikistan\", emoji: \"🇹🇯\" },\n { value: \"TK\", label: \"Tokelau\", emoji: \"🇹🇰\" },\n { value: \"TL\", label: \"Timor-Leste\", emoji: \"🇹🇱\" },\n { value: \"TM\", label: \"Turkmenistan\", emoji: \"🇹🇲\" },\n { value: \"TN\", label: \"Tunisia\", emoji: \"🇹🇳\" },\n { value: \"TO\", label: \"Tonga\", emoji: \"🇹🇴\" },\n { value: \"TR\", label: \"Türkiye\", emoji: \"🇹🇷\" },\n { value: \"TT\", label: \"Trinidad and Tobago\", emoji: \"🇹🇹\" },\n { value: \"TV\", label: \"Tuvalu\", emoji: \"🇹🇻\" },\n { value: \"TW\", label: \"Taiwan, Province of China\", emoji: \"🇹🇼\" },\n { value: \"TZ\", label: \"Tanzania, United Republic of\", emoji: \"🇹🇿\" },\n { value: \"UA\", label: \"Ukraine\", emoji: \"🇺🇦\" },\n { value: \"UG\", label: \"Uganda\", emoji: \"🇺🇬\" },\n { value: \"UM\", label: \"United States Minor Outlying Islands\", emoji: \"🇺🇲\" },\n { value: \"US\", label: \"United States of America\", emoji: \"🇺🇸\" },\n { value: \"UY\", label: \"Uruguay\", emoji: \"🇺🇾\" },\n { value: \"UZ\", label: \"Uzbekistan\", emoji: \"🇺🇿\" },\n { value: \"VA\", label: \"Holy See\", emoji: \"🇻🇦\" },\n { value: \"VC\", label: \"Saint Vincent and the Grenadines\", emoji: \"🇻🇨\" },\n { value: \"VE\", label: \"Venezuela, Bolivarian Republic of\", emoji: \"🇻🇪\" },\n { value: \"VG\", label: \"Virgin Islands, British\", emoji: \"🇻🇬\" },\n { value: \"VI\", label: \"Virgin Islands, U.S.\", emoji: \"🇻🇮\" },\n { value: \"VN\", label: \"Viet Nam\", emoji: \"🇻🇳\" },\n { value: \"VU\", label: \"Vanuatu\", emoji: \"🇻🇺\" },\n { value: \"WF\", label: \"Wallis and Futuna\", emoji: \"🇼🇫\" },\n { value: \"WS\", label: \"Samoa\", emoji: \"🇼🇸\" },\n { value: \"YE\", label: \"Yemen\", emoji: \"🇾🇪\" },\n { value: \"YT\", label: \"Mayotte\", emoji: \"🇾🇹\" },\n { value: \"ZA\", label: \"South Africa\", emoji: \"🇿🇦\" },\n { value: \"ZM\", label: \"Zambia\", emoji: \"🇿🇲\" },\n { value: \"ZW\", label: \"Zimbabwe\", emoji: \"🇿🇼\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useRef } from \"react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-links", | |
| "content": "\"use client\"\nexport const ComboboxWithLinks = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n selectionBehavior=\"clear\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item asChild item={item} key={item.value}>\n <a href={item.docs}>\n {item.label} <LuExternalLink size={10} />\n </a>\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\", docs: \"https://react.dev\" },\n { label: \"Solid\", value: \"solid\", docs: \"https://solidjs.com\" },\n { label: \"Vue\", value: \"vue\", docs: \"https://vuejs.org\" },\n { label: \"Angular\", value: \"angular\", docs: \"https://angular.io\" },\n { label: \"Svelte\", value: \"svelte\", docs: \"https://svelte.dev\" },\n { label: \"Preact\", value: \"preact\", docs: \"https://preactjs.com\" },\n { label: \"Qwik\", value: \"qwik\", docs: \"https://qwik.builder.io\" },\n { label: \"Lit\", value: \"lit\", docs: \"https://lit.dev\" },\n { label: \"Alpine.js\", value: \"alpinejs\", docs: \"https://alpinejs.dev\" },\n { label: \"Ember\", value: \"ember\", docs: \"https://emberjs.com\" },\n { label: \"Next.js\", value: \"nextjs\", docs: \"https://nextjs.org\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { LuExternalLink } from \"react-icons/lu\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"", | |
| "npmDependencies": [ | |
| "react-icons" | |
| ] | |
| }, | |
| { | |
| "name": "combobox-with-multiple", | |
| "content": "\"use client\"\nconst skills = [\n \"JavaScript\",\n \"TypeScript\",\n \"React\",\n \"Node.js\",\n \"GraphQL\",\n \"PostgreSQL\",\n]\n\nexport const ComboboxWithMultiple = () => {\n const [searchValue, setSearchValue] = useState(\"\")\n const [selectedSkills, setSelectedSkills] = useState<string[]>([])\n\n const filteredItems = useMemo(\n () =>\n skills.filter((item) =>\n item.toLowerCase().includes(searchValue.toLowerCase()),\n ),\n [searchValue],\n )\n\n const collection = useMemo(\n () => createListCollection({ items: filteredItems }),\n [filteredItems],\n )\n\n const handleValueChange = (details: Combobox.ValueChangeDetails) => {\n setSelectedSkills(details.value)\n }\n\n return (\n <Combobox.Root\n multiple\n closeOnSelect\n width=\"320px\"\n value={selectedSkills}\n collection={collection}\n onValueChange={handleValueChange}\n onInputValueChange={(details) => setSearchValue(details.inputValue)}\n >\n <Wrap gap=\"2\">\n {selectedSkills.map((skill) => (\n <Badge key={skill}>{skill}</Badge>\n ))}\n </Wrap>\n\n <Combobox.Label>Select Skills</Combobox.Label>\n\n <Combobox.Control>\n <Combobox.Input />\n <Combobox.IndicatorGroup>\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.ItemGroup>\n <Combobox.ItemGroupLabel>Skills</Combobox.ItemGroupLabel>\n {filteredItems.map((item) => (\n <Combobox.Item key={item} item={item}>\n {item}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n <Combobox.Empty>No skills found</Combobox.Empty>\n </Combobox.ItemGroup>\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Badge,\n Combobox,\n Portal,\n Wrap,\n createListCollection,\n} from \"@chakra-ui/react\"", | |
| "import { useMemo, useState } from \"react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-option-group", | |
| "content": "\"use client\"\nexport const ComboboxWithOptionGroup = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n groupBy: (item) => item.type,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"320px\"\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.group().map(([group, items]) => (\n <Combobox.ItemGroup key={group}>\n <Combobox.ItemGroupLabel>{group}</Combobox.ItemGroupLabel>\n <Combobox.ItemGroup>\n {items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.ItemGroup>\n </Combobox.ItemGroup>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\", type: \"Frontend\" },\n { label: \"Node.js\", value: \"nodejs\", type: \"Backend\" },\n { label: \"Django\", value: \"django\", type: \"Backend\" },\n { label: \"Vue\", value: \"vue\", type: \"Frontend\" },\n { label: \"Svelte\", value: \"svelte\", type: \"Frontend\" },\n { label: \"Next.js\", value: \"nextjs\", type: \"Frontend\" },\n { label: \"Express\", value: \"express\", type: \"Backend\" },\n { label: \"Ruby on Rails\", value: \"rails\", type: \"Backend\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-positioning", | |
| "content": "\"use client\"\nexport const ComboboxWithPositioning = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n collection={collection}\n onInputValueChange={(e) => filter(e.inputValue)}\n width=\"160px\"\n positioning={{ flip: false, gutter: 2, placement: \"right-start\" }}\n >\n <Combobox.Label>Select framework</Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-selection-behavior", | |
| "content": "\"use client\"\nexport const ComboboxWithSelectionBehavior = () => {\n return (\n <Stack gap=\"8\" p=\"4\">\n <ComboboxDemo selectionBehavior=\"replace\" />\n <ComboboxDemo selectionBehavior=\"clear\" />\n <ComboboxDemo selectionBehavior=\"preserve\" />\n </Stack>\n )\n}\n\nconst descriptions = {\n replace: \"Selected item replaces the input value\",\n clear: \"Input value is cleared after selection\",\n preserve: \"Input value is preserved after selection\",\n}\n\nconst ComboboxDemo = (props: Partial<Combobox.RootProps>) => {\n const { selectionBehavior = \"replace\" } = props\n\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: companies,\n filter: contains,\n })\n\n return (\n <Box>\n <Stack mb={4}>\n <Heading as=\"h3\">{selectionBehavior} Selection</Heading>\n <Text textStyle=\"sm\" color=\"gray.600\">\n {descriptions[selectionBehavior]}\n </Text>\n </Stack>\n\n <Combobox.Root\n collection={collection}\n selectionBehavior={selectionBehavior}\n onInputValueChange={(details) => filter(details.inputValue)}\n >\n <Combobox.Label>Select Companies</Combobox.Label>\n\n <Combobox.Control>\n <Combobox.Input />\n </Combobox.Control>\n\n <Combobox.Content>\n {collection.items.map((item) => (\n <Combobox.Item key={item.value} item={item}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Root>\n </Box>\n )\n}\n\nconst companies = [\n { label: \"Apple\", value: \"apple\" },\n { label: \"Amazon\", value: \"amazon\" },\n { label: \"Meta\", value: \"meta\" },\n { label: \"Netflix\", value: \"netflix\" },\n { label: \"Google\", value: \"google\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Box,\n Combobox,\n Heading,\n Stack,\n Text,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-sizes", | |
| "content": "\"use client\"\nexport const ComboboxWithSizes = () => {\n return (\n <Stack gap=\"8\">\n <ComboboxDemo size=\"xs\" />\n <ComboboxDemo size=\"sm\" />\n <ComboboxDemo size=\"md\" />\n <ComboboxDemo size=\"lg\" />\n </Stack>\n )\n}\n\nconst ComboboxDemo = (props: Omit<Combobox.RootProps, \"collection\">) => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n {...props}\n onInputValueChange={(e) => filter(e.inputValue)}\n collection={collection}\n >\n <Combobox.Label>\n Select framework ({props.size?.toString()})\n </Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n Stack,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-store", | |
| "content": "\"use client\"\nexport const ComboboxWithStore = () => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n const combobox = useCombobox({\n collection,\n onInputValueChange(e) {\n filter(e.inputValue)\n },\n })\n\n return (\n <Combobox.RootProvider value={combobox} width=\"320px\">\n <Combobox.Label>Select framework</Combobox.Label>\n\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.RootProvider>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n useCombobox,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| }, | |
| { | |
| "name": "combobox-with-variants", | |
| "content": "\"use client\"\nexport const ComboboxWithVariants = () => {\n return (\n <Stack gap=\"8\">\n <ComboboxDemo variant=\"subtle\" />\n <ComboboxDemo variant=\"outline\" />\n <ComboboxDemo variant=\"flushed\" />\n </Stack>\n )\n}\n\nconst ComboboxDemo = (props: Omit<Combobox.RootProps, \"collection\">) => {\n const { contains } = useFilter({ sensitivity: \"base\" })\n\n const { collection, filter } = useListCollection({\n initialItems: frameworks,\n filter: contains,\n })\n\n return (\n <Combobox.Root\n {...props}\n onInputValueChange={(e) => filter(e.inputValue)}\n collection={collection}\n >\n <Combobox.Label>\n Select framework ({props.variant?.toString()})\n </Combobox.Label>\n <Combobox.Control>\n <Combobox.Input placeholder=\"Type to search\" />\n <Combobox.IndicatorGroup>\n <Combobox.ClearTrigger />\n <Combobox.Trigger />\n </Combobox.IndicatorGroup>\n </Combobox.Control>\n <Portal>\n <Combobox.Positioner>\n <Combobox.Content>\n <Combobox.Empty>No items found</Combobox.Empty>\n {collection.items.map((item) => (\n <Combobox.Item item={item} key={item.value}>\n {item.label}\n <Combobox.ItemIndicator />\n </Combobox.Item>\n ))}\n </Combobox.Content>\n </Combobox.Positioner>\n </Portal>\n </Combobox.Root>\n )\n}\n\nconst frameworks = [\n { label: \"React\", value: \"react\" },\n { label: \"Solid\", value: \"solid\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Preact\", value: \"preact\" },\n { label: \"Qwik\", value: \"qwik\" },\n { label: \"Lit\", value: \"lit\" },\n { label: \"Alpine.js\", value: \"alpinejs\" },\n { label: \"Ember\", value: \"ember\" },\n { label: \"Next.js\", value: \"nextjs\" },\n]\n", | |
| "hasSnippet": false, | |
| "importPaths": [ | |
| "import {\n Combobox,\n Portal,\n Stack,\n useFilter,\n useListCollection,\n} from \"@chakra-ui/react\"" | |
| ], | |
| "importPath": "import { Combobox } from \"@chakra-ui/react\"" | |
| } | |
| ] | |
| } |