reshaped 3.3.10 → 3.3.12

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 (284) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/bundle.css +1 -1
  3. package/dist/bundle.js +10 -10
  4. package/dist/cjs/themes/_generator/utilities/generateColors.d.ts +1 -1
  5. package/dist/cjs/themes/_generator/utilities/generateColors.js +3 -2
  6. package/dist/cjs/themes/_generator/utilities/tests/color.test.js +32 -31
  7. package/dist/cjs/themes/slate/theme.css +1 -1
  8. package/dist/components/Accordion/tests/Accordion.stories.d.ts +30 -8
  9. package/dist/components/Accordion/tests/Accordion.stories.js +172 -119
  10. package/dist/components/ActionBar/tests/ActionBar.stories.d.ts +12 -3
  11. package/dist/components/ActionBar/tests/ActionBar.stories.js +51 -36
  12. package/dist/components/ActionBar/tests/ActionBar.test.stories.d.ts +15 -0
  13. package/dist/components/ActionBar/tests/ActionBar.test.stories.js +26 -0
  14. package/dist/components/Actionable/Actionable.js +1 -1
  15. package/dist/components/Actionable/Actionable.types.d.ts +3 -3
  16. package/dist/components/Actionable/tests/Actionable.stories.d.ts +19 -5
  17. package/dist/components/Actionable/tests/Actionable.stories.js +88 -63
  18. package/dist/components/Actionable/tests/Actionable.test.stories.d.ts +32 -0
  19. package/dist/components/Actionable/tests/Actionable.test.stories.js +130 -0
  20. package/dist/components/Alert/Alert.js +1 -1
  21. package/dist/components/Alert/tests/Alert.stories.d.ts +12 -3
  22. package/dist/components/Alert/tests/Alert.stories.js +51 -86
  23. package/dist/components/Alert/tests/Alert.test.stories.d.ts +15 -0
  24. package/dist/components/Alert/tests/Alert.test.stories.js +26 -0
  25. package/dist/components/Autocomplete/Autocomplete.js +9 -2
  26. package/dist/components/Autocomplete/tests/Autocomplete.stories.d.ts +6 -2
  27. package/dist/components/Autocomplete/tests/Autocomplete.stories.js +94 -111
  28. package/dist/components/Autocomplete/tests/Autocomplete.test.stories.d.ts +23 -0
  29. package/dist/components/Autocomplete/tests/Autocomplete.test.stories.js +86 -0
  30. package/dist/components/Avatar/Avatar.js +1 -1
  31. package/dist/components/Avatar/tests/Avatar.stories.d.ts +14 -4
  32. package/dist/components/Avatar/tests/Avatar.stories.js +94 -80
  33. package/dist/components/Avatar/tests/Avatar.test.stories.d.ts +17 -0
  34. package/dist/components/Avatar/tests/Avatar.test.stories.js +39 -0
  35. package/dist/components/Badge/tests/Badge.stories.d.ts +33 -8
  36. package/dist/components/Badge/tests/Badge.stories.js +238 -212
  37. package/dist/components/Badge/tests/Badge.test.stories.d.ts +20 -0
  38. package/dist/components/Badge/tests/Badge.test.stories.js +44 -0
  39. package/dist/components/Breadcrumbs/Breadcrumbs.js +2 -2
  40. package/dist/components/Breadcrumbs/Breadcrumbs.types.d.ts +1 -0
  41. package/dist/components/Breadcrumbs/tests/Breadcrumbs.stories.d.ts +24 -5
  42. package/dist/components/Breadcrumbs/tests/Breadcrumbs.stories.js +114 -95
  43. package/dist/components/Breadcrumbs/tests/Breadcrumbs.test.stories.d.ts +23 -0
  44. package/dist/components/Breadcrumbs/tests/Breadcrumbs.test.stories.js +76 -0
  45. package/dist/components/Button/Button.js +5 -2
  46. package/dist/components/Button/Button.module.css +1 -1
  47. package/dist/components/Button/Button.types.d.ts +1 -0
  48. package/dist/components/Button/tests/Button.stories.d.ts +2 -2
  49. package/dist/components/Button/tests/Button.stories.js +77 -74
  50. package/dist/components/Button/tests/Button.test.stories.d.ts +27 -0
  51. package/dist/components/Button/tests/Button.test.stories.js +112 -0
  52. package/dist/components/Calendar/tests/Calendar.test.stories.d.ts +26 -0
  53. package/dist/components/Calendar/tests/Calendar.test.stories.js +161 -0
  54. package/dist/components/Card/Card.d.ts +3 -3
  55. package/dist/components/Card/Card.types.d.ts +1 -1
  56. package/dist/components/Card/tests/Card.stories.d.ts +3 -4
  57. package/dist/components/Card/tests/Card.stories.js +0 -11
  58. package/dist/components/Card/tests/Card.test.stories.d.ts +35 -0
  59. package/dist/components/Card/tests/Card.test.stories.js +54 -0
  60. package/dist/components/Carousel/Carousel.types.d.ts +1 -1
  61. package/dist/components/Carousel/CarouselControl.js +1 -1
  62. package/dist/components/Carousel/tests/Carousel.stories.d.ts +3 -0
  63. package/dist/components/Carousel/tests/Carousel.stories.js +5 -1
  64. package/dist/components/Carousel/tests/Carousel.test.stories.d.ts +17 -0
  65. package/dist/components/Carousel/tests/Carousel.test.stories.js +52 -0
  66. package/dist/components/Checkbox/tests/Checkbox.test.stories.d.ts +25 -0
  67. package/dist/components/Checkbox/tests/Checkbox.test.stories.js +104 -0
  68. package/dist/components/CheckboxGroup/tests/CheckboxGroup.test.stories.d.ts +22 -0
  69. package/dist/components/CheckboxGroup/tests/CheckboxGroup.test.stories.js +78 -0
  70. package/dist/components/Container/Container.module.css +1 -1
  71. package/dist/components/Container/tests/Container.stories.d.ts +12 -3
  72. package/dist/components/Container/tests/Container.stories.js +50 -31
  73. package/dist/components/Container/tests/Container.test.stories.d.ts +15 -0
  74. package/dist/components/Container/tests/Container.test.stories.js +26 -0
  75. package/dist/components/ContextMenu/ContextMenu.js +13 -9
  76. package/dist/components/ContextMenu/tests/ContextMenu.stories.js +2 -3
  77. package/dist/components/ContextMenu/tests/ContextMenu.test.stories.d.ts +26 -0
  78. package/dist/components/ContextMenu/tests/ContextMenu.test.stories.js +53 -0
  79. package/dist/components/Dismissible/Dismissible.js +1 -1
  80. package/dist/components/Dismissible/tests/Dismissible.stories.d.ts +10 -3
  81. package/dist/components/Dismissible/tests/Dismissible.stories.js +51 -34
  82. package/dist/components/Dismissible/tests/Dismissible.test.stories.d.ts +19 -0
  83. package/dist/components/Dismissible/tests/Dismissible.test.stories.js +42 -0
  84. package/dist/components/Divider/tests/Divider.test.stories.d.ts +18 -0
  85. package/dist/components/Divider/tests/Divider.test.stories.js +47 -0
  86. package/dist/components/DropdownMenu/DropdownMenu.js +1 -1
  87. package/dist/components/DropdownMenu/tests/DropdownMenu.test.stories.d.ts +37 -0
  88. package/dist/components/DropdownMenu/tests/DropdownMenu.test.stories.js +117 -0
  89. package/dist/components/FileUpload/tests/FileUpload.test.stories.d.ts +22 -0
  90. package/dist/components/FileUpload/tests/FileUpload.test.stories.js +52 -0
  91. package/dist/components/FormControl/FormControl.context.d.ts +12 -0
  92. package/dist/components/FormControl/FormControlCaption.js +1 -1
  93. package/dist/components/FormControl/FormControlLabel.js +1 -1
  94. package/dist/components/FormControl/tests/FormControl.stories.d.ts +11 -5
  95. package/dist/components/FormControl/tests/FormControl.stories.js +78 -73
  96. package/dist/components/FormControl/tests/FormControl.test.stories.d.ts +20 -0
  97. package/dist/components/FormControl/tests/FormControl.test.stories.js +49 -0
  98. package/dist/components/Grid/Grid.d.ts +2 -2
  99. package/dist/components/Grid/Grid.types.d.ts +3 -2
  100. package/dist/components/Grid/tests/Grid.stories.d.ts +22 -7
  101. package/dist/components/Grid/tests/Grid.stories.js +164 -149
  102. package/dist/components/Grid/tests/Grid.test.stories.d.ts +19 -0
  103. package/dist/components/Grid/tests/Grid.test.stories.js +42 -0
  104. package/dist/components/Hidden/Hidden.types.d.ts +1 -1
  105. package/dist/components/Hidden/tests/Hidden.stories.d.ts +4 -1
  106. package/dist/components/Hidden/tests/Hidden.stories.js +28 -25
  107. package/dist/components/Hidden/tests/Hidden.test.stories.d.ts +15 -0
  108. package/dist/components/Hidden/tests/Hidden.test.stories.js +20 -0
  109. package/dist/components/HiddenVisually/tests/HiddenVisually.stories.d.ts +4 -1
  110. package/dist/components/HiddenVisually/tests/HiddenVisually.stories.js +8 -5
  111. package/dist/components/HiddenVisually/tests/HiddenVisually.test.stories.d.ts +15 -0
  112. package/dist/components/HiddenVisually/tests/HiddenVisually.test.stories.js +20 -0
  113. package/dist/components/Hotkey/tests/Hotkey.test.stories.d.ts +15 -0
  114. package/dist/components/Hotkey/tests/Hotkey.test.stories.js +26 -0
  115. package/dist/components/Icon/tests/Icon.stories.d.ts +12 -3
  116. package/dist/components/Icon/tests/Icon.stories.js +69 -60
  117. package/dist/components/Icon/tests/Icon.test.stories.d.ts +16 -0
  118. package/dist/components/Icon/tests/Icon.test.stories.js +35 -0
  119. package/dist/components/Image/tests/Image.stories.d.ts +24 -5
  120. package/dist/components/Image/tests/Image.stories.js +95 -75
  121. package/dist/components/Image/tests/Image.test.stories.d.ts +25 -0
  122. package/dist/components/Image/tests/Image.test.stories.js +80 -0
  123. package/dist/components/Link/tests/Link.test.stories.d.ts +29 -0
  124. package/dist/components/Link/tests/Link.test.stories.js +87 -0
  125. package/dist/components/Loader/Loader.js +1 -1
  126. package/dist/components/Loader/Loader.types.d.ts +1 -0
  127. package/dist/components/Loader/tests/Loader.stories.js +8 -8
  128. package/dist/components/Loader/tests/Loader.test.stories.d.ts +16 -0
  129. package/dist/components/Loader/tests/Loader.test.stories.js +32 -0
  130. package/dist/components/MenuItem/tests/MenuItem.test.stories.d.ts +26 -0
  131. package/dist/components/MenuItem/tests/MenuItem.test.stories.js +100 -0
  132. package/dist/components/Modal/Modal.types.d.ts +1 -1
  133. package/dist/components/Modal/tests/Modal.test.stories.d.ts +32 -0
  134. package/dist/components/Modal/tests/Modal.test.stories.js +149 -0
  135. package/dist/components/Overlay/Overlay.types.d.ts +1 -1
  136. package/dist/components/Overlay/tests/Overlay.stories.d.ts +4 -2
  137. package/dist/components/Overlay/tests/Overlay.stories.js +53 -53
  138. package/dist/components/Overlay/tests/Overlay.test.stories.d.ts +28 -0
  139. package/dist/components/Overlay/tests/Overlay.test.stories.js +146 -0
  140. package/dist/components/Pagination/tests/Pagination.test.stories.d.ts +23 -0
  141. package/dist/components/Pagination/tests/Pagination.test.stories.js +86 -0
  142. package/dist/components/PinField/tests/PinField.stories.d.ts +0 -1
  143. package/dist/components/PinField/tests/PinField.stories.js +10 -19
  144. package/dist/components/PinField/tests/PinField.test.stories.d.ts +29 -0
  145. package/dist/components/PinField/tests/PinField.test.stories.js +177 -0
  146. package/dist/components/Popover/tests/Popover.test.stories.d.ts +40 -0
  147. package/dist/components/Popover/tests/Popover.test.stories.js +167 -0
  148. package/dist/components/Progress/Progress.js +2 -2
  149. package/dist/components/Progress/Progress.types.d.ts +1 -0
  150. package/dist/components/Progress/tests/Progress.stories.js +10 -10
  151. package/dist/components/Progress/tests/Progress.test.stories.d.ts +16 -0
  152. package/dist/components/Progress/tests/Progress.test.stories.js +35 -0
  153. package/dist/components/Radio/tests/Radio.test.stories.d.ts +30 -0
  154. package/dist/components/Radio/tests/Radio.test.stories.js +118 -0
  155. package/dist/components/RadioGroup/tests/RadioGroup.test.stories.d.ts +22 -0
  156. package/dist/components/RadioGroup/tests/RadioGroup.test.stories.js +78 -0
  157. package/dist/components/Reshaped/tests/Reshaped.stories.d.ts +33 -0
  158. package/dist/components/Reshaped/tests/Reshaped.stories.js +88 -0
  159. package/dist/components/Resizable/Resizable.js +4 -1
  160. package/dist/components/Resizable/Resizable.types.d.ts +2 -2
  161. package/dist/components/Resizable/tests/Resizable.stories.d.ts +3 -0
  162. package/dist/components/Resizable/tests/Resizable.stories.js +4 -0
  163. package/dist/components/Resizable/tests/Resizable.test.stories.d.ts +19 -0
  164. package/dist/components/Resizable/tests/Resizable.test.stories.js +25 -0
  165. package/dist/components/Scrim/tests/Scrim.test.stories.d.ts +15 -0
  166. package/dist/components/Scrim/tests/Scrim.test.stories.js +25 -0
  167. package/dist/components/ScrollArea/ScrollArea.js +1 -1
  168. package/dist/components/ScrollArea/ScrollArea.module.css +1 -1
  169. package/dist/components/ScrollArea/tests/ScrollArea.stories.d.ts +17 -4
  170. package/dist/components/ScrollArea/tests/ScrollArea.stories.js +114 -139
  171. package/dist/components/ScrollArea/tests/ScrollArea.test.stories.d.ts +23 -0
  172. package/dist/components/ScrollArea/tests/ScrollArea.test.stories.js +66 -0
  173. package/dist/components/Select/tests/Select.stories.d.ts +1 -1
  174. package/dist/components/Select/tests/Select.stories.js +5 -12
  175. package/dist/components/Select/tests/Select.test.stories.d.ts +27 -0
  176. package/dist/components/Select/tests/Select.test.stories.js +132 -0
  177. package/dist/components/Skeleton/tests/Skeleton.test.stories.d.ts +15 -0
  178. package/dist/components/Skeleton/tests/Skeleton.test.stories.js +23 -0
  179. package/dist/components/Slider/Slider.types.d.ts +1 -1
  180. package/dist/components/Slider/tests/Slider.stories.d.ts +0 -1
  181. package/dist/components/Slider/tests/Slider.stories.js +8 -9
  182. package/dist/components/Slider/tests/Slider.test.stories.d.ts +38 -0
  183. package/dist/components/Slider/tests/Slider.test.stories.js +150 -0
  184. package/dist/components/Stepper/Stepper.js +1 -1
  185. package/dist/components/Stepper/tests/Stepper.stories.js +0 -3
  186. package/dist/components/Stepper/tests/Stepper.test.stories.d.ts +18 -0
  187. package/dist/components/Stepper/tests/Stepper.test.stories.js +28 -0
  188. package/dist/components/Switch/tests/Switch.test.stories.d.ts +23 -0
  189. package/dist/components/Switch/tests/Switch.test.stories.js +79 -0
  190. package/dist/components/Table/tests/Table.test.stories.d.ts +25 -0
  191. package/dist/components/Table/tests/Table.test.stories.js +93 -0
  192. package/dist/components/Tabs/Tabs.types.d.ts +3 -3
  193. package/dist/components/Tabs/TabsContext.d.ts +3 -3
  194. package/dist/components/Tabs/TabsItem.js +1 -1
  195. package/dist/components/Tabs/tests/Tabs.stories.js +4 -4
  196. package/dist/components/Tabs/tests/Tabs.test.stories.d.ts +28 -0
  197. package/dist/components/Tabs/tests/Tabs.test.stories.js +128 -0
  198. package/dist/components/Text/Text.d.ts +1 -1
  199. package/dist/components/Text/Text.types.d.ts +1 -1
  200. package/dist/components/Text/tests/Text.stories.d.ts +29 -8
  201. package/dist/components/Text/tests/Text.stories.js +148 -125
  202. package/dist/components/Text/tests/Text.test.stories.d.ts +18 -0
  203. package/dist/components/Text/tests/Text.test.stories.js +49 -0
  204. package/dist/components/TextArea/TextArea.module.css +1 -1
  205. package/dist/components/TextArea/tests/TextArea.stories.js +1 -1
  206. package/dist/components/TextArea/tests/TextArea.test.stories.d.ts +29 -0
  207. package/dist/components/TextArea/tests/TextArea.test.stories.js +99 -0
  208. package/dist/components/TextField/TextField.js +3 -1
  209. package/dist/components/TextField/tests/TextField.stories.js +1 -1
  210. package/dist/components/TextField/tests/TextField.test.stories.d.ts +29 -0
  211. package/dist/components/TextField/tests/TextField.test.stories.js +99 -0
  212. package/dist/components/Theme/Theme.types.d.ts +2 -2
  213. package/dist/components/Theme/tests/Theme.test.stories.d.ts +24 -0
  214. package/dist/components/Theme/tests/Theme.test.stories.js +133 -0
  215. package/dist/components/Timeline/tests/Timeline.test.stories.d.ts +18 -0
  216. package/dist/components/Timeline/tests/Timeline.test.stories.js +32 -0
  217. package/dist/components/Toast/ToastContainer.js +1 -1
  218. package/dist/components/Toast/tests/Toast.test.stories.d.ts +16 -0
  219. package/dist/components/Toast/tests/Toast.test.stories.js +101 -0
  220. package/dist/components/Tooltip/Tooltip.d.ts +1 -1
  221. package/dist/components/Tooltip/tests/Tooltip.stories.d.ts +1 -1
  222. package/dist/components/Tooltip/tests/Tooltip.stories.js +0 -14
  223. package/dist/components/Tooltip/tests/Tooltip.test.stories.d.ts +19 -0
  224. package/dist/components/Tooltip/tests/Tooltip.test.stories.js +40 -0
  225. package/dist/components/View/View.d.ts +2 -2
  226. package/dist/components/View/View.js +4 -4
  227. package/dist/components/View/View.types.d.ts +2 -2
  228. package/dist/components/View/tests/View.stories.d.ts +114 -30
  229. package/dist/components/View/tests/View.stories.js +1092 -1012
  230. package/dist/components/View/tests/View.test.stories.d.ts +20 -0
  231. package/dist/components/View/tests/View.test.stories.js +50 -0
  232. package/dist/components/_private/Flyout/Flyout.types.d.ts +6 -6
  233. package/dist/components/_private/Flyout/FlyoutContent.js +1 -1
  234. package/dist/components/_private/Flyout/FlyoutControlled.js +5 -3
  235. package/dist/components/_private/Flyout/tests/Flyout.stories.js +5 -5
  236. package/dist/components/_private/Flyout/tests/Flyout.test.stories.d.ts +28 -0
  237. package/dist/components/_private/Flyout/tests/Flyout.test.stories.js +205 -0
  238. package/dist/components/_private/Flyout/useFlyout.d.ts +3 -3
  239. package/dist/components/_private/Portal/Portal.types.d.ts +3 -3
  240. package/dist/components/_private/Portal/tests/Portal.stories.js +1 -1
  241. package/dist/hooks/_private/useIsDismissible.d.ts +1 -1
  242. package/dist/hooks/_private/useOnClickOutside.d.ts +1 -1
  243. package/dist/hooks/_private/useSingletonHotkeys.d.ts +3 -3
  244. package/dist/hooks/_private/useSingletonHotkeys.js +1 -1
  245. package/dist/hooks/tests/useDrag.stories.js +1 -0
  246. package/dist/hooks/tests/useDrag.test.stories.d.ts +26 -0
  247. package/dist/hooks/tests/useDrag.test.stories.js +120 -0
  248. package/dist/hooks/tests/useElementId.stories.d.ts +6 -0
  249. package/dist/hooks/tests/useElementId.stories.js +19 -0
  250. package/dist/hooks/tests/useHotkeys.test.stories.d.ts +39 -0
  251. package/dist/hooks/tests/useHotkeys.test.stories.js +119 -0
  252. package/dist/hooks/tests/useRTL.stories.d.ts +6 -0
  253. package/dist/hooks/tests/useRTL.stories.js +25 -0
  254. package/dist/hooks/tests/useResponsiveClientValue.stories.d.ts +9 -1
  255. package/dist/hooks/tests/useResponsiveClientValue.stories.js +22 -9
  256. package/dist/hooks/tests/useScrollLock.stories.d.ts +6 -0
  257. package/dist/hooks/tests/useScrollLock.stories.js +22 -0
  258. package/dist/hooks/tests/useToggle.stories.d.ts +8 -0
  259. package/dist/hooks/tests/useToggle.stories.js +54 -0
  260. package/dist/hooks/useDrag.d.ts +3 -3
  261. package/dist/hooks/useHotkeys.d.ts +2 -2
  262. package/dist/hooks/useHotkeys.js +3 -1
  263. package/dist/hooks/useScrollLock.d.ts +2 -1
  264. package/dist/hooks/useScrollLock.js +7 -3
  265. package/dist/tests/ShadowDOM.stories.js +1 -1
  266. package/dist/themes/_generator/tests/themes.stories.d.ts +3 -0
  267. package/dist/themes/_generator/tests/themes.stories.js +7 -11
  268. package/dist/themes/_generator/utilities/generateColors.d.ts +1 -1
  269. package/dist/themes/_generator/utilities/generateColors.js +3 -2
  270. package/dist/themes/slate/theme.css +1 -1
  271. package/dist/types/global.d.ts +1 -1
  272. package/dist/utilities/helpers.d.ts +1 -0
  273. package/dist/utilities/helpers.js +3 -0
  274. package/dist/utilities/scroll/lock.d.ts +1 -0
  275. package/dist/utilities/scroll/lock.js +3 -3
  276. package/dist/utilities/scroll/lockSafari.d.ts +1 -1
  277. package/dist/utilities/scroll/lockSafari.js +4 -5
  278. package/dist/utilities/scroll/lockStandard.d.ts +4 -1
  279. package/dist/utilities/scroll/lockStandard.js +7 -2
  280. package/dist/utilities/storybook/Example.js +1 -2
  281. package/package.json +22 -21
  282. package/dist/components/Theme/tests/Theme.stories.d.ts +0 -13
  283. package/dist/components/Theme/tests/Theme.stories.js +0 -80
  284. package/dist/utilities/storybook/Example.module.css +0 -1
@@ -0,0 +1,20 @@
1
+ import { StoryObj } from "@storybook/react";
2
+ declare const _default: {
3
+ title: string;
4
+ component: {
5
+ <As extends keyof React.JSX.IntrinsicElements = "div">(props: import("./..").ViewProps<As>): React.ReactNode;
6
+ Item: <As extends keyof React.JSX.IntrinsicElements = "div">(props: import("./..").ViewItemProps<As>) => React.ReactNode;
7
+ };
8
+ parameters: {
9
+ iframe: {
10
+ url: string;
11
+ };
12
+ chromatic: {
13
+ disableSnapshot: boolean;
14
+ };
15
+ };
16
+ };
17
+ export default _default;
18
+ export declare const asProp: StoryObj;
19
+ export declare const className: StoryObj;
20
+ export declare const itemClassName: StoryObj;
@@ -0,0 +1,50 @@
1
+ import { expect } from "@storybook/test";
2
+ import View from "../index.js";
3
+ export default {
4
+ title: "Utilities/View/tests",
5
+ component: View,
6
+ parameters: {
7
+ iframe: {
8
+ url: "https://reshaped.so/docs/utilities/view",
9
+ },
10
+ chromatic: { disableSnapshot: true },
11
+ },
12
+ };
13
+ export const asProp = {
14
+ name: "as",
15
+ render: () => (<View as="ul">
16
+ <View.Item as="li">Content</View.Item>
17
+ </View>),
18
+ play: async ({ canvas }) => {
19
+ const list = canvas.getByRole("list");
20
+ const item = canvas.getByRole("listitem");
21
+ expect(list).toBeInTheDocument();
22
+ expect(item).toBeInTheDocument();
23
+ },
24
+ };
25
+ export const className = {
26
+ name: "className, attributes",
27
+ render: () => (<div data-testid="root">
28
+ <View className="test-classname" attributes={{ id: "test-id" }}>
29
+ Content
30
+ </View>
31
+ </div>),
32
+ play: async ({ canvas }) => {
33
+ const root = canvas.getByTestId("root").firstChild;
34
+ expect(root).toHaveClass("test-classname");
35
+ expect(root).toHaveAttribute("id", "test-id");
36
+ },
37
+ };
38
+ export const itemClassName = {
39
+ name: "item className, attributes",
40
+ render: () => (<div data-testid="root">
41
+ <View.Item className="test-classname" attributes={{ id: "test-id" }}>
42
+ Content
43
+ </View.Item>
44
+ </div>),
45
+ play: async ({ canvas }) => {
46
+ const root = canvas.getByTestId("root").firstChild;
47
+ expect(root).toHaveClass("test-classname");
48
+ expect(root).toHaveAttribute("id", "test-id");
49
+ },
50
+ };
@@ -44,7 +44,7 @@ export type Instance = {
44
44
  open: () => void;
45
45
  close: () => void;
46
46
  updatePosition: () => void;
47
- } | undefined;
47
+ } | null;
48
48
  type WithUncontrolled = {
49
49
  active?: never;
50
50
  defaultActive?: boolean;
@@ -54,7 +54,7 @@ type WithControlled = {
54
54
  defaultActive?: never;
55
55
  };
56
56
  export type TriggerAttributes = {
57
- ref: React.RefObject<HTMLButtonElement>;
57
+ ref: React.RefObject<HTMLButtonElement | null>;
58
58
  onBlur?: (e: React.FocusEvent) => void;
59
59
  onFocus?: () => void;
60
60
  onMouseDown?: () => void;
@@ -93,8 +93,8 @@ type BaseProps = {
93
93
  contentClassName?: string;
94
94
  contentAttributes?: G.Attributes<"div">;
95
95
  instanceRef?: React.Ref<Instance>;
96
- containerRef?: React.RefObject<HTMLElement>;
97
- initialFocusRef?: React.RefObject<HTMLElement>;
96
+ containerRef?: React.RefObject<HTMLElement | null>;
97
+ initialFocusRef?: React.RefObject<HTMLElement | null>;
98
98
  };
99
99
  export type DefaultProps = Required<{
100
100
  position: BaseProps["position"];
@@ -115,8 +115,8 @@ export type ContextProps = {
115
115
  id: string;
116
116
  flyout: UseFlyoutData;
117
117
  width?: Width;
118
- triggerElRef?: React.RefObject<HTMLButtonElement>;
119
- flyoutElRef: React.RefObject<HTMLDivElement>;
118
+ triggerElRef?: React.RefObject<HTMLButtonElement | null>;
119
+ flyoutElRef: React.RefObject<HTMLDivElement | null>;
120
120
  handleClose: (options?: {
121
121
  closeParents?: boolean;
122
122
  }) => void;
@@ -51,7 +51,7 @@ const FlyoutContent = (props) => {
51
51
  const content = (_jsx(ContentProvider, { value: { elRef: flyoutElRef }, children: _jsx("div", { className: contentClassNames, style: {
52
52
  ...styles,
53
53
  "--rs-flyout-gap": contentGap,
54
- }, ref: flyoutElRef, onTransitionEnd: handleTransitionEnd, onMouseEnter: triggerType === "hover" ? handleMouseEnter : undefined, onMouseLeave: triggerType === "hover" ? handleMouseLeave : undefined, onMouseDown: handleContentMouseDown, onTouchStart: handleContentMouseDown, onMouseUp: handleContentMouseUp, onTouchEnd: handleContentMouseUp, children: _jsx("div", { role: role, ...attributes, id: id, "aria-modal": triggerType === "click", style: contentAttributes?.style, className: innerClassNames, children: children }) }) }));
54
+ }, ref: flyoutElRef, onTransitionEnd: handleTransitionEnd, onMouseEnter: triggerType === "hover" ? handleMouseEnter : undefined, onMouseLeave: triggerType === "hover" ? handleMouseLeave : undefined, onMouseDown: handleContentMouseDown, onTouchStart: handleContentMouseDown, onMouseUp: handleContentMouseUp, onTouchEnd: handleContentMouseUp, children: _jsx("div", { role: role, ...attributes, id: id, "aria-modal": role === "dialog" ? true : undefined, style: contentAttributes?.style, className: innerClassNames, children: children }) }) }));
55
55
  const closestScrollable = triggerElRef && findClosestRenderContainer({ el: triggerElRef.current });
56
56
  const scrollableRef = closestScrollable === document.body || !closestScrollable
57
57
  ? undefined
@@ -37,10 +37,10 @@ const FlyoutRoot = (props) => {
37
37
  const isParentTriggerInsideFlyout = !!parentTriggerRef?.current && parentContentRef?.current?.contains(parentTriggerRef.current);
38
38
  const tryParentTrigger = !parentContentRef || isParentTriggerInsideFlyout;
39
39
  const triggerElRef = (tryParentTrigger && parentTriggerRef) || internalTriggerElRef;
40
- const triggerBoundsRef = React.useRef();
40
+ const triggerBoundsRef = React.useRef(null);
41
41
  const flyoutElRef = React.useRef(null);
42
42
  const id = useElementId(passedId);
43
- const timerRef = React.useRef();
43
+ const timerRef = React.useRef(null);
44
44
  const trapFocusRef = React.useRef(null);
45
45
  const lockedRef = React.useRef(false);
46
46
  // Check if transition had enough time to start when opening a flyout
@@ -154,6 +154,8 @@ const FlyoutRoot = (props) => {
154
154
  }, [isRendered, handleOpen, handleClose]);
155
155
  const handleTriggerMouseDown = React.useCallback(() => {
156
156
  const rect = triggerElRef.current?.getBoundingClientRect();
157
+ if (!rect)
158
+ return;
157
159
  triggerBoundsRef.current = rect;
158
160
  }, [triggerElRef]);
159
161
  const handleContentMouseDown = () => {
@@ -173,7 +175,7 @@ const FlyoutRoot = (props) => {
173
175
  * After animation has started, we're sure about the correct bounds
174
176
  * so drop the cache to make flyout work when trigger moves around
175
177
  */
176
- triggerBoundsRef.current = undefined;
178
+ triggerBoundsRef.current = null;
177
179
  }, [resolvedActive]);
178
180
  const handleTransitionEnd = React.useCallback((e) => {
179
181
  if (flyoutElRef.current !== e.currentTarget || e.propertyName !== "transform")
@@ -7,7 +7,7 @@ import Theme from "../../../Theme/index.js";
7
7
  import Button from "../../../Button/index.js";
8
8
  import Flyout from "../index.js";
9
9
  import TextField from "../../../TextField/index.js";
10
- export default { title: "Utilities/Internal/Flyout" };
10
+ export default { title: "Internal/Flyout" };
11
11
  const Demo = (props) => {
12
12
  const { position = "bottom-start", children, ...rest } = props;
13
13
  return (<Flyout triggerType="click" position={position} {...rest}>
@@ -254,7 +254,7 @@ export const testDynamicBounds = () => {
254
254
  const [left, setLeft] = React.useState(50);
255
255
  const [top, setTop] = React.useState(50);
256
256
  const [size, setSize] = React.useState("medium");
257
- const flyoutRef = React.useRef();
257
+ const flyoutRef = React.useRef(null);
258
258
  React.useEffect(() => {
259
259
  flyoutRef.current?.updatePosition();
260
260
  }, [left, top]);
@@ -311,11 +311,11 @@ export const testDisableOutsideClick = () => {
311
311
  };
312
312
  export const testScopedTheming = () => (<View gap={3} align="start">
313
313
  <Button color="primary">Reshaped button</Button>
314
- <Theme name="twitter">
314
+ <Theme name="slate">
315
315
  <Flyout triggerType="click" active position="bottom-start">
316
316
  <Flyout.Trigger>
317
317
  {(attributes) => (<Button color="primary" attributes={attributes}>
318
- Twitter button
318
+ Slate button
319
319
  </Button>)}
320
320
  </Flyout.Trigger>
321
321
  <Flyout.Content>
@@ -327,7 +327,7 @@ export const testScopedTheming = () => (<View gap={3} align="start">
327
327
  }}>
328
328
  <View gap={1}>
329
329
  <View.Item>Portal content, rendered in body</View.Item>
330
- <Button color="primary">Twitter button</Button>
330
+ <Button color="primary">Slate button</Button>
331
331
  </View>
332
332
  </div>
333
333
  </Flyout.Content>
@@ -0,0 +1,28 @@
1
+ import { StoryObj } from "@storybook/react";
2
+ import { fn } from "@storybook/test";
3
+ declare const _default: {
4
+ title: string;
5
+ };
6
+ export default _default;
7
+ export declare const defaultActive: StoryObj<{
8
+ handleOpen: ReturnType<typeof fn>;
9
+ handleClose: ReturnType<typeof fn>;
10
+ }>;
11
+ export declare const active: StoryObj<{
12
+ handleOpen: ReturnType<typeof fn>;
13
+ handleClose: ReturnType<typeof fn>;
14
+ }>;
15
+ export declare const activeFalse: StoryObj<{
16
+ handleOpen: ReturnType<typeof fn>;
17
+ handleClose: ReturnType<typeof fn>;
18
+ }>;
19
+ export declare const triggerType: StoryObj<{
20
+ handleOpen: ReturnType<typeof fn>;
21
+ handleClose: ReturnType<typeof fn>;
22
+ }>;
23
+ export declare const disabled: StoryObj<{
24
+ handleOpen: ReturnType<typeof fn>;
25
+ }>;
26
+ export declare const containerRef: StoryObj;
27
+ export declare const shadowDom: StoryObj;
28
+ export declare const className: StoryObj;
@@ -0,0 +1,205 @@
1
+ import { expect, fn, userEvent, within, waitFor } from "@storybook/test";
2
+ import Flyout from "../index.js";
3
+ import Button from "../../../Button/index.js";
4
+ import Reshaped from "../../../Reshaped/index.js";
5
+ import { useRef } from "react";
6
+ import { createRoot } from "react-dom/client";
7
+ import { sleep } from "../../../../utilities/helpers.js";
8
+ export default {
9
+ title: "Internal/Flyout/tests",
10
+ };
11
+ export const defaultActive = {
12
+ name: "defaultActive, uncontrolled",
13
+ args: {
14
+ handleOpen: fn(),
15
+ handleClose: fn(),
16
+ },
17
+ render: (args) => (<Flyout onOpen={args.handleOpen} onClose={args.handleClose} defaultActive>
18
+ <Flyout.Trigger>
19
+ {(attributes) => <Button attributes={attributes}>Open</Button>}
20
+ </Flyout.Trigger>
21
+ <Flyout.Content>Content</Flyout.Content>
22
+ </Flyout>),
23
+ play: async ({ canvasElement, args }) => {
24
+ const canvas = within(canvasElement.ownerDocument.body);
25
+ const trigger = canvas.getAllByRole("button")[0];
26
+ let item = canvas.getByText("Content");
27
+ await sleep(500);
28
+ await userEvent.click(document.body);
29
+ await waitFor(() => {
30
+ expect(args.handleClose).toHaveBeenCalledTimes(1);
31
+ expect(args.handleClose).toHaveBeenCalledWith();
32
+ expect(item).not.toBeInTheDocument();
33
+ });
34
+ await userEvent.click(trigger);
35
+ await waitFor(() => {
36
+ expect(args.handleOpen).toHaveBeenCalledTimes(1);
37
+ expect(args.handleOpen).toHaveBeenCalledWith();
38
+ });
39
+ item = canvas.getByText("Content");
40
+ expect(item).toBeInTheDocument();
41
+ },
42
+ };
43
+ export const active = {
44
+ name: "active, controlled",
45
+ args: {
46
+ handleOpen: fn(),
47
+ handleClose: fn(),
48
+ },
49
+ render: (args) => (<Flyout onOpen={args.handleOpen} onClose={args.handleClose} active>
50
+ <Flyout.Trigger>
51
+ {(attributes) => <Button attributes={attributes}>Open</Button>}
52
+ </Flyout.Trigger>
53
+ <Flyout.Content>Content</Flyout.Content>
54
+ </Flyout>),
55
+ play: async ({ canvasElement, args }) => {
56
+ const canvas = within(canvasElement.ownerDocument.body);
57
+ const item = canvas.getByText("Content");
58
+ await userEvent.click(document.body);
59
+ await waitFor(() => {
60
+ expect(args.handleClose).toHaveBeenCalledTimes(1);
61
+ expect(args.handleClose).toHaveBeenCalledWith();
62
+ });
63
+ expect(item).toBeInTheDocument();
64
+ },
65
+ };
66
+ export const activeFalse = {
67
+ name: "active false, controlled",
68
+ args: {
69
+ handleOpen: fn(),
70
+ handleClose: fn(),
71
+ },
72
+ render: (args) => (<Flyout onOpen={args.handleOpen} onClose={args.handleClose} active={false}>
73
+ <Flyout.Trigger>
74
+ {(attributes) => <Button attributes={attributes}>Open</Button>}
75
+ </Flyout.Trigger>
76
+ <Flyout.Content>Content</Flyout.Content>
77
+ </Flyout>),
78
+ play: async ({ canvasElement, args }) => {
79
+ const canvas = within(canvasElement.ownerDocument.body);
80
+ const trigger = canvas.getAllByRole("button")[0];
81
+ await userEvent.click(trigger);
82
+ await waitFor(() => {
83
+ expect(args.handleOpen).toHaveBeenCalledTimes(1);
84
+ expect(args.handleOpen).toHaveBeenCalledWith();
85
+ });
86
+ const item = canvas.queryByText("Content");
87
+ expect(item).not.toBeInTheDocument();
88
+ },
89
+ };
90
+ export const triggerType = {
91
+ name: "triggerType hover",
92
+ args: {
93
+ handleOpen: fn(),
94
+ handleClose: fn(),
95
+ },
96
+ render: (args) => (<Flyout onOpen={args.handleOpen} onClose={args.handleClose} triggerType="hover">
97
+ <Flyout.Trigger>
98
+ {(attributes) => <Button attributes={attributes}>Open</Button>}
99
+ </Flyout.Trigger>
100
+ <Flyout.Content>Content</Flyout.Content>
101
+ </Flyout>),
102
+ play: async ({ canvasElement, args }) => {
103
+ const canvas = within(canvasElement.ownerDocument.body);
104
+ const trigger = canvas.getAllByRole("button")[0];
105
+ await userEvent.hover(trigger);
106
+ await waitFor(() => {
107
+ expect(args.handleOpen).toHaveBeenCalledTimes(1);
108
+ expect(args.handleOpen).toHaveBeenCalledWith();
109
+ });
110
+ await userEvent.unhover(trigger);
111
+ await waitFor(() => {
112
+ expect(args.handleClose).toHaveBeenCalledTimes(1);
113
+ expect(args.handleClose).toHaveBeenCalledWith();
114
+ });
115
+ },
116
+ };
117
+ export const disabled = {
118
+ name: "disabled",
119
+ args: {
120
+ handleOpen: fn(),
121
+ },
122
+ render: () => (<div data-testid="root">
123
+ <Flyout disabled>
124
+ <Flyout.Trigger>
125
+ {(attributes) => <Button attributes={attributes}>Open</Button>}
126
+ </Flyout.Trigger>
127
+ <Flyout.Content className="test-classname" attributes={{ "data-testid": "test-id" }}>
128
+ Content
129
+ </Flyout.Content>
130
+ </Flyout>
131
+ </div>),
132
+ play: async ({ canvasElement, args }) => {
133
+ const canvas = within(canvasElement.ownerDocument.body);
134
+ const button = canvas.getAllByRole("button")[0];
135
+ await userEvent.click(button);
136
+ expect(args.handleOpen).toHaveBeenCalledTimes(0);
137
+ },
138
+ };
139
+ export const containerRef = {
140
+ name: "containerRef",
141
+ render: () => {
142
+ const portalRef = useRef(null);
143
+ return (<div ref={portalRef} data-testid="test-id">
144
+ <Flyout containerRef={portalRef} active>
145
+ <Flyout.Trigger>
146
+ {(attributes) => <Button attributes={attributes}>Trigger</Button>}
147
+ </Flyout.Trigger>
148
+ <Flyout.Content>Content</Flyout.Content>
149
+ </Flyout>
150
+ </div>);
151
+ },
152
+ play: async ({ canvasElement }) => {
153
+ const canvas = within(canvasElement.ownerDocument.body);
154
+ const containerEl = canvas.getByTestId("test-id");
155
+ const contentEl = canvas.getByText("Content");
156
+ expect(containerEl).toContainElement(contentEl);
157
+ },
158
+ };
159
+ class CustomElement extends window.HTMLElement {
160
+ constructor() {
161
+ super();
162
+ this.attachShadow({ mode: "open" });
163
+ if (!this.shadowRoot)
164
+ return;
165
+ const root = createRoot(this.shadowRoot);
166
+ root.render(<Reshaped>
167
+ <Flyout active>
168
+ <Flyout.Trigger>
169
+ {(attributes) => <button {...attributes}>Trigger</button>}
170
+ </Flyout.Trigger>
171
+ <Flyout.Content>
172
+ <div id="test-id"/>
173
+ </Flyout.Content>
174
+ </Flyout>
175
+ </Reshaped>);
176
+ }
177
+ }
178
+ window.customElements.define("custom-element-flyout", CustomElement);
179
+ export const shadowDom = {
180
+ name: "shadow DOM",
181
+ // @ts-ignore
182
+ render: () => <custom-element-flyout />,
183
+ play: async () => {
184
+ expect(document.querySelector("custom-element-flyout")?.shadowRoot?.querySelector(`#test-id`)).toBeTruthy();
185
+ expect(document.body.querySelector(`#test-id`)).toBe(null);
186
+ },
187
+ };
188
+ export const className = {
189
+ name: "className, attributes",
190
+ render: () => (<div data-testid="root">
191
+ <Flyout active>
192
+ <Flyout.Trigger>
193
+ {(attributes) => <Button attributes={attributes}>Open</Button>}
194
+ </Flyout.Trigger>
195
+ <Flyout.Content className="test-classname" attributes={{ "data-testid": "test-id" }}>
196
+ Content
197
+ </Flyout.Content>
198
+ </Flyout>
199
+ </div>),
200
+ play: async ({ canvasElement }) => {
201
+ const canvas = within(canvasElement.ownerDocument.body);
202
+ const menu = await canvas.findByTestId("test-id");
203
+ expect(menu).toHaveClass("test-classname");
204
+ },
205
+ };
@@ -9,9 +9,9 @@ type UseFlyout = (args: {
9
9
  contentGap?: number;
10
10
  contentShift?: number;
11
11
  container?: HTMLElement | null;
12
- triggerElRef: React.RefObject<HTMLElement>;
13
- flyoutElRef: React.RefObject<HTMLElement>;
14
- triggerBounds?: DOMRect | G.Coordinates;
12
+ triggerElRef: React.RefObject<HTMLElement | null>;
13
+ flyoutElRef: React.RefObject<HTMLElement | null>;
14
+ triggerBounds?: DOMRect | G.Coordinates | null;
15
15
  }) => Pick<T.State, "styles" | "position" | "status"> & {
16
16
  updatePosition: (options?: {
17
17
  sync?: boolean;
@@ -1,11 +1,11 @@
1
1
  import React from "react";
2
2
  export type Props = {
3
3
  children?: React.ReactNode;
4
- targetRef?: React.RefObject<HTMLElement | ShadowRoot>;
4
+ targetRef?: React.RefObject<HTMLElement | ShadowRoot | null>;
5
5
  };
6
6
  export type ScopeProps<T extends HTMLElement> = {
7
- children: (ref: React.RefObject<T>) => React.ReactNode;
7
+ children: (ref: React.RefObject<T | null>) => React.ReactNode;
8
8
  };
9
9
  export type Context = {
10
- scopeRef: React.RefObject<HTMLElement>;
10
+ scopeRef: React.RefObject<HTMLElement | null>;
11
11
  };
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import Portal from "../index.js";
3
- export default { title: "Utilities/Internal/Portal" };
3
+ export default { title: "Internal/Portal" };
4
4
  export const base = () => {
5
5
  const ref = React.useRef(null);
6
6
  const [mounted, setMounted] = React.useState(false);
@@ -3,7 +3,7 @@
3
3
  * Example: Use to only close the latest opened Flyout/Modal
4
4
  */
5
5
  import React from "react";
6
- type Ref = React.RefObject<HTMLElement>;
6
+ type Ref = React.RefObject<HTMLElement | null>;
7
7
  declare const useIsDismissible: (args: {
8
8
  active?: boolean;
9
9
  contentRef: Ref;
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
- declare const useOnClickOutside: (refs: React.RefObject<HTMLElement>[], handler: (event: Event) => void, deps: any[]) => void;
2
+ declare const useOnClickOutside: (refs: React.RefObject<HTMLElement | null>[], handler: (event: Event) => void, deps: any[]) => void;
3
3
  export default useOnClickOutside;
@@ -10,17 +10,17 @@ type HotkeyOptions = {
10
10
  };
11
11
  type Context = {
12
12
  isPressed: (key: string) => boolean;
13
- addHotkeys: (hotkeys: Hotkeys, ref: React.RefObject<HTMLElement>, options?: HotkeyOptions) => (() => void) | undefined;
13
+ addHotkeys: (hotkeys: Hotkeys, ref: React.RefObject<HTMLElement | null>, options?: HotkeyOptions) => (() => void) | undefined;
14
14
  };
15
15
  type HotkeyData = {
16
16
  callback: Callback;
17
- ref: React.RefObject<HTMLElement>;
17
+ ref: React.RefObject<HTMLElement | null>;
18
18
  options: HotkeyOptions;
19
19
  };
20
20
  export declare class HotkeyStore {
21
21
  hotkeyMap: Record<string, Set<HotkeyData>>;
22
22
  getSize: () => number;
23
- bindHotkeys: (hotkeys: Hotkeys, ref: React.RefObject<HTMLElement>, options: HotkeyOptions) => void;
23
+ bindHotkeys: (hotkeys: Hotkeys, ref: React.RefObject<HTMLElement | null>, options: HotkeyOptions) => void;
24
24
  unbindHotkeys: (hotkeys: Hotkeys) => void;
25
25
  handleKeyDown: (pressedMap: PressedMap, e: KeyboardEvent) => void;
26
26
  }
@@ -82,7 +82,7 @@ export class HotkeyStore {
82
82
  if (hotkeyData?.size) {
83
83
  hotkeyData.forEach((data) => {
84
84
  const eventTarget = e.composedPath()[0];
85
- if (data.ref?.current &&
85
+ if (data.ref.current &&
86
86
  !(eventTarget === data.ref.current || data.ref.current.contains(eventTarget))) {
87
87
  return;
88
88
  }
@@ -17,6 +17,7 @@ function Example() {
17
17
  <View height={8} width={8} borderRadius="small" animated backgroundColor={active ? "primary" : "neutral"} attributes={{
18
18
  role: "button",
19
19
  tabIndex: 0,
20
+ "aria-label": "Drag",
20
21
  ref,
21
22
  style: { translate: `${state.x}px ${state.y}px`, cursor: active ? "grabbing" : "grab" },
22
23
  }}/>
@@ -0,0 +1,26 @@
1
+ import { StoryObj } from "@storybook/react";
2
+ import { fn } from "@storybook/test";
3
+ declare const _default: {
4
+ title: string;
5
+ parameters: {
6
+ chromatic: {
7
+ disableSnapshot: boolean;
8
+ };
9
+ };
10
+ };
11
+ export default _default;
12
+ export declare const mouseEvents: StoryObj<{
13
+ handleDrag: ReturnType<typeof fn>;
14
+ }>;
15
+ export declare const touchEvents: StoryObj<{
16
+ handleDrag: ReturnType<typeof fn>;
17
+ }>;
18
+ export declare const orientationHorizontal: StoryObj<{
19
+ handleDrag: ReturnType<typeof fn>;
20
+ }>;
21
+ export declare const orientationVertical: StoryObj<{
22
+ handleDrag: ReturnType<typeof fn>;
23
+ }>;
24
+ export declare const disabled: StoryObj<{
25
+ handleDrag: ReturnType<typeof fn>;
26
+ }>;
@@ -0,0 +1,120 @@
1
+ import { fireEvent, fn, expect } from "@storybook/test";
2
+ import View from "../../components/View/index.js";
3
+ import useDrag from "../useDrag.js";
4
+ export default {
5
+ title: "Hooks/useDrag/tests",
6
+ parameters: {
7
+ chromatic: { disableSnapshot: true },
8
+ },
9
+ };
10
+ const Demo = (props) => {
11
+ const { ref, containerRef } = useDrag((options) => {
12
+ props.onDrag(options);
13
+ }, {
14
+ orientation: props.orientation,
15
+ disabled: props.disabled,
16
+ });
17
+ return (<View backgroundColor="neutral-faded" width="200px" height="200px" attributes={{ ref: containerRef, "data-testid": "test-id" }}>
18
+ <View height={8} width={8} backgroundColor="primary" attributes={{
19
+ "data-testid": "test-handle-id",
20
+ ref,
21
+ }}/>
22
+ </View>);
23
+ };
24
+ export const mouseEvents = {
25
+ name: "onDrag, mouse events",
26
+ args: {
27
+ handleDrag: fn(),
28
+ },
29
+ render: (args) => {
30
+ return <Demo onDrag={args.handleDrag}/>;
31
+ },
32
+ play: ({ canvas, args }) => {
33
+ const trigger = canvas.getByTestId("test-handle-id");
34
+ fireEvent.mouseDown(trigger);
35
+ fireEvent.mouseMove(document.body, { clientX: 100, clientY: 50 });
36
+ expect(args.handleDrag).toHaveBeenCalledTimes(1);
37
+ expect(args.handleDrag).toHaveBeenCalledWith(expect.objectContaining({ x: 100, y: 50 }));
38
+ fireEvent.mouseUp(trigger);
39
+ fireEvent.mouseUp(document.body, { clientX: 50, clientY: 100 });
40
+ expect(args.handleDrag).toHaveBeenCalledTimes(1);
41
+ },
42
+ };
43
+ export const touchEvents = {
44
+ name: "onDrag, touch events",
45
+ args: {
46
+ handleDrag: fn(),
47
+ },
48
+ render: (args) => {
49
+ return <Demo onDrag={args.handleDrag}/>;
50
+ },
51
+ play: ({ canvas, args }) => {
52
+ const createTouch = (target, x, y) => {
53
+ return new Touch({
54
+ identifier: Date.now(),
55
+ target,
56
+ clientX: x,
57
+ clientY: y,
58
+ screenX: x,
59
+ screenY: y,
60
+ pageX: x,
61
+ pageY: y,
62
+ });
63
+ };
64
+ const trigger = canvas.getByTestId("test-handle-id");
65
+ fireEvent.touchStart(trigger, { changedTouches: [createTouch(trigger, 0, 0)] });
66
+ fireEvent.touchMove(document.body, { changedTouches: [createTouch(trigger, 100, 50)] });
67
+ expect(args.handleDrag).toHaveBeenCalledTimes(1);
68
+ expect(args.handleDrag).toHaveBeenCalledWith(expect.objectContaining({ x: 100, y: 50 }));
69
+ fireEvent.touchEnd(trigger);
70
+ fireEvent.touchEnd(document.body, { changedTouches: [createTouch(trigger, 100, 50)] });
71
+ expect(args.handleDrag).toHaveBeenCalledTimes(1);
72
+ },
73
+ };
74
+ export const orientationHorizontal = {
75
+ name: "orientation horizontal",
76
+ args: {
77
+ handleDrag: fn(),
78
+ },
79
+ render: (args) => {
80
+ return <Demo onDrag={args.handleDrag} orientation="horizontal"/>;
81
+ },
82
+ play: ({ canvas, args }) => {
83
+ const trigger = canvas.getByTestId("test-handle-id");
84
+ fireEvent.mouseDown(trigger);
85
+ fireEvent.mouseMove(document.body, { clientX: 100, clientY: 50 });
86
+ expect(args.handleDrag).toHaveBeenCalledTimes(1);
87
+ expect(args.handleDrag).toHaveBeenCalledWith(expect.objectContaining({ x: 100, y: 0 }));
88
+ },
89
+ };
90
+ export const orientationVertical = {
91
+ name: "orientation vertical",
92
+ args: {
93
+ handleDrag: fn(),
94
+ },
95
+ render: (args) => {
96
+ return <Demo onDrag={args.handleDrag} orientation="vertical"/>;
97
+ },
98
+ play: ({ canvas, args }) => {
99
+ const trigger = canvas.getByTestId("test-handle-id");
100
+ fireEvent.mouseDown(trigger);
101
+ fireEvent.mouseMove(document.body, { clientX: 100, clientY: 50 });
102
+ expect(args.handleDrag).toHaveBeenCalledTimes(1);
103
+ expect(args.handleDrag).toHaveBeenCalledWith(expect.objectContaining({ x: 0, y: 50 }));
104
+ },
105
+ };
106
+ export const disabled = {
107
+ name: "disabled",
108
+ args: {
109
+ handleDrag: fn(),
110
+ },
111
+ render: (args) => {
112
+ return <Demo onDrag={args.handleDrag} disabled/>;
113
+ },
114
+ play: ({ canvas, args }) => {
115
+ const trigger = canvas.getByTestId("test-handle-id");
116
+ fireEvent.mouseDown(trigger);
117
+ fireEvent.mouseMove(document.body, { clientX: 100, clientY: 50 });
118
+ expect(args.handleDrag).toHaveBeenCalledTimes(0);
119
+ },
120
+ };