|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { getPropsString } from '@/lib/utils'; |
| 4 | + |
| 5 | +export const getCode = (props: Record<string, unknown>) => { |
| 6 | + const { multiple, ...rest } = props; |
| 7 | + return ` |
| 8 | + <Combobox${getPropsString({ ...(multiple ? { multiple } : {}) })}> |
| 9 | + <Combobox.Input placeholder="Enter a fruit"${getPropsString(rest)} /> |
| 10 | + <Combobox.Content> |
| 11 | + <Combobox.Item>Apple</Combobox.Item> |
| 12 | + <Combobox.Item>Banana</Combobox.Item> |
| 13 | + <Combobox.Item>Blueberry</Combobox.Item> |
| 14 | + <Combobox.Item>Grapes</Combobox.Item> |
| 15 | + <Combobox.Item>Pineapple</Combobox.Item> |
| 16 | + </Combobox.Content> |
| 17 | + </Combobox>`; |
| 18 | +}; |
| 19 | + |
| 20 | +export const playground = { |
| 21 | + type: 'playground', |
| 22 | + controls: { |
| 23 | + label: { type: 'text', initialValue: 'Fruits' }, |
| 24 | + size: { |
| 25 | + type: 'select', |
| 26 | + options: ['small', 'large'], |
| 27 | + defaultValue: 'large' |
| 28 | + }, |
| 29 | + multiple: { |
| 30 | + type: 'checkbox', |
| 31 | + defaultValue: false |
| 32 | + } |
| 33 | + }, |
| 34 | + getCode |
| 35 | +}; |
| 36 | + |
| 37 | +export const basicDemo = { |
| 38 | + type: 'code', |
| 39 | + code: ` |
| 40 | + <Combobox> |
| 41 | + <Combobox.Input placeholder="Enter a fruit" /> |
| 42 | + <Combobox.Content> |
| 43 | + <Combobox.Item>Apple</Combobox.Item> |
| 44 | + <Combobox.Item>Banana</Combobox.Item> |
| 45 | + <Combobox.Item>Grape</Combobox.Item> |
| 46 | + <Combobox.Item>Orange</Combobox.Item> |
| 47 | + </Combobox.Content> |
| 48 | + </Combobox>` |
| 49 | +}; |
| 50 | + |
| 51 | +export const iconDemo = { |
| 52 | + type: 'code', |
| 53 | + code: ` |
| 54 | + <Combobox> |
| 55 | + <Combobox.Input placeholder="Enter a fruit" /> |
| 56 | + <Combobox.Content> |
| 57 | + <Combobox.Item leadingIcon={<Info size={16} />}>Apple</Combobox.Item> |
| 58 | + <Combobox.Item leadingIcon={<X size={16} />}>Banana</Combobox.Item> |
| 59 | + <Combobox.Item leadingIcon={<Home size={16} />}>Grape</Combobox.Item> |
| 60 | + <Combobox.Item leadingIcon={<Laugh size={16} />}>Orange</Combobox.Item> |
| 61 | + </Combobox.Content> |
| 62 | + </Combobox>` |
| 63 | +}; |
| 64 | + |
| 65 | +export const sizeDemo = { |
| 66 | + type: 'code', |
| 67 | + code: ` |
| 68 | + <Flex align="center" gap="large"> |
| 69 | + <Combobox> |
| 70 | + <Combobox.Input size="small" placeholder="Small combobox" /> |
| 71 | + <Combobox.Content> |
| 72 | + <Combobox.Item>Option 1</Combobox.Item> |
| 73 | + <Combobox.Item>Option 2</Combobox.Item> |
| 74 | + </Combobox.Content> |
| 75 | + </Combobox> |
| 76 | + <Combobox> |
| 77 | + <Combobox.Input placeholder="Large combobox" /> |
| 78 | + <Combobox.Content> |
| 79 | + <Combobox.Item>Option 1</Combobox.Item> |
| 80 | + <Combobox.Item>Option 2</Combobox.Item> |
| 81 | + </Combobox.Content> |
| 82 | + </Combobox> |
| 83 | + </Flex>` |
| 84 | +}; |
| 85 | + |
| 86 | +export const multipleDemo = { |
| 87 | + type: 'code', |
| 88 | + code: ` |
| 89 | + <Combobox multiple> |
| 90 | + <Combobox.Input placeholder="Select fruits..." /> |
| 91 | + <Combobox.Content> |
| 92 | + <Combobox.Item>Apple</Combobox.Item> |
| 93 | + <Combobox.Item>Banana</Combobox.Item> |
| 94 | + <Combobox.Item>Grape</Combobox.Item> |
| 95 | + <Combobox.Item>Orange</Combobox.Item> |
| 96 | + <Combobox.Item>Pineapple</Combobox.Item> |
| 97 | + <Combobox.Item>Mango</Combobox.Item> |
| 98 | + </Combobox.Content> |
| 99 | + </Combobox>` |
| 100 | +}; |
| 101 | + |
| 102 | +export const groupDemo = { |
| 103 | + type: 'code', |
| 104 | + code: ` |
| 105 | + <Combobox> |
| 106 | + <Combobox.Input placeholder="Enter a fruit" /> |
| 107 | + <Combobox.Content> |
| 108 | + <Combobox.Group> |
| 109 | + <Combobox.Label>Fruits</Combobox.Label> |
| 110 | + <Combobox.Item>Apple</Combobox.Item> |
| 111 | + <Combobox.Item>Banana</Combobox.Item> |
| 112 | + </Combobox.Group> |
| 113 | + <Combobox.Separator /> |
| 114 | + <Combobox.Group> |
| 115 | + <Combobox.Label>Vegetables</Combobox.Label> |
| 116 | + <Combobox.Item>Carrot</Combobox.Item> |
| 117 | + <Combobox.Item>Broccoli</Combobox.Item> |
| 118 | + </Combobox.Group> |
| 119 | + </Combobox.Content> |
| 120 | + </Combobox>` |
| 121 | +}; |
| 122 | + |
| 123 | +export const controlledDemo = { |
| 124 | + type: 'code', |
| 125 | + code: ` |
| 126 | + function ControlledDemo() { |
| 127 | + const [value, setValue] = React.useState(""); |
| 128 | + const [inputValue, setInputValue] = React.useState(""); |
| 129 | +
|
| 130 | + return ( |
| 131 | + <Flex direction="column" gap="medium"> |
| 132 | + <Text>Selected: {value || "None"}</Text> |
| 133 | + <Combobox |
| 134 | + value={value} |
| 135 | + onValueChange={setValue} |
| 136 | + inputValue={inputValue} |
| 137 | + onInputValueChange={setInputValue} |
| 138 | + > |
| 139 | + <Combobox.Input placeholder="Enter a fruit" /> |
| 140 | + <Combobox.Content> |
| 141 | + <Combobox.Item>Apple</Combobox.Item> |
| 142 | + <Combobox.Item>Banana</Combobox.Item> |
| 143 | + <Combobox.Item>Grape</Combobox.Item> |
| 144 | + </Combobox.Content> |
| 145 | + </Combobox> |
| 146 | + </Flex> |
| 147 | + ); |
| 148 | + }` |
| 149 | +}; |
0 commit comments