Skip to content

Commit 1018295

Browse files
committed
refactor: examples and stories
1 parent 223a140 commit 1018295

File tree

5 files changed

+23
-265
lines changed

5 files changed

+23
-265
lines changed

apps/compositions/src/examples/combobox-multi-with-replace-selection-behavior.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

apps/compositions/src/examples/combobox-with-custom-options.tsx

Lines changed: 0 additions & 181 deletions
This file was deleted.
Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
"use client"
22

33
import {
4-
Badge,
54
Box,
65
Combobox,
76
Heading,
87
Stack,
98
Text,
10-
createListCollection,
9+
useFilter,
10+
useListCollection,
1111
} from "@chakra-ui/react"
12-
import { useState } from "react"
1312

14-
const companies = ["Apple", "Amazon", "Meta", "Netflix", "Google"]
15-
16-
export const ComboboxSelectionBehavior = () => {
13+
export const ComboboxWithSelectionBehavior = () => {
1714
return (
18-
<Stack gap={8} p={4}>
15+
<Stack gap="8" p="4">
1916
<ComboboxDemo selectionBehavior="replace" />
2017
<ComboboxDemo selectionBehavior="clear" />
2118
<ComboboxDemo selectionBehavior="preserve" />
@@ -29,12 +26,15 @@ const descriptions = {
2926
preserve: "Input value is preserved after selection",
3027
}
3128

32-
function ComboboxDemo(props: Partial<Combobox.RootProps>) {
29+
const ComboboxDemo = (props: Partial<Combobox.RootProps>) => {
3330
const { selectionBehavior = "replace" } = props
34-
const [value, setValue] = useState<string[]>([])
35-
const [inputValue, setInputValue] = useState("")
3631

37-
const collection = createListCollection({ items: companies })
32+
const { contains } = useFilter({ sensitivity: "base" })
33+
34+
const { collection, filter } = useListCollection({
35+
initialItems: companies,
36+
filter: contains,
37+
})
3838

3939
return (
4040
<Box>
@@ -46,48 +46,33 @@ function ComboboxDemo(props: Partial<Combobox.RootProps>) {
4646
</Stack>
4747

4848
<Combobox.Root
49-
multiple
50-
value={value}
51-
inputValue={inputValue}
5249
collection={collection}
5350
selectionBehavior={selectionBehavior}
54-
onValueChange={(details) => setValue(details.value)}
55-
onInputValueChange={(details) => setInputValue(details.inputValue)}
51+
onInputValueChange={(details) => filter(details.inputValue)}
5652
>
5753
<Combobox.Label>Select Companies</Combobox.Label>
5854

59-
{selectionBehavior !== "replace" && (
60-
<Stack direction="row">
61-
{value.map((company) => (
62-
<Badge key={company}>{company}</Badge>
63-
))}
64-
</Stack>
65-
)}
66-
6755
<Combobox.Control>
6856
<Combobox.Input />
69-
<Combobox.IndicatorGroup>
70-
<Combobox.ClearTrigger />
71-
<Combobox.Trigger />
72-
</Combobox.IndicatorGroup>
7357
</Combobox.Control>
7458

7559
<Combobox.Content>
7660
{collection.items.map((item) => (
77-
<Combobox.Item key={item} item={item}>
78-
{item}
61+
<Combobox.Item key={item.value} item={item}>
62+
{item.label}
7963
<Combobox.ItemIndicator />
8064
</Combobox.Item>
8165
))}
8266
</Combobox.Content>
8367
</Combobox.Root>
84-
85-
<Box mt={2} p={2} bg="gray.50" rounded="sm">
86-
<Box textStyle="sm">
87-
<Box>Selected: {value.join(", ") || "none"}</Box>
88-
<Box>Input Value: {inputValue || "empty"}</Box>
89-
</Box>
90-
</Box>
9168
</Box>
9269
)
9370
}
71+
72+
const companies = [
73+
{ label: "Apple", value: "apple" },
74+
{ label: "Amazon", value: "amazon" },
75+
{ label: "Meta", value: "meta" },
76+
{ label: "Netflix", value: "netflix" },
77+
{ label: "Google", value: "google" },
78+
]

packages/react/__stories__/combobox.stories.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ export { ComboboxWithField as Field } from "compositions/examples/combobox-with-
4141
export { ComboboxWithCustomFilter as CustomFilter } from "compositions/examples/combobox-with-custom-filter"
4242
export { ComboboxWithInputInContent as InputInContent } from "compositions/examples/combobox-with-input-in-content"
4343

44-
export { ComboboxMultiWithReplaceSelectionBehavior as MultiWithReplaceSelectionBehaviors } from "compositions/examples/combobox-multi-with-replace-selection-behavior"
45-
export { ComboboxWithCustomOptions as CustomOptions } from "compositions/examples/combobox-with-custom-options"
4644
export { ComboboxSelectionBehavior as SelectionBehavior } from "compositions/examples/combobox-with-selection-behavior"
4745
export { ComboboxWithCreateableOptions as CreateableOptions } from "compositions/examples/combobox-with-createable-options"
4846
export { ComboboxColorPicker as ColorPicker } from "compositions/examples/combobox-color-picker"

packages/react/src/theme/recipes/combobox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const comboboxSlotRecipe = defineSlotRecipe({
7373
justifyContent: "center",
7474
gap: "1",
7575
pos: "absolute",
76-
right: "0",
76+
insetEnd: "0",
7777
top: "0",
7878
bottom: "0",
7979
px: "var(--combobox-input-padding-x)",

0 commit comments

Comments
 (0)