reshaped 3.9.0-canary.0 → 3.9.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/dist/bundle.css +1 -1
  2. package/dist/bundle.js +10 -10
  3. package/dist/components/Button/Button.module.css +1 -1
  4. package/dist/components/Card/Card.module.css +1 -1
  5. package/dist/components/DropdownMenu/DropdownMenu.js +1 -1
  6. package/dist/components/Flyout/Flyout.constants.d.ts +1 -3
  7. package/dist/components/Flyout/Flyout.constants.js +1 -3
  8. package/dist/components/Flyout/FlyoutControlled.js +6 -8
  9. package/dist/components/Flyout/utilities/cooldown.js +1 -2
  10. package/dist/components/Icon/Icon.module.css +1 -1
  11. package/dist/components/Progress/Progress.module.css +1 -1
  12. package/dist/components/Reshaped/Reshaped.css +1 -1
  13. package/dist/components/Text/Text.module.css +1 -1
  14. package/dist/components/Theme/Theme.module.css +1 -1
  15. package/dist/hooks/useOnClickOutside.js +2 -4
  16. package/dist/themes/_generator/tokens/css.js +2 -2
  17. package/dist/themes/figma/theme.css +1 -1
  18. package/dist/themes/fragments/twitter/theme.css +1 -1
  19. package/dist/themes/reshaped/theme.css +1 -1
  20. package/dist/themes/slate/theme.css +1 -1
  21. package/package.json +40 -35
  22. package/dist/components/Accordion/tests/Accordion.stories.d.ts +0 -44
  23. package/dist/components/Accordion/tests/Accordion.stories.js +0 -204
  24. package/dist/components/ActionBar/tests/ActionBar.stories.d.ts +0 -40
  25. package/dist/components/ActionBar/tests/ActionBar.stories.js +0 -223
  26. package/dist/components/Actionable/tests/Actionable.stories.d.ts +0 -41
  27. package/dist/components/Actionable/tests/Actionable.stories.js +0 -220
  28. package/dist/components/Alert/tests/Alert.stories.d.ts +0 -24
  29. package/dist/components/Alert/tests/Alert.stories.js +0 -78
  30. package/dist/components/Autocomplete/tests/Autocomplete.stories.d.ts +0 -32
  31. package/dist/components/Autocomplete/tests/Autocomplete.stories.js +0 -246
  32. package/dist/components/Avatar/tests/Avatar.stories.d.ts +0 -31
  33. package/dist/components/Avatar/tests/Avatar.stories.js +0 -176
  34. package/dist/components/Badge/tests/Badge.stories.d.ts +0 -55
  35. package/dist/components/Badge/tests/Badge.stories.js +0 -328
  36. package/dist/components/Breadcrumbs/tests/Breadcrumbs.stories.d.ts +0 -40
  37. package/dist/components/Breadcrumbs/tests/Breadcrumbs.stories.js +0 -187
  38. package/dist/components/Button/tests/Button.stories.d.ts +0 -79
  39. package/dist/components/Button/tests/Button.stories.js +0 -789
  40. package/dist/components/Calendar/tests/Calendar.stories.d.ts +0 -29
  41. package/dist/components/Calendar/tests/Calendar.stories.js +0 -255
  42. package/dist/components/Card/tests/Card.stories.d.ts +0 -52
  43. package/dist/components/Card/tests/Card.stories.js +0 -125
  44. package/dist/components/Carousel/tests/Carousel.stories.d.ts +0 -34
  45. package/dist/components/Carousel/tests/Carousel.stories.js +0 -224
  46. package/dist/components/Checkbox/tests/Checkbox.stories.d.ts +0 -30
  47. package/dist/components/Checkbox/tests/Checkbox.stories.js +0 -171
  48. package/dist/components/CheckboxGroup/tests/CheckboxGroup.stories.d.ts +0 -19
  49. package/dist/components/CheckboxGroup/tests/CheckboxGroup.stories.js +0 -83
  50. package/dist/components/Container/tests/Container.stories.d.ts +0 -24
  51. package/dist/components/Container/tests/Container.stories.js +0 -75
  52. package/dist/components/ContextMenu/tests/ContextMenu.stories.d.ts +0 -26
  53. package/dist/components/ContextMenu/tests/ContextMenu.stories.js +0 -70
  54. package/dist/components/Dismissible/tests/Dismissible.stories.d.ts +0 -25
  55. package/dist/components/Dismissible/tests/Dismissible.stories.js +0 -97
  56. package/dist/components/Divider/tests/Divider.stories.d.ts +0 -20
  57. package/dist/components/Divider/tests/Divider.stories.js +0 -120
  58. package/dist/components/DropdownMenu/tests/DropdownMenu.stories.d.ts +0 -53
  59. package/dist/components/DropdownMenu/tests/DropdownMenu.stories.js +0 -278
  60. package/dist/components/FileUpload/tests/FileUpload.stories.d.ts +0 -31
  61. package/dist/components/FileUpload/tests/FileUpload.stories.js +0 -140
  62. package/dist/components/Flyout/tests/Flyout.stories.d.ts +0 -103
  63. package/dist/components/Flyout/tests/Flyout.stories.js +0 -738
  64. package/dist/components/FormControl/tests/FormControl.stories.d.ts +0 -31
  65. package/dist/components/FormControl/tests/FormControl.stories.js +0 -143
  66. package/dist/components/Grid/tests/Grid.stories.d.ts +0 -38
  67. package/dist/components/Grid/tests/Grid.stories.js +0 -245
  68. package/dist/components/Hidden/tests/Hidden.stories.d.ts +0 -16
  69. package/dist/components/Hidden/tests/Hidden.stories.js +0 -48
  70. package/dist/components/HiddenVisually/tests/HiddenVisually.stories.d.ts +0 -16
  71. package/dist/components/HiddenVisually/tests/HiddenVisually.stories.js +0 -28
  72. package/dist/components/Hotkey/tests/Hotkey.stories.d.ts +0 -13
  73. package/dist/components/Hotkey/tests/Hotkey.stories.js +0 -53
  74. package/dist/components/Icon/tests/Icon.stories.d.ts +0 -25
  75. package/dist/components/Icon/tests/Icon.stories.js +0 -113
  76. package/dist/components/Image/tests/Image.stories.d.ts +0 -41
  77. package/dist/components/Image/tests/Image.stories.js +0 -196
  78. package/dist/components/Link/tests/Link.stories.d.ts +0 -42
  79. package/dist/components/Link/tests/Link.stories.js +0 -155
  80. package/dist/components/Loader/tests/Loader.stories.d.ts +0 -21
  81. package/dist/components/Loader/tests/Loader.stories.js +0 -68
  82. package/dist/components/MenuItem/tests/MenuItem.stories.d.ts +0 -59
  83. package/dist/components/MenuItem/tests/MenuItem.stories.js +0 -236
  84. package/dist/components/Modal/tests/Modal.stories.d.ts +0 -64
  85. package/dist/components/Modal/tests/Modal.stories.js +0 -410
  86. package/dist/components/NumberField/tests/NumberField.stories.d.ts +0 -28
  87. package/dist/components/NumberField/tests/NumberField.stories.js +0 -258
  88. package/dist/components/Overlay/tests/Overlay.stories.d.ts +0 -28
  89. package/dist/components/Overlay/tests/Overlay.stories.js +0 -202
  90. package/dist/components/Pagination/tests/Pagination.stories.d.ts +0 -24
  91. package/dist/components/Pagination/tests/Pagination.stories.js +0 -105
  92. package/dist/components/PinField/tests/PinField.stories.d.ts +0 -34
  93. package/dist/components/PinField/tests/PinField.stories.js +0 -209
  94. package/dist/components/Popover/tests/Popover.stories.d.ts +0 -69
  95. package/dist/components/Popover/tests/Popover.stories.js +0 -340
  96. package/dist/components/Progress/tests/Progress.stories.d.ts +0 -30
  97. package/dist/components/Progress/tests/Progress.stories.js +0 -102
  98. package/dist/components/ProgressIndicator/tests/ProgressIndicator.stories.d.ts +0 -19
  99. package/dist/components/ProgressIndicator/tests/ProgressIndicator.stories.js +0 -92
  100. package/dist/components/Radio/tests/Radio.stories.d.ts +0 -35
  101. package/dist/components/Radio/tests/Radio.stories.js +0 -162
  102. package/dist/components/RadioGroup/tests/RadioGroup.stories.d.ts +0 -19
  103. package/dist/components/RadioGroup/tests/RadioGroup.stories.js +0 -77
  104. package/dist/components/Reshaped/tests/Reshaped.stories.d.ts +0 -34
  105. package/dist/components/Reshaped/tests/Reshaped.stories.js +0 -108
  106. package/dist/components/Resizable/tests/Resizable.stories.d.ts +0 -38
  107. package/dist/components/Resizable/tests/Resizable.stories.js +0 -185
  108. package/dist/components/Scrim/tests/Scrim.stories.d.ts +0 -20
  109. package/dist/components/Scrim/tests/Scrim.stories.js +0 -67
  110. package/dist/components/ScrollArea/tests/ScrollArea.stories.d.ts +0 -37
  111. package/dist/components/ScrollArea/tests/ScrollArea.stories.js +0 -244
  112. package/dist/components/Select/tests/Select.stories.d.ts +0 -53
  113. package/dist/components/Select/tests/Select.stories.js +0 -616
  114. package/dist/components/Skeleton/tests/Skeleton.stories.d.ts +0 -20
  115. package/dist/components/Skeleton/tests/Skeleton.stories.js +0 -63
  116. package/dist/components/Slider/tests/Slider.stories.d.ts +0 -47
  117. package/dist/components/Slider/tests/Slider.stories.js +0 -279
  118. package/dist/components/Stepper/tests/Stepper.stories.d.ts +0 -31
  119. package/dist/components/Stepper/tests/Stepper.stories.js +0 -135
  120. package/dist/components/Switch/tests/Switch.stories.d.ts +0 -22
  121. package/dist/components/Switch/tests/Switch.stories.js +0 -137
  122. package/dist/components/Switch/tests/Switch.test.stories.d.ts +0 -13
  123. package/dist/components/Switch/tests/Switch.test.stories.js +0 -11
  124. package/dist/components/Table/tests/Table.stories.d.ts +0 -42
  125. package/dist/components/Table/tests/Table.stories.js +0 -348
  126. package/dist/components/Tabs/tests/Tabs.stories.d.ts +0 -62
  127. package/dist/components/Tabs/tests/Tabs.stories.js +0 -539
  128. package/dist/components/Text/tests/Text.stories.d.ts +0 -48
  129. package/dist/components/Text/tests/Text.stories.js +0 -201
  130. package/dist/components/TextArea/tests/TextArea.stories.d.ts +0 -53
  131. package/dist/components/TextArea/tests/TextArea.stories.js +0 -204
  132. package/dist/components/TextField/tests/TextField.stories.d.ts +0 -54
  133. package/dist/components/TextField/tests/TextField.stories.js +0 -252
  134. package/dist/components/Theme/tests/Theme.stories.d.ts +0 -25
  135. package/dist/components/Theme/tests/Theme.stories.js +0 -171
  136. package/dist/components/Timeline/tests/Timeline.stories.d.ts +0 -22
  137. package/dist/components/Timeline/tests/Timeline.stories.js +0 -86
  138. package/dist/components/Toast/tests/Toast.stories.d.ts +0 -41
  139. package/dist/components/Toast/tests/Toast.stories.js +0 -432
  140. package/dist/components/ToggleButton/tests/ToggleButton.stories.d.ts +0 -27
  141. package/dist/components/ToggleButton/tests/ToggleButton.stories.js +0 -97
  142. package/dist/components/ToggleButtonGroup/tests/ToggleButtonGroup.stories.d.ts +0 -27
  143. package/dist/components/ToggleButtonGroup/tests/ToggleButtonGroup.stories.js +0 -169
  144. package/dist/components/Tooltip/tests/Tooltip.stories.d.ts +0 -28
  145. package/dist/components/Tooltip/tests/Tooltip.stories.js +0 -182
  146. package/dist/components/View/tests/View.stories.d.ts +0 -141
  147. package/dist/components/View/tests/View.stories.js +0 -1329
  148. package/dist/components/_private/Portal/tests/Portal.stories.d.ts +0 -6
  149. package/dist/components/_private/Portal/tests/Portal.stories.js +0 -17
  150. package/dist/hooks/tests/useDrag.stories.d.ts +0 -31
  151. package/dist/hooks/tests/useDrag.stories.js +0 -147
  152. package/dist/hooks/tests/useElementId.stories.d.ts +0 -11
  153. package/dist/hooks/tests/useElementId.stories.js +0 -23
  154. package/dist/hooks/tests/useHandlerRef.stories.d.ts +0 -14
  155. package/dist/hooks/tests/useHandlerRef.stories.js +0 -44
  156. package/dist/hooks/tests/useHotkeys.stories.d.ts +0 -43
  157. package/dist/hooks/tests/useHotkeys.stories.js +0 -158
  158. package/dist/hooks/tests/useKeyboardArrowNavigation.stories.d.ts +0 -15
  159. package/dist/hooks/tests/useKeyboardArrowNavigation.stories.js +0 -128
  160. package/dist/hooks/tests/useKeyboardMode.stories.d.ts +0 -11
  161. package/dist/hooks/tests/useKeyboardMode.stories.js +0 -42
  162. package/dist/hooks/tests/useOnClickOutside.stories.d.ts +0 -23
  163. package/dist/hooks/tests/useOnClickOutside.stories.js +0 -111
  164. package/dist/hooks/tests/useRTL.stories.d.ts +0 -11
  165. package/dist/hooks/tests/useRTL.stories.js +0 -23
  166. package/dist/hooks/tests/useResponsiveClientValue.stories.d.ts +0 -18
  167. package/dist/hooks/tests/useResponsiveClientValue.stories.js +0 -30
  168. package/dist/hooks/tests/useScrollLock.stories.d.ts +0 -14
  169. package/dist/hooks/tests/useScrollLock.stories.js +0 -97
  170. package/dist/hooks/tests/useToggle.stories.d.ts +0 -13
  171. package/dist/hooks/tests/useToggle.stories.js +0 -59
  172. package/dist/tests/ShadowDOM.stories.d.ts +0 -6
  173. package/dist/tests/ShadowDOM.stories.js +0 -110
  174. package/dist/tests/themes.stories.d.ts +0 -16
  175. package/dist/tests/themes.stories.js +0 -327
  176. package/dist/utilities/a11y/tests/TrapFocus.stories.d.ts +0 -14
  177. package/dist/utilities/a11y/tests/TrapFocus.stories.js +0 -615
@@ -1,616 +0,0 @@
1
- import React from "react";
2
- import { expect, fn, userEvent, within } from "storybook/test";
3
- import IconZap from "../../../icons/Zap.js";
4
- import { Example, Placeholder } from "../../../utilities/storybook/index.js";
5
- import useToggle from "../../../hooks/useToggle.js";
6
- import Modal from "../../Modal/index.js";
7
- import MenuItem from "../../MenuItem/index.js";
8
- import Select from "../index.js";
9
- import Text from "../../Text/index.js";
10
- import FormControl from "../../FormControl/index.js";
11
- import Badge from "../../Badge/index.js";
12
- export default {
13
- title: "Components/Select",
14
- component: Select,
15
- parameters: {
16
- iframe: {
17
- url: "https://reshaped.so/docs/components/select",
18
- },
19
- },
20
- };
21
- export const nativeRender = {
22
- name: "native rendering, options, name, id",
23
- render: () => (<Example>
24
- <Example.Item title="native with options prop">
25
- <Select name="animal" id="animal-1" placeholder="Select an animal" options={[
26
- { label: "Dog", value: "dog" },
27
- { label: "Turtle", value: "turtle" },
28
- ]} inputAttributes={{
29
- "aria-label": "Select an animal",
30
- }}/>
31
- </Example.Item>
32
- <Example.Item title="native with option tags">
33
- <Select name="animal" id="animal-2" placeholder="Select an animal" inputAttributes={{
34
- "aria-label": "Select an animal",
35
- }}>
36
- <option value="dog">Dog</option>
37
- <option value="turtle">Turtle</option>
38
- </Select>
39
- </Example.Item>
40
- </Example>),
41
- play: ({ canvas }) => {
42
- const [selectWithProp, selectWithTags] = canvas.getAllByRole("combobox");
43
- const optionsFromProps = within(selectWithProp).getAllByRole("option");
44
- const optionsFromTags = within(selectWithTags).getAllByRole("option");
45
- expect(selectWithProp).toHaveAttribute("name", "animal");
46
- expect(selectWithProp).toHaveAttribute("id", "animal-1");
47
- expect(optionsFromProps).toHaveLength(3);
48
- expect(optionsFromProps[0]).toHaveTextContent("Select an animal");
49
- expect(optionsFromProps[1]).toHaveTextContent("Dog");
50
- expect(optionsFromProps[2]).toHaveTextContent("Turtle");
51
- expect(selectWithTags).toHaveAttribute("name", "animal");
52
- expect(selectWithTags).toHaveAttribute("id", "animal-2");
53
- expect(optionsFromTags).toHaveLength(3);
54
- expect(optionsFromTags[0]).toHaveTextContent("Select an animal");
55
- expect(optionsFromTags[1]).toHaveTextContent("Dog");
56
- expect(optionsFromTags[2]).toHaveTextContent("Turtle");
57
- },
58
- };
59
- export const customRender = {
60
- name: "custom rendering, name, id, option groups",
61
- render: () => (<Example>
62
- <Example.Item title="custom with options">
63
- <Select.Custom name="animal" id="animal-1" placeholder="Select an animal" inputAttributes={{
64
- "aria-label": "Select an animal",
65
- }}>
66
- <Select.Option value="dog">Dog</Select.Option>
67
- <Select.Option value="turtle">Turtle</Select.Option>
68
- </Select.Custom>
69
- </Example.Item>
70
- <Example.Item title="native with option tags">
71
- <Select.Custom name="animal-2" id="animal-2" placeholder="Select an animal" inputAttributes={{
72
- "aria-label": "Select an animal",
73
- }}>
74
- <Select.Group label="Birds">
75
- <Select.Option value="pigeon">Pigeon</Select.Option>
76
- <Select.Option value="parrot">Parrot</Select.Option>
77
- </Select.Group>
78
- <Select.Group label="Sea Mammals">
79
- <Select.Option value="whale">Whale</Select.Option>
80
- <Select.Option value="dolphin">Dolphin</Select.Option>
81
- </Select.Group>
82
- </Select.Custom>
83
- </Example.Item>
84
- </Example>),
85
- play: async ({ canvas, canvasElement, mount }) => {
86
- await mount();
87
- const [trigger] = canvas.getAllByRole("button");
88
- const hiddenInputs = canvasElement.querySelectorAll('input[type="hidden"]');
89
- const [hiddenInput] = Array.from(hiddenInputs);
90
- // Testing only options
91
- expect(hiddenInput).toHaveAttribute("name", "animal");
92
- expect(hiddenInput).toHaveAttribute("id", "animal-1");
93
- expect(trigger).toHaveTextContent("Select an animal");
94
- await userEvent.click(trigger);
95
- const options = within(canvasElement.ownerDocument.body).getAllByRole("option");
96
- expect(options).toHaveLength(2);
97
- expect(options[0]).toHaveTextContent("Dog");
98
- expect(options[1]).toHaveTextContent("Turtle");
99
- // Testing options with groups
100
- // Remount to instantly close select
101
- await mount();
102
- const [_, triggerWithGroups] = canvas.getAllByRole("button");
103
- const hiddenInputs2 = canvasElement.querySelectorAll('input[type="hidden"]');
104
- const [__, hiddenInputWithGroups] = Array.from(hiddenInputs2);
105
- await userEvent.click(triggerWithGroups);
106
- const optionsWithGroups = within(canvasElement.ownerDocument.body).getAllByRole("option");
107
- const optionGroups = within(canvasElement.ownerDocument.body).getAllByRole("group");
108
- expect(hiddenInputWithGroups).toHaveAttribute("name", "animal-2");
109
- expect(hiddenInputWithGroups).toHaveAttribute("id", "animal-2");
110
- expect(triggerWithGroups).toHaveTextContent("Select an animal");
111
- expect(optionGroups).toHaveLength(2);
112
- expect(optionGroups[0]).toHaveTextContent("Birds");
113
- expect(optionGroups[1]).toHaveTextContent("Sea Mammals");
114
- expect(optionsWithGroups).toHaveLength(4);
115
- expect(optionsWithGroups[0]).toHaveTextContent("Pigeon");
116
- expect(optionsWithGroups[1]).toHaveTextContent("Parrot");
117
- expect(optionsWithGroups[2]).toHaveTextContent("Whale");
118
- expect(optionsWithGroups[3]).toHaveTextContent("Dolphin");
119
- },
120
- };
121
- export const nativeHandlers = {
122
- name: "native, controlled, uncontrolled, onFocus, onBlur, onChange",
123
- args: {
124
- handleChange: fn(),
125
- handleControlledChange: fn(),
126
- handleFocus: fn(),
127
- handleBlur: fn(),
128
- handleClick: fn(),
129
- },
130
- render: (args) => (<Example>
131
- <Example.Item title="native, uncontrolled, onChange">
132
- <Select name="animal" placeholder="Select an animal" defaultValue="dog" onChange={args.handleChange} inputAttributes={{
133
- "aria-label": "Select an animal",
134
- }}>
135
- <option value="dog">Dog</option>
136
- <option value="turtle">Turtle</option>
137
- </Select>
138
- </Example.Item>
139
- <Example.Item title="native, controlled, onChange">
140
- <Select name="animal-2" placeholder="Select an animal" value="dog" onChange={args.handleControlledChange} inputAttributes={{
141
- "aria-label": "Select an animal",
142
- }}>
143
- <option value="dog">Dog</option>
144
- <option value="turtle">Turtle</option>
145
- </Select>
146
- </Example.Item>
147
- <Example.Item title="native, onFocus, onBlur, onClick">
148
- <Select name="animal-3" placeholder="Select an animal" defaultValue="dog" onFocus={args.handleFocus} onBlur={args.handleBlur} onClick={args.handleClick} inputAttributes={{
149
- "aria-label": "Select an animal",
150
- }}>
151
- <option value="dog">Dog</option>
152
- <option value="turtle">Turtle</option>
153
- </Select>
154
- </Example.Item>
155
- </Example>),
156
- play: async ({ canvas, args }) => {
157
- const [uncontrolled, controlled, focusable] = canvas.getAllByRole("combobox");
158
- // Uncontrolled
159
- expect(uncontrolled).toHaveValue("dog");
160
- await userEvent.selectOptions(uncontrolled, "turtle");
161
- expect(uncontrolled).toHaveValue("turtle");
162
- expect(args.handleChange).toHaveBeenCalledTimes(1);
163
- expect(args.handleChange).toHaveBeenCalledWith({
164
- name: "animal",
165
- value: "turtle",
166
- event: expect.objectContaining({ target: uncontrolled }),
167
- });
168
- // Controlled
169
- expect(controlled).toHaveValue("dog");
170
- await userEvent.selectOptions(controlled, "turtle");
171
- expect(controlled).toHaveValue("dog");
172
- expect(args.handleControlledChange).toHaveBeenCalledTimes(1);
173
- expect(args.handleControlledChange).toHaveBeenCalledWith({
174
- name: "animal-2",
175
- value: "turtle",
176
- event: expect.objectContaining({ target: controlled }),
177
- });
178
- // Focus + blur
179
- await userEvent.click(focusable);
180
- expect(args.handleFocus).toHaveBeenCalledTimes(1);
181
- expect(args.handleFocus).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
182
- expect(args.handleClick).toHaveBeenCalledTimes(1);
183
- expect(args.handleClick).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
184
- await userEvent.click(document.body);
185
- expect(args.handleBlur).toHaveBeenCalledTimes(1);
186
- expect(args.handleBlur).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
187
- },
188
- };
189
- export const customHandlers = {
190
- name: "custom, controlled, uncontrolled, onFocus, onBlur, onChange",
191
- args: {
192
- handleChange: fn(),
193
- handleControlledChange: fn(),
194
- handleFocus: fn(),
195
- handleBlur: fn(),
196
- handleClick: fn(),
197
- },
198
- render: (args) => (<Example>
199
- <Example.Item title="custom, uncontrolled, onChange">
200
- <Select.Custom name="animal" placeholder="Select an animal" defaultValue="dog" onChange={args.handleChange} inputAttributes={{
201
- "aria-label": "Select an animal",
202
- }}>
203
- <Select.Option value="dog">Dog</Select.Option>
204
- <Select.Option value="turtle">Turtle</Select.Option>
205
- </Select.Custom>
206
- </Example.Item>
207
- <Example.Item title="custom, controlled, onChange">
208
- <Select.Custom name="animal-2" placeholder="Select an animal" value="dog" onChange={args.handleControlledChange} inputAttributes={{
209
- "aria-label": "Select an animal",
210
- }}>
211
- <Select.Option value="dog">Dog</Select.Option>
212
- <Select.Option value="turtle">Turtle</Select.Option>
213
- </Select.Custom>
214
- </Example.Item>
215
- <Example.Item title="native, onFocus, onBlur, onClick">
216
- <Select.Custom name="animal-3" placeholder="Select an animal" defaultValue="dog" onFocus={args.handleFocus} onBlur={args.handleBlur} onClick={args.handleClick} inputAttributes={{
217
- "aria-label": "Select an animal",
218
- }}>
219
- <Select.Option value="dog">Dog</Select.Option>
220
- <Select.Option value="turtle">Turtle</Select.Option>
221
- </Select.Custom>
222
- </Example.Item>
223
- </Example>),
224
- play: async ({ canvas, canvasElement, args, mount }) => {
225
- await mount();
226
- const [uncontrolled] = canvas.getAllByRole("button");
227
- const hiddenInputs = canvasElement.querySelectorAll('input[type="hidden"]');
228
- const [inputUncontrolled] = Array.from(hiddenInputs);
229
- // Uncontrolled
230
- expect(inputUncontrolled).toHaveValue("dog");
231
- await userEvent.click(uncontrolled);
232
- const [_, uncontrolledOption] = within(canvasElement.ownerDocument.body).getAllByRole("option");
233
- await userEvent.click(uncontrolledOption);
234
- expect(inputUncontrolled).toHaveValue("turtle");
235
- expect(args.handleChange).toHaveBeenCalledTimes(1);
236
- expect(args.handleChange).toHaveBeenCalledWith({
237
- name: "animal",
238
- value: "turtle",
239
- });
240
- // Controlled
241
- await mount();
242
- const [__, controlled, focusable] = canvas.getAllByRole("button");
243
- const hiddenInputs2 = canvasElement.querySelectorAll('input[type="hidden"]');
244
- const [___, inputControlled] = Array.from(hiddenInputs2);
245
- expect(inputControlled).toHaveValue("dog");
246
- await userEvent.click(controlled);
247
- const [____, controlledOption] = within(canvasElement.ownerDocument.body).getAllByRole("option");
248
- await userEvent.click(controlledOption);
249
- expect(inputControlled).toHaveValue("dog");
250
- expect(args.handleControlledChange).toHaveBeenCalledTimes(1);
251
- expect(args.handleControlledChange).toHaveBeenCalledWith({
252
- name: "animal-2",
253
- value: "turtle",
254
- });
255
- // Focus + blur + click
256
- await userEvent.click(focusable);
257
- expect(args.handleFocus).toHaveBeenCalledTimes(1);
258
- expect(args.handleFocus).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
259
- expect(args.handleClick).toHaveBeenCalledTimes(1);
260
- expect(args.handleClick).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
261
- await userEvent.click(document.body);
262
- expect(args.handleBlur).toHaveBeenCalledTimes(1);
263
- expect(args.handleBlur).toHaveBeenCalledWith(expect.objectContaining({ target: focusable }));
264
- },
265
- };
266
- export const triggerOnly = {
267
- name: "trigger only, onClick",
268
- args: {
269
- handleClick: fn(),
270
- },
271
- render: (args) => {
272
- const toggle = useToggle();
273
- const [value, setValue] = React.useState("Dog");
274
- const handleClick = (e) => {
275
- args.handleClick(e);
276
- toggle.toggle();
277
- };
278
- return (<Example>
279
- <Example.Item title="trigger only, onClick">
280
- <Select name="animal" placeholder="Select an animal" onClick={handleClick} value="dog" inputAttributes={{
281
- "aria-label": "Select an animal",
282
- }}>
283
- {value}
284
- </Select>
285
- <Modal active={toggle.active} onClose={toggle.deactivate} position="bottom" padding={2} attributes={{ "aria-label": "Select an animal" }}>
286
- <div role="listbox" aria-label="Select an animal">
287
- <MenuItem roundedCorners onClick={() => {
288
- setValue("Dog");
289
- toggle.deactivate();
290
- }} attributes={{
291
- role: "option",
292
- }}>
293
- Dog
294
- </MenuItem>
295
- <MenuItem roundedCorners attributes={{
296
- role: "option",
297
- }} onClick={() => {
298
- setValue("Turtle");
299
- toggle.deactivate();
300
- }}>
301
- Turtle
302
- </MenuItem>
303
- </div>
304
- </Modal>
305
- </Example.Item>
306
- </Example>);
307
- },
308
- play: async ({ canvas, args, canvasElement }) => {
309
- const [trigger] = canvas.getAllByRole("button");
310
- const hiddenInputs = canvasElement.querySelectorAll('input[type="hidden"]');
311
- const [input] = Array.from(hiddenInputs);
312
- expect(trigger).toHaveTextContent("Dog");
313
- expect(input).toHaveAttribute("name", "animal");
314
- expect(input).toHaveValue("dog");
315
- await userEvent.click(trigger);
316
- expect(args.handleClick).toHaveBeenCalledTimes(1);
317
- expect(args.handleClick).toHaveBeenCalledWith(expect.objectContaining({ target: trigger }));
318
- },
319
- };
320
- export const multiple = {
321
- name: "multiple",
322
- args: {
323
- handleChange: fn(),
324
- },
325
- render: (args) => (<Example>
326
- <Example.Item title="multiple">
327
- <Select.Custom multiple name="animal" placeholder="Select an animal" defaultValue={["dog"]} onChange={args.handleChange}>
328
- <Select.Option value="dog">Dog</Select.Option>
329
- <Select.Option value="turtle">Turtle</Select.Option>
330
- </Select.Custom>
331
- </Example.Item>
332
- </Example>),
333
- play: async ({ canvas, canvasElement, args }) => {
334
- const [uncontrolled] = canvas.getAllByRole("button");
335
- const hiddenInputs = canvasElement.querySelectorAll('input[type="hidden"]');
336
- const [inputUncontrolled] = Array.from(hiddenInputs);
337
- // Uncontrolled
338
- expect(inputUncontrolled).toHaveValue('["dog"]');
339
- await userEvent.click(uncontrolled);
340
- const [_, uncontrolledOption] = within(canvasElement.ownerDocument.body).getAllByRole("option");
341
- await userEvent.click(uncontrolledOption);
342
- expect(inputUncontrolled).toHaveValue('["dog","turtle"]');
343
- expect(args.handleChange).toHaveBeenCalledTimes(1);
344
- expect(args.handleChange).toHaveBeenCalledWith({
345
- name: "animal",
346
- value: ["dog", "turtle"],
347
- });
348
- },
349
- };
350
- export const variant = {
351
- name: "variant",
352
- render: () => (<Example>
353
- <Example.Item title="variant: faded, native">
354
- <Select variant="faded" name="animal" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
355
- <option value="dog">Dog</option>
356
- <option value="turtle">Turtle</option>
357
- </Select>
358
- </Example.Item>
359
-
360
- <Example.Item title="variant: faded, custom">
361
- <Select.Custom variant="faded" name="animal-2" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
362
- <Select.Option value="dog">Dog</Select.Option>
363
- <Select.Option value="turtle">Turtle</Select.Option>
364
- </Select.Custom>
365
- </Example.Item>
366
-
367
- <Example.Item title="variant: ghost, native">
368
- <Select variant="ghost" name="animal-3" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
369
- <option value="dog">Dog</option>
370
- <option value="turtle">Turtle</option>
371
- </Select>
372
- </Example.Item>
373
-
374
- <Example.Item title="variant: ghost, custom">
375
- <Select.Custom variant="ghost" name="animal-4" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
376
- <Select.Option value="dog">Dog</Select.Option>
377
- <Select.Option value="turtle">Turtle</Select.Option>
378
- </Select.Custom>
379
- </Example.Item>
380
-
381
- <Example.Item title="variant: headless, native">
382
- <Select variant="headless" name="animal-5" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
383
- <option value="dog">Dog</option>
384
- <option value="turtle">Turtle</option>
385
- </Select>
386
- </Example.Item>
387
-
388
- <Example.Item title="variant: headless, custom">
389
- <Select.Custom variant="headless" name="animal-6" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
390
- <Select.Option value="dog">Dog</Select.Option>
391
- <Select.Option value="turtle">Turtle</Select.Option>
392
- </Select.Custom>
393
- </Example.Item>
394
- </Example>),
395
- };
396
- export const size = {
397
- name: "size",
398
- render: () => (<Example>
399
- <Example.Item title="size: small">
400
- <Select.Custom size="small" name="animal" placeholder="Select an animal">
401
- <Select.Option value="dog">Dog</Select.Option>
402
- <Select.Option value="turtle">Turtle</Select.Option>
403
- </Select.Custom>
404
- </Example.Item>
405
- <Example.Item title="size: medium">
406
- <Select.Custom size="medium" name="animal" placeholder="Select an animal">
407
- <Select.Option value="dog">Dog</Select.Option>
408
- <Select.Option value="turtle">Turtle</Select.Option>
409
- </Select.Custom>
410
- </Example.Item>
411
- <Example.Item title="size: large">
412
- <Select.Custom size="large" name="animal" placeholder="Select an animal">
413
- <Select.Option value="dog">Dog</Select.Option>
414
- <Select.Option value="turtle">Turtle</Select.Option>
415
- </Select.Custom>
416
- </Example.Item>
417
- <Example.Item title="size: xlarge">
418
- <Select.Custom size="xlarge" name="animal" placeholder="Select an animal">
419
- <Select.Option value="dog">Dog</Select.Option>
420
- <Select.Option value="turtle">Turtle</Select.Option>
421
- </Select.Custom>
422
- </Example.Item>
423
- </Example>),
424
- };
425
- export const startSlot = {
426
- name: "icon,startSlot",
427
- render: () => (<Example>
428
- <Example.Item title="icon">
429
- <Select.Custom name="animal" placeholder="Select an animal" icon={IconZap}>
430
- <Select.Option value="dog">Dog</Select.Option>
431
- <Select.Option value="turtle">Turtle</Select.Option>
432
- </Select.Custom>
433
- </Example.Item>
434
-
435
- <Example.Item title="startSlot">
436
- <Select.Custom name="animal" placeholder="Select an animal" startSlot={<Placeholder h={20}/>}>
437
- <Select.Option value="dog">Dog</Select.Option>
438
- <Select.Option value="turtle">Turtle</Select.Option>
439
- </Select.Custom>
440
- </Example.Item>
441
- </Example>),
442
- };
443
- export const renderValue = {
444
- name: "renderValue",
445
- render: () => {
446
- const options = [
447
- {
448
- value: "1",
449
- label: "Title 1",
450
- subtitle: "Subtitle 1",
451
- },
452
- {
453
- value: "2",
454
- label: "Title 2",
455
- subtitle: "Subtitle 2",
456
- },
457
- ];
458
- return (<Example>
459
- <Example.Item title="default renderer, single">
460
- <Select.Custom name="animal" defaultValue="1" placeholder="Nothing selected">
461
- {options.map((option) => (<Select.Option key={option.value} value={option.value}>
462
- <Text weight="medium">{option.label}</Text>
463
- <Text weight="regular" color="neutral-faded">
464
- {option.subtitle}
465
- </Text>
466
- </Select.Option>))}
467
- </Select.Custom>
468
- </Example.Item>
469
-
470
- <Example.Item title="default renderer, multiple">
471
- <Select.Custom name="animal" defaultValue={["1"]} multiple placeholder="Nothing selected">
472
- {options.map((option) => (<Select.Option key={option.value} value={option.value}>
473
- <Text weight="medium">{option.label}</Text>
474
- <Text weight="regular" color="neutral-faded">
475
- {option.subtitle}
476
- </Text>
477
- </Select.Option>))}
478
- </Select.Custom>
479
- </Example.Item>
480
-
481
- <Example.Item title="renderValue, single">
482
- <Select.Custom name="animal" defaultValue="1" placeholder="Nothing selected" renderValue={(args) => <Badge>Title {args.value}</Badge>}>
483
- {options.map((option) => (<Select.Option key={option.value} value={option.value}>
484
- <Text weight="medium">{option.label}</Text>
485
- <Text weight="regular" color="neutral-faded">
486
- {option.subtitle}
487
- </Text>
488
- </Select.Option>))}
489
- </Select.Custom>
490
- </Example.Item>
491
-
492
- <Example.Item title="renderValue, multiple">
493
- <Select.Custom name="animal" defaultValue={["1"]} multiple placeholder="Nothing selected" renderValue={(args) => <Badge>Titles {args.value.join(", ")}</Badge>}>
494
- {options.map((option) => (<Select.Option key={option.value} value={option.value}>
495
- <Text weight="medium">{option.label}</Text>
496
- <Text weight="regular" color="neutral-faded">
497
- {option.subtitle}
498
- </Text>
499
- </Select.Option>))}
500
- </Select.Custom>
501
- </Example.Item>
502
- </Example>);
503
- },
504
- };
505
- export const error = {
506
- name: "error",
507
- render: () => (<Example>
508
- <Example.Item title="error">
509
- <Select.Custom name="animal" placeholder="Select an animal" hasError>
510
- <Select.Option value="dog">Dog</Select.Option>
511
- <Select.Option value="turtle">Turtle</Select.Option>
512
- </Select.Custom>
513
- </Example.Item>
514
- </Example>),
515
- };
516
- export const disabled = {
517
- name: "disabled",
518
- render: () => (<Example>
519
- <Example.Item title="disabled, native">
520
- <Select name="animal" placeholder="Select an animal" disabled inputAttributes={{ "aria-label": "Select an animal" }}>
521
- <option value="dog">Dog</option>
522
- <option value="turtle">Turtle</option>
523
- </Select>
524
- </Example.Item>
525
- <Example.Item title="disabled, custom">
526
- <Select.Custom name="animal-2" placeholder="Select an animal" disabled inputAttributes={{ "aria-label": "Select an animal" }}>
527
- <Select.Option value="dog">Dog</Select.Option>
528
- <Select.Option value="turtle">Turtle</Select.Option>
529
- </Select.Custom>
530
- </Example.Item>
531
- </Example>),
532
- play: ({ canvas }) => {
533
- const [native] = canvas.getAllByRole("combobox");
534
- const [custom] = canvas.getAllByRole("button");
535
- expect(native).toBeDisabled();
536
- expect(custom).toBeDisabled();
537
- },
538
- };
539
- export const className = {
540
- name: "className, attributes, inputAttributes",
541
- render: () => (<Example>
542
- <Example.Item title="native, className, attributes, inputAttributes">
543
- <Select name="animal" placeholder="Select an animal" className="native-class" attributes={{ id: "test-id" }} inputAttributes={{ "aria-label": "test-label" }}>
544
- <option value="dog">Dog</option>
545
- <option value="turtle">Turtle</option>
546
- </Select>
547
- </Example.Item>
548
- <Example.Item title="custom, className, attributes, inputAttributes">
549
- <Select.Custom name="animal" placeholder="Select an animal" className="custom-class" attributes={{ id: "test-id" }} inputAttributes={{ "aria-label": "test-label" }}>
550
- <Select.Option value="dog">Dog</Select.Option>
551
- <Select.Option value="turtle">Turtle</Select.Option>
552
- </Select.Custom>
553
- </Example.Item>
554
- </Example>),
555
- play: ({ canvas, canvasElement }) => {
556
- const native = canvasElement.querySelector(".native-class");
557
- const nativeInput = canvas.getByRole("combobox");
558
- const custom = canvasElement.querySelector(".custom-class");
559
- const [customTrigger] = canvas.getAllByRole("button");
560
- expect(native).toHaveAttribute("id", "test-id");
561
- expect(nativeInput).toHaveAttribute("aria-label", "test-label");
562
- expect(custom).toHaveAttribute("id", "test-id");
563
- expect(customTrigger).toHaveAttribute("aria-label", "test-label");
564
- },
565
- };
566
- export const fallback = {
567
- name: "test: fallbackAdjustLayout",
568
- render: () => (<Example>
569
- <Example.Item title="fallback">
570
- <Select.Custom name="animal" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
571
- {[...Array(100)].map((_, index) => (<Select.Option key={index} value={`item-${index}`}>
572
- Item {index + 1}
573
- </Select.Option>))}
574
- </Select.Custom>
575
- <div style={{ height: "1000px" }}></div>
576
- <Select.Custom name="animal" placeholder="Select an animal" inputAttributes={{ "aria-label": "Select an animal" }}>
577
- {[...Array(100)].map((_, index) => (<Select.Option key={index} value={`item-${index}`}>
578
- Item {index + 1}
579
- </Select.Option>))}
580
- </Select.Custom>
581
- </Example.Item>
582
- </Example>),
583
- };
584
- export const formControl = {
585
- name: "test: with FormControl",
586
- render: () => (<Example>
587
- <Example.Item title="FormControl">
588
- <FormControl hasError>
589
- <FormControl.Label>Animal</FormControl.Label>
590
- <Select.Custom name="animal" placeholder="Select an animal">
591
- <Select.Option value="dog">Dog</Select.Option>
592
- <Select.Option value="turtle">Turtle</Select.Option>
593
- </Select.Custom>
594
- <FormControl.Error>This field is required</FormControl.Error>
595
- </FormControl>
596
- </Example.Item>
597
- </Example>),
598
- };
599
- export const testComposition = {
600
- name: "test: composition",
601
- render: () => (<Example>
602
- <Example.Item title="custom with options">
603
- <Select.Custom name="animal" id="animal" placeholder="Select an animal" inputAttributes={{
604
- "aria-label": "Select an animal",
605
- }}>
606
- <Select.Group>
607
- <Select.Option value="dog">Dog</Select.Option>
608
- <Select.Option value="turtle">Turtle</Select.Option>
609
- </Select.Group>
610
- <Select.Group>
611
- <div>hello</div>
612
- </Select.Group>
613
- </Select.Custom>
614
- </Example.Item>
615
- </Example>),
616
- };
@@ -1,20 +0,0 @@
1
- import { StoryObj } from "@storybook/react-vite";
2
- declare const _default: {
3
- title: string;
4
- component: import("react").FC<import("./..").SkeletonProps>;
5
- parameters: {
6
- iframe: {
7
- url: string;
8
- };
9
- };
10
- };
11
- export default _default;
12
- export declare const variant: {
13
- name: string;
14
- render: () => import("react").JSX.Element;
15
- };
16
- export declare const radius: {
17
- name: string;
18
- render: () => import("react").JSX.Element;
19
- };
20
- export declare const className: StoryObj;