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,6 +0,0 @@
1
- import React from "react";
2
- declare const _default: {
3
- title: string;
4
- };
5
- export default _default;
6
- export declare const base: () => React.JSX.Element;
@@ -1,17 +0,0 @@
1
- import React from "react";
2
- import Portal from "../index.js";
3
- export default { title: "Internal/Portal" };
4
- export const base = () => {
5
- const ref = React.useRef(null);
6
- const [mounted, setMounted] = React.useState(false);
7
- React.useEffect(() => {
8
- setMounted(true);
9
- }, []);
10
- return (<>
11
- <div style={{ border: "2px solid #333", padding: 16 }}>
12
- App
13
- {mounted && <Portal targetRef={ref}>Ported to green</Portal>}
14
- </div>
15
- <div ref={ref} style={{ border: "2px solid green", padding: 16 }}/>
16
- </>);
17
- };
@@ -1,31 +0,0 @@
1
- import React from "react";
2
- import { StoryObj } from "@storybook/react-vite";
3
- import { fn } from "storybook/test";
4
- declare const _default: {
5
- title: string;
6
- parameters: {
7
- chromatic: {
8
- disableSnapshot: boolean;
9
- };
10
- };
11
- };
12
- export default _default;
13
- export declare const base: {
14
- name: string;
15
- render: () => React.JSX.Element;
16
- };
17
- export declare const mouseEvents: StoryObj<{
18
- handleDrag: ReturnType<typeof fn>;
19
- }>;
20
- export declare const touchEvents: StoryObj<{
21
- handleDrag: ReturnType<typeof fn>;
22
- }>;
23
- export declare const orientationHorizontal: StoryObj<{
24
- handleDrag: ReturnType<typeof fn>;
25
- }>;
26
- export declare const orientationVertical: StoryObj<{
27
- handleDrag: ReturnType<typeof fn>;
28
- }>;
29
- export declare const disabled: StoryObj<{
30
- handleDrag: ReturnType<typeof fn>;
31
- }>;
@@ -1,147 +0,0 @@
1
- import React from "react";
2
- import { fireEvent, fn, expect } from "storybook/test";
3
- import View from "../../components/View/index.js";
4
- import useDrag from "../_private/useDrag.js";
5
- import useToggle from "../useToggle.js";
6
- import Button from "../../components/Button/index.js";
7
- export default {
8
- title: "Internal/useDrag",
9
- parameters: {
10
- chromatic: { disableSnapshot: true },
11
- },
12
- };
13
- function Example() {
14
- const [state, setState] = React.useState({ x: 0, y: 0 });
15
- const disabledToggle = useToggle();
16
- const { ref, containerRef, active } = useDrag((args) => {
17
- setState(args);
18
- }, {
19
- disabled: disabledToggle.active,
20
- });
21
- return (<View direction="row" gap={4}>
22
- <View backgroundColor="neutral-faded" borderRadius="medium" width="200px" height="200px" attributes={{ ref: containerRef }}>
23
- <View height={8} width={8} borderRadius="small" animated backgroundColor={active ? "primary" : "neutral"} attributes={{
24
- role: "button",
25
- tabIndex: 0,
26
- "aria-label": "Drag",
27
- ref,
28
- style: { translate: `${state.x}px ${state.y}px`, cursor: active ? "grabbing" : "grab" },
29
- }}/>
30
- </View>
31
- <Button onClick={() => disabledToggle.toggle()}>
32
- {disabledToggle.active ? "Enable" : "Disable"}
33
- </Button>
34
- </View>);
35
- }
36
- export const base = { name: "base", render: () => <Example /> };
37
- const Demo = (props) => {
38
- const { ref, containerRef } = useDrag((options) => {
39
- props.onDrag(options);
40
- }, {
41
- orientation: props.orientation,
42
- disabled: props.disabled,
43
- });
44
- return (<View backgroundColor="neutral-faded" width="200px" height="200px" attributes={{ ref: containerRef, "data-testid": "test-id" }}>
45
- <View height={8} width={8} backgroundColor="primary" attributes={{
46
- "data-testid": "test-handle-id",
47
- ref,
48
- }}/>
49
- </View>);
50
- };
51
- export const mouseEvents = {
52
- name: "onDrag, mouse events",
53
- args: {
54
- handleDrag: fn(),
55
- },
56
- render: (args) => {
57
- return <Demo onDrag={args.handleDrag}/>;
58
- },
59
- play: ({ canvas, args }) => {
60
- const trigger = canvas.getByTestId("test-handle-id");
61
- fireEvent.mouseDown(trigger);
62
- fireEvent.mouseMove(document.body, { clientX: 100, clientY: 50 });
63
- expect(args.handleDrag).toHaveBeenCalledTimes(1);
64
- expect(args.handleDrag).toHaveBeenCalledWith(expect.objectContaining({ x: 100, y: 50 }));
65
- fireEvent.mouseUp(trigger);
66
- fireEvent.mouseUp(document.body, { clientX: 50, clientY: 100 });
67
- expect(args.handleDrag).toHaveBeenCalledTimes(1);
68
- },
69
- };
70
- export const touchEvents = {
71
- name: "onDrag, touch events",
72
- args: {
73
- handleDrag: fn(),
74
- },
75
- render: (args) => {
76
- return <Demo onDrag={args.handleDrag}/>;
77
- },
78
- play: ({ canvas, args }) => {
79
- const createTouch = (target, x, y) => {
80
- return new Touch({
81
- identifier: Date.now(),
82
- target,
83
- clientX: x,
84
- clientY: y,
85
- screenX: x,
86
- screenY: y,
87
- pageX: x,
88
- pageY: y,
89
- });
90
- };
91
- const trigger = canvas.getByTestId("test-handle-id");
92
- fireEvent.touchStart(trigger, { changedTouches: [createTouch(trigger, 0, 0)] });
93
- fireEvent.touchMove(document.body, { changedTouches: [createTouch(trigger, 100, 50)] });
94
- expect(args.handleDrag).toHaveBeenCalledTimes(1);
95
- expect(args.handleDrag).toHaveBeenCalledWith(expect.objectContaining({ x: 100, y: 50 }));
96
- fireEvent.touchEnd(trigger);
97
- fireEvent.touchEnd(document.body, { changedTouches: [createTouch(trigger, 100, 50)] });
98
- expect(args.handleDrag).toHaveBeenCalledTimes(1);
99
- },
100
- };
101
- export const orientationHorizontal = {
102
- name: "orientation horizontal",
103
- args: {
104
- handleDrag: fn(),
105
- },
106
- render: (args) => {
107
- return <Demo onDrag={args.handleDrag} orientation="horizontal"/>;
108
- },
109
- play: ({ canvas, args }) => {
110
- const trigger = canvas.getByTestId("test-handle-id");
111
- fireEvent.mouseDown(trigger);
112
- fireEvent.mouseMove(document.body, { clientX: 100, clientY: 50 });
113
- expect(args.handleDrag).toHaveBeenCalledTimes(1);
114
- expect(args.handleDrag).toHaveBeenCalledWith(expect.objectContaining({ x: 100, y: 0 }));
115
- },
116
- };
117
- export const orientationVertical = {
118
- name: "orientation vertical",
119
- args: {
120
- handleDrag: fn(),
121
- },
122
- render: (args) => {
123
- return <Demo onDrag={args.handleDrag} orientation="vertical"/>;
124
- },
125
- play: ({ canvas, args }) => {
126
- const trigger = canvas.getByTestId("test-handle-id");
127
- fireEvent.mouseDown(trigger);
128
- fireEvent.mouseMove(document.body, { clientX: 100, clientY: 50 });
129
- expect(args.handleDrag).toHaveBeenCalledTimes(1);
130
- expect(args.handleDrag).toHaveBeenCalledWith(expect.objectContaining({ x: 0, y: 50 }));
131
- },
132
- };
133
- export const disabled = {
134
- name: "disabled",
135
- args: {
136
- handleDrag: fn(),
137
- },
138
- render: (args) => {
139
- return <Demo onDrag={args.handleDrag} disabled/>;
140
- },
141
- play: ({ canvas, args }) => {
142
- const trigger = canvas.getByTestId("test-handle-id");
143
- fireEvent.mouseDown(trigger);
144
- fireEvent.mouseMove(document.body, { clientX: 100, clientY: 50 });
145
- expect(args.handleDrag).toHaveBeenCalledTimes(0);
146
- },
147
- };
@@ -1,11 +0,0 @@
1
- import { StoryObj } from "@storybook/react-vite";
2
- declare const _default: {
3
- title: string;
4
- parameters: {
5
- chromatic: {
6
- disableSnapshot: boolean;
7
- };
8
- };
9
- };
10
- export default _default;
11
- export declare const id: StoryObj;
@@ -1,23 +0,0 @@
1
- import { expect, waitFor } from "storybook/test";
2
- import useElementId from "../useElementId.js";
3
- export default {
4
- title: "Hooks/useElementId",
5
- parameters: {
6
- chromatic: { disableSnapshot: true },
7
- },
8
- };
9
- const Component = (props) => {
10
- const id = useElementId(props.id);
11
- return <div id={id}>{id}</div>;
12
- };
13
- export const id = {
14
- name: "passed id",
15
- render: () => {
16
- return <Component id="hey"/>;
17
- },
18
- play: async () => {
19
- waitFor(() => {
20
- expect(document.querySelector("#hey")).toBeTruthy();
21
- });
22
- },
23
- };
@@ -1,14 +0,0 @@
1
- import { StoryObj } from "@storybook/react-vite";
2
- import { Mock } 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 base: StoryObj<{
13
- handleEffect: Mock;
14
- }>;
@@ -1,44 +0,0 @@
1
- import React from "react";
2
- import { expect, fn, userEvent } from "storybook/test";
3
- import Button from "../../components/Button/index.js";
4
- import View from "../../components/View/index.js";
5
- import useHandlerRef from "../useHandlerRef.js";
6
- export default {
7
- title: "Hooks/useHandlerRef",
8
- parameters: {
9
- chromatic: { disableSnapshot: true },
10
- },
11
- };
12
- const Component = (props) => {
13
- const { onEffect, count } = props;
14
- const onEffectRef = useHandlerRef(onEffect);
15
- React.useEffect(() => {
16
- onEffectRef.current();
17
- }, [onEffectRef]);
18
- return <>Counter: {count}</>;
19
- };
20
- export const base = {
21
- name: "base",
22
- args: {
23
- handleEffect: fn(),
24
- },
25
- render: (args) => {
26
- const [count, setCount] = React.useState(0);
27
- // Creating a new handler on each render
28
- const handleEffect = () => {
29
- args.handleEffect(0);
30
- };
31
- return (<View gap={4}>
32
- <Button onClick={() => setCount((prev) => prev + 1)}>Increase count</Button>
33
- <Component onEffect={handleEffect} count={count}/>
34
- </View>);
35
- },
36
- play: async ({ canvas, args }) => {
37
- const button = canvas.getAllByRole("button")[0];
38
- // mount, triggerred twice in dev mode
39
- expect(args.handleEffect).toHaveBeenCalledTimes(2);
40
- await userEvent.click(button);
41
- // Rerendering the component doesn't re-trigger the effect
42
- expect(args.handleEffect).toHaveBeenCalledTimes(2);
43
- },
44
- };
@@ -1,43 +0,0 @@
1
- import { StoryObj } from "@storybook/react-vite";
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 base: {
13
- name: string;
14
- render: () => import("react").JSX.Element;
15
- };
16
- export declare const singleKey: StoryObj<{
17
- handleHotkey: ReturnType<typeof fn>;
18
- }>;
19
- export declare const modKey: StoryObj<{
20
- handleHotkey: ReturnType<typeof fn>;
21
- }>;
22
- export declare const modKeyHold: StoryObj<{
23
- handleHotkey: ReturnType<typeof fn>;
24
- }>;
25
- export declare const keyList: StoryObj<{
26
- handleHotkey: ReturnType<typeof fn>;
27
- }>;
28
- export declare const keyCombination: StoryObj<{
29
- handleHotkey: ReturnType<typeof fn>;
30
- }>;
31
- export declare const keyCombinationFormat: StoryObj<{
32
- handleHotkey: ReturnType<typeof fn>;
33
- }>;
34
- export declare const keyCombinationOrder: StoryObj<{
35
- handleHotkey: ReturnType<typeof fn>;
36
- }>;
37
- export declare const keyCombinationMoreThanRequired: StoryObj<{
38
- handleHotkey: ReturnType<typeof fn>;
39
- }>;
40
- export declare const optionModified: StoryObj<{
41
- handleHotkey: ReturnType<typeof fn>;
42
- handleHotkeyModified: ReturnType<typeof fn>;
43
- }>;
@@ -1,158 +0,0 @@
1
- import { expect, fn, userEvent } from "storybook/test";
2
- import View from "../../components/View/index.js";
3
- import useHotkeys from "../useHotkeys.js";
4
- export default {
5
- title: "Hooks/useHotkeys",
6
- parameters: {
7
- chromatic: { disableSnapshot: true },
8
- },
9
- };
10
- export const base = {
11
- name: "base",
12
- render: () => {
13
- const { checkHotkeyState } = useHotkeys({
14
- "shift + b + n": () => console.log("pressed"),
15
- "c + v": () => console.log("c + v"),
16
- "Meta + k": () => console.log("meta + k"),
17
- "Meta + f": () => console.log("meta + f"),
18
- "Meta + v": () => console.log("meta + v"),
19
- "Meta + b": () => console.log("meta + b"),
20
- "control + enter": () => console.log("control + enter"),
21
- "meta + enter": () => console.log("meta + enter"),
22
- "mod + enter": () => console.log("mod + enter"),
23
- "mod + ArrowRight": () => console.log("right"),
24
- "mod + ArrowUp": () => console.log("top"),
25
- "shift + ArrowRight": () => console.log("right"),
26
- "shift + ArrowUp": () => console.log("top"),
27
- "alt+shift+n": () => console.log("alt+shift+n"),
28
- "shift+alt+n": () => console.log("shift+alt+n"),
29
- "alt+shiftLeft+n": () => console.log("alt+shiftLeft+n"),
30
- });
31
- const active = checkHotkeyState("shift + b + n");
32
- const shiftActive = checkHotkeyState("shift");
33
- const bActive = checkHotkeyState("b");
34
- const nActive = checkHotkeyState("n");
35
- return (<View animated gap={2} direction="row" backgroundColor={active ? "positive-faded" : undefined} padding={2} borderRadius="small">
36
- <View paddingInline={4} paddingBlock={2} borderRadius="small" borderColor="neutral-faded" animated backgroundColor={shiftActive ? "neutral-faded" : "elevation-raised"} shadow={shiftActive ? undefined : "raised"}>
37
- Shift
38
- </View>
39
- <View paddingInline={4} paddingBlock={2} borderRadius="small" borderColor="neutral-faded" animated backgroundColor={bActive ? "neutral-faded" : "elevation-raised"} shadow={bActive ? undefined : "raised"}>
40
- b
41
- </View>
42
- <View paddingInline={4} paddingBlock={2} borderRadius="small" borderColor="neutral-faded" animated backgroundColor={nActive ? "neutral-faded" : "elevation-raised"} shadow={nActive ? undefined : "raised"}>
43
- n
44
- </View>
45
- </View>);
46
- },
47
- };
48
- const Component = (props) => {
49
- const { hotkeys } = props;
50
- useHotkeys(hotkeys);
51
- return <div />;
52
- };
53
- export const singleKey = {
54
- name: "single key",
55
- args: {
56
- handleHotkey: fn(),
57
- },
58
- render: (args) => <Component hotkeys={{ a: args.handleHotkey }}/>,
59
- play: async ({ args }) => {
60
- await userEvent.keyboard("a");
61
- await userEvent.keyboard("b");
62
- expect(args.handleHotkey).toHaveBeenCalledTimes(1);
63
- },
64
- };
65
- export const modKey = {
66
- name: "mod key",
67
- args: {
68
- handleHotkey: fn(),
69
- },
70
- render: (args) => <Component hotkeys={{ mod: args.handleHotkey }}/>,
71
- play: async ({ args }) => {
72
- await userEvent.keyboard("{Meta/}");
73
- expect(args.handleHotkey).toHaveBeenCalledTimes(1);
74
- },
75
- };
76
- export const modKeyHold = {
77
- name: "mod key on hold",
78
- args: {
79
- handleHotkey: fn(),
80
- },
81
- render: (args) => <Component hotkeys={{ "Meta + b": args.handleHotkey }}/>,
82
- play: async ({ args }) => {
83
- await userEvent.keyboard("{Meta>}bb{/Meta}");
84
- expect(args.handleHotkey).toHaveBeenCalledTimes(2);
85
- },
86
- };
87
- export const keyList = {
88
- name: "key list",
89
- args: {
90
- handleHotkey: fn(),
91
- },
92
- render: (args) => <Component hotkeys={{ "a,b": args.handleHotkey }}/>,
93
- play: async ({ args }) => {
94
- await userEvent.keyboard("a");
95
- expect(args.handleHotkey).toHaveBeenCalledTimes(1);
96
- await userEvent.keyboard("b");
97
- expect(args.handleHotkey).toHaveBeenCalledTimes(2);
98
- },
99
- };
100
- export const keyCombination = {
101
- name: "key combination",
102
- args: {
103
- handleHotkey: fn(),
104
- },
105
- render: (args) => <Component hotkeys={{ "a+b": args.handleHotkey }}/>,
106
- play: async ({ args }) => {
107
- await userEvent.keyboard("{a>}b{/a}");
108
- expect(args.handleHotkey).toHaveBeenCalledTimes(1);
109
- },
110
- };
111
- export const keyCombinationFormat = {
112
- name: "key combination without formatting",
113
- args: {
114
- handleHotkey: fn(),
115
- },
116
- render: (args) => <Component hotkeys={{ "A + b": args.handleHotkey }}/>,
117
- play: async ({ args }) => {
118
- await userEvent.keyboard("{a>}b{/a}");
119
- expect(args.handleHotkey).toHaveBeenCalledTimes(1);
120
- },
121
- };
122
- export const keyCombinationOrder = {
123
- name: "key combination without order",
124
- args: {
125
- handleHotkey: fn(),
126
- },
127
- render: (args) => <Component hotkeys={{ "b+a": args.handleHotkey }}/>,
128
- play: async ({ args }) => {
129
- await userEvent.keyboard("{a>}b{/a}");
130
- expect(args.handleHotkey).toHaveBeenCalledTimes(1);
131
- },
132
- };
133
- export const keyCombinationMoreThanRequired = {
134
- name: "key combination, more keys pressed",
135
- args: {
136
- handleHotkey: fn(),
137
- },
138
- render: (args) => <Component hotkeys={{ "z + x": args.handleHotkey }}/>,
139
- play: async ({ args }) => {
140
- await userEvent.keyboard("{z>}{x>}c{/x}{/z}");
141
- // When c is pressed, it doesn't trigger a+b for the second time
142
- expect(args.handleHotkey).toHaveBeenCalledTimes(1);
143
- },
144
- };
145
- export const optionModified = {
146
- name: "modified with alt/option",
147
- args: {
148
- handleHotkey: fn(),
149
- handleHotkeyModified: fn(),
150
- },
151
- render: (args) => (<Component hotkeys={{ "alt+n": args.handleHotkeyModified, "alt+shift": args.handleHotkey }}/>),
152
- play: async ({ args }) => {
153
- await userEvent.keyboard("{Alt>}n{/Alt}");
154
- expect(args.handleHotkeyModified).toHaveBeenCalledTimes(1);
155
- await userEvent.keyboard("{Alt>}{Shift}{/Alt}");
156
- expect(args.handleHotkey).toHaveBeenCalledTimes(1);
157
- },
158
- };
@@ -1,15 +0,0 @@
1
- import { StoryObj } from "@storybook/react-vite";
2
- declare const _default: {
3
- title: string;
4
- parameters: {
5
- chromatic: {
6
- disableSnapshot: boolean;
7
- };
8
- };
9
- };
10
- export default _default;
11
- export declare const base: StoryObj;
12
- export declare const horizontal: StoryObj;
13
- export declare const vertical: StoryObj;
14
- export declare const circular: StoryObj;
15
- export declare const disabled: StoryObj;
@@ -1,128 +0,0 @@
1
- import React, { useRef } from "react";
2
- import { expect, userEvent } from "storybook/test";
3
- import View from "../../components/View/index.js";
4
- import Button from "../../components/Button/index.js";
5
- import useKeyboardArrowNavigation from "../useKeyboardArrowNavigation.js";
6
- export default {
7
- title: "Hooks/useKeyboardArrowNavigation",
8
- parameters: {
9
- chromatic: { disableSnapshot: true },
10
- },
11
- };
12
- export const base = {
13
- name: "base",
14
- render: () => {
15
- const ref = useRef(null);
16
- useKeyboardArrowNavigation({ ref });
17
- return (<View gap={2} direction="row" attributes={{ ref }}>
18
- <Button onClick={() => { }}>Action 1</Button>
19
- <Button onClick={() => { }}>Action 2</Button>
20
- <Button onClick={() => { }}>Action 3</Button>
21
- </View>);
22
- },
23
- play: async ({ canvas }) => {
24
- const buttons = canvas.getAllByRole("button");
25
- buttons[0].focus();
26
- await userEvent.keyboard("{ArrowRight/}");
27
- expect(document.activeElement).toBe(buttons[1]);
28
- await userEvent.keyboard("{ArrowDown/}");
29
- expect(document.activeElement).toBe(buttons[2]);
30
- await userEvent.keyboard("{ArrowUp/}");
31
- expect(document.activeElement).toBe(buttons[1]);
32
- await userEvent.keyboard("{ArrowLeft/}");
33
- expect(document.activeElement).toBe(buttons[0]);
34
- },
35
- };
36
- export const horizontal = {
37
- name: "orientation: horizontal",
38
- render: () => {
39
- const ref = useRef(null);
40
- useKeyboardArrowNavigation({ ref, orientation: "horizontal" });
41
- return (<View gap={2} direction="row" attributes={{ ref }}>
42
- <Button onClick={() => { }}>Action 1</Button>
43
- <Button onClick={() => { }}>Action 2</Button>
44
- <Button onClick={() => { }}>Action 3</Button>
45
- </View>);
46
- },
47
- play: async ({ canvas }) => {
48
- const buttons = canvas.getAllByRole("button");
49
- expect(buttons[0]).toHaveAttribute("tabindex", "0");
50
- expect(buttons[1]).toHaveAttribute("tabindex", "-1");
51
- expect(buttons[2]).toHaveAttribute("tabindex", "-1");
52
- buttons[0].focus();
53
- await userEvent.keyboard("{ArrowRight/}");
54
- expect(document.activeElement).toBe(buttons[1]);
55
- await userEvent.keyboard("{ArrowLeft/}");
56
- expect(document.activeElement).toBe(buttons[0]);
57
- await userEvent.keyboard("{ArrowDown/}");
58
- expect(document.activeElement).toBe(buttons[0]);
59
- await userEvent.keyboard("{ArrowUp/}");
60
- expect(document.activeElement).toBe(buttons[0]);
61
- },
62
- };
63
- export const vertical = {
64
- name: "orientation: vertical",
65
- render: () => {
66
- const ref = useRef(null);
67
- useKeyboardArrowNavigation({ ref, orientation: "vertical" });
68
- return (<View gap={2} direction="column" attributes={{ ref }}>
69
- <Button onClick={() => { }}>Action 1</Button>
70
- <Button onClick={() => { }}>Action 2</Button>
71
- <Button onClick={() => { }}>Action 3</Button>
72
- </View>);
73
- },
74
- play: async ({ canvas }) => {
75
- const buttons = canvas.getAllByRole("button");
76
- buttons[0].focus();
77
- await userEvent.keyboard("{ArrowDown/}");
78
- expect(document.activeElement).toBe(buttons[1]);
79
- await userEvent.keyboard("{ArrowUp/}");
80
- expect(document.activeElement).toBe(buttons[0]);
81
- await userEvent.keyboard("{ArrowRight/}");
82
- expect(document.activeElement).toBe(buttons[0]);
83
- await userEvent.keyboard("{ArrowLeft/}");
84
- expect(document.activeElement).toBe(buttons[0]);
85
- },
86
- };
87
- export const circular = {
88
- name: "circular",
89
- render: () => {
90
- const ref = useRef(null);
91
- useKeyboardArrowNavigation({ ref, circular: true });
92
- return (<View gap={2} direction="row" attributes={{ ref }}>
93
- <Button onClick={() => { }}>Action 1</Button>
94
- <Button onClick={() => { }}>Action 2</Button>
95
- <Button onClick={() => { }}>Action 3</Button>
96
- </View>);
97
- },
98
- play: async ({ canvas }) => {
99
- const buttons = canvas.getAllByRole("button");
100
- buttons[0].focus();
101
- await userEvent.keyboard("{ArrowRight/}");
102
- await userEvent.keyboard("{ArrowRight/}");
103
- expect(document.activeElement).toBe(buttons[2]);
104
- await userEvent.keyboard("{ArrowRight/}");
105
- expect(document.activeElement).toBe(buttons[0]);
106
- await userEvent.keyboard("{ArrowLeft/}");
107
- expect(document.activeElement).toBe(buttons[2]);
108
- },
109
- };
110
- export const disabled = {
111
- name: "disabled",
112
- render: () => {
113
- const ref = useRef(null);
114
- useKeyboardArrowNavigation({ ref, disabled: true });
115
- return (<View gap={2} direction="row" attributes={{ ref }}>
116
- <Button onClick={() => { }}>Action 1</Button>
117
- <Button onClick={() => { }}>Action 2</Button>
118
- <Button onClick={() => { }}>Action 3</Button>
119
- </View>);
120
- },
121
- play: async ({ canvas }) => {
122
- const buttons = canvas.getAllByRole("button");
123
- buttons[0].focus();
124
- await userEvent.keyboard("{ArrowRight/}");
125
- expect(document.activeElement).toBe(buttons[0]);
126
- expect(buttons[0]).not.toHaveAttribute("tabindex");
127
- },
128
- };
@@ -1,11 +0,0 @@
1
- import { StoryObj } from "@storybook/react-vite";
2
- declare const _default: {
3
- title: string;
4
- parameters: {
5
- chromatic: {
6
- disableSnapshot: boolean;
7
- };
8
- };
9
- };
10
- export default _default;
11
- export declare const base: StoryObj;