reshaped 3.8.0-canary.11 → 3.8.0-canary.13

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 (43) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/bundle.css +1 -1
  3. package/dist/bundle.d.ts +1 -0
  4. package/dist/bundle.js +9 -9
  5. package/dist/components/Button/Button.module.css +1 -1
  6. package/dist/components/Button/tests/Button.stories.js +1 -1
  7. package/dist/components/Tabs/TabsList.js +3 -20
  8. package/dist/components/Text/Text.module.css +1 -1
  9. package/dist/components/TextField/TextField.js +10 -2
  10. package/dist/components/TextField/TextField.module.css +1 -1
  11. package/dist/components/TextField/TextField.types.d.ts +5 -1
  12. package/dist/components/TextField/tests/TextField.stories.js +11 -5
  13. package/dist/components/ToggleButton/ToggleButton.types.d.ts +5 -1
  14. package/dist/components/ToggleButton/ToggleButtonControlled.js +9 -2
  15. package/dist/components/ToggleButton/tests/ToggleButton.stories.d.ts +4 -0
  16. package/dist/components/ToggleButton/tests/ToggleButton.stories.js +10 -0
  17. package/dist/components/ToggleButtonGroup/ToggleButtonGroup.types.d.ts +10 -0
  18. package/dist/components/ToggleButtonGroup/ToggleButtonGroupControlled.js +6 -42
  19. package/dist/components/ToggleButtonGroup/tests/ToggleButtonGroup.stories.d.ts +1 -0
  20. package/dist/components/ToggleButtonGroup/tests/ToggleButtonGroup.stories.js +17 -0
  21. package/dist/hooks/tests/useKeyboardArrowNavigation.stories.d.ts +15 -0
  22. package/dist/hooks/tests/useKeyboardArrowNavigation.stories.js +128 -0
  23. package/dist/hooks/useKeyboardArrowNavigation.d.ts +9 -0
  24. package/dist/hooks/useKeyboardArrowNavigation.js +62 -0
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +1 -0
  27. package/dist/utilities/a11y/focus.d.ts +21 -4
  28. package/dist/utilities/a11y/focus.js +4 -3
  29. package/package.json +1 -1
  30. package/dist/components/DropdownMenu/tests/DropdownMenu.test.stories.d.ts +0 -21
  31. package/dist/components/DropdownMenu/tests/DropdownMenu.test.stories.js +0 -11
  32. package/dist/components/Link/tests/Link.test.stories.d.ts +0 -17
  33. package/dist/components/Link/tests/Link.test.stories.js +0 -11
  34. package/dist/components/Loader/tests/Loader.test.stories.d.ts +0 -13
  35. package/dist/components/Loader/tests/Loader.test.stories.js +0 -11
  36. package/dist/components/Table/tests/Table.test.stories.d.ts +0 -19
  37. package/dist/components/Table/tests/Table.test.stories.js +0 -11
  38. package/dist/components/TextField/tests/TextField.test.stories.d.ts +0 -15
  39. package/dist/components/TextField/tests/TextField.test.stories.js +0 -11
  40. package/dist/components/Timeline/tests/Timeline.test.stories.d.ts +0 -15
  41. package/dist/components/Timeline/tests/Timeline.test.stories.js +0 -11
  42. package/dist/components/Tooltip/tests/Tooltip.test.stories.d.ts +0 -13
  43. package/dist/components/Tooltip/tests/Tooltip.test.stories.js +0 -11
@@ -0,0 +1,128 @@
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
+ };
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ type Props = {
3
+ ref: React.RefObject<HTMLElement | null>;
4
+ disabled?: boolean;
5
+ orientation?: "vertical" | "horizontal";
6
+ circular?: boolean;
7
+ };
8
+ declare const useKeyboardArrowNavigation: (props: Props) => void;
9
+ export default useKeyboardArrowNavigation;
@@ -0,0 +1,62 @@
1
+ import React, { useEffect } from "react";
2
+ import { focusFirstElement, focusLastElement, focusNextElement, focusPreviousElement, getFocusableElements, } from "../utilities/a11y/index.js";
3
+ import useHotkeys from "./useHotkeys.js";
4
+ const useKeyboardArrowNavigation = (props) => {
5
+ const { ref, disabled, orientation, circular } = props;
6
+ const backHotkeys = [];
7
+ const forwardHotkeys = [];
8
+ if (!orientation || orientation === "vertical") {
9
+ backHotkeys.push("ArrowUp");
10
+ forwardHotkeys.push("ArrowDown");
11
+ }
12
+ if (!orientation || orientation === "horizontal") {
13
+ backHotkeys.push("ArrowLeft");
14
+ forwardHotkeys.push("ArrowRight");
15
+ }
16
+ const updateTabIndex = React.useCallback((options) => {
17
+ const { el, focusableElements } = options;
18
+ const initialEl = focusableElements.find((el) => el.getAttribute("tabindex") !== "-1");
19
+ const activeEl = el ?? initialEl ?? focusableElements[0];
20
+ focusableElements.forEach((el) => el.setAttribute("tabindex", "-1"));
21
+ activeEl?.setAttribute("tabindex", "0");
22
+ }, []);
23
+ useEffect(() => {
24
+ if (!ref.current)
25
+ return;
26
+ if (disabled)
27
+ return;
28
+ const focusableElements = getFocusableElements(ref.current);
29
+ updateTabIndex({ focusableElements });
30
+ }, [ref, updateTabIndex, disabled]);
31
+ useHotkeys({
32
+ [backHotkeys.join(", ")]: () => {
33
+ if (!ref.current)
34
+ return;
35
+ const data = focusPreviousElement(ref.current, { circular });
36
+ updateTabIndex(data);
37
+ },
38
+ [forwardHotkeys.join(", ")]: () => {
39
+ if (!ref.current)
40
+ return;
41
+ const data = focusNextElement(ref.current, { circular });
42
+ updateTabIndex(data);
43
+ },
44
+ Home: () => {
45
+ if (!ref.current)
46
+ return;
47
+ const data = focusFirstElement(ref.current);
48
+ updateTabIndex(data);
49
+ },
50
+ End: () => {
51
+ if (!ref.current)
52
+ return;
53
+ const data = focusLastElement(ref.current);
54
+ updateTabIndex(data);
55
+ },
56
+ }, [updateTabIndex, circular], {
57
+ ref,
58
+ preventDefault: true,
59
+ disabled,
60
+ });
61
+ };
62
+ export default useKeyboardArrowNavigation;
package/dist/index.d.ts CHANGED
@@ -135,6 +135,7 @@ export { default as useHandlerRef } from "./hooks/useHandlerRef";
135
135
  export { default as useHotkeys } from "./hooks/useHotkeys";
136
136
  export { default as useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect";
137
137
  export { default as useKeyboardMode } from "./hooks/useKeyboardMode";
138
+ export { default as useKeyboardArrowNavigation } from "./hooks/useKeyboardArrowNavigation";
138
139
  export { default as useOnClickOutside } from "./hooks/useOnClickOutside";
139
140
  export { default as useResponsiveClientValue } from "./hooks/useResponsiveClientValue";
140
141
  export { default as useRTL } from "./hooks/useRTL";
package/dist/index.js CHANGED
@@ -74,6 +74,7 @@ export { default as useHandlerRef } from "./hooks/useHandlerRef.js";
74
74
  export { default as useHotkeys } from "./hooks/useHotkeys.js";
75
75
  export { default as useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect.js";
76
76
  export { default as useKeyboardMode } from "./hooks/useKeyboardMode.js";
77
+ export { default as useKeyboardArrowNavigation } from "./hooks/useKeyboardArrowNavigation.js";
77
78
  export { default as useOnClickOutside } from "./hooks/useOnClickOutside.js";
78
79
  export { default as useResponsiveClientValue } from "./hooks/useResponsiveClientValue.js";
79
80
  export { default as useRTL } from "./hooks/useRTL.js";
@@ -14,8 +14,25 @@ export declare const getFocusData: (args: {
14
14
  }) => {
15
15
  overflow: boolean;
16
16
  el: FocusableElement;
17
+ focusableElements: FocusableElement[];
18
+ };
19
+ export declare const focusNextElement: (root: HTMLElement, options?: {
20
+ circular?: boolean;
21
+ }) => {
22
+ el: FocusableElement;
23
+ focusableElements: FocusableElement[];
24
+ };
25
+ export declare const focusPreviousElement: (root: HTMLElement, options?: {
26
+ circular?: boolean;
27
+ }) => {
28
+ el: FocusableElement;
29
+ focusableElements: FocusableElement[];
30
+ };
31
+ export declare const focusFirstElement: (root: HTMLElement) => {
32
+ el: FocusableElement;
33
+ focusableElements: FocusableElement[];
34
+ };
35
+ export declare const focusLastElement: (root: HTMLElement) => {
36
+ el: FocusableElement;
37
+ focusableElements: FocusableElement[];
17
38
  };
18
- export declare const focusNextElement: (root: HTMLElement) => void;
19
- export declare const focusPreviousElement: (root: HTMLElement) => void;
20
- export declare const focusFirstElement: (root: HTMLElement) => void;
21
- export declare const focusLastElement: (root: HTMLElement) => void;
@@ -88,13 +88,14 @@ export const getFocusData = (args) => {
88
88
  nextIndex = target === "prev" ? positions.first : positions.last;
89
89
  }
90
90
  }
91
- return { overflow: isOverflow, el: focusable[nextIndex] };
91
+ return { overflow: isOverflow, el: focusable[nextIndex], focusableElements: focusable };
92
92
  };
93
93
  const focusTargetElement = (root, target, options) => {
94
94
  const data = getFocusData({ root, target, options });
95
95
  focusElement(data.el);
96
+ return { el: data.el, focusableElements: data.focusableElements };
96
97
  };
97
- export const focusNextElement = (root) => focusTargetElement(root, "next", { includeNegativeTabIndex: true });
98
- export const focusPreviousElement = (root) => focusTargetElement(root, "prev", { includeNegativeTabIndex: true });
98
+ export const focusNextElement = (root, options) => focusTargetElement(root, "next", { ...options, includeNegativeTabIndex: true });
99
+ export const focusPreviousElement = (root, options) => focusTargetElement(root, "prev", { ...options, includeNegativeTabIndex: true });
99
100
  export const focusFirstElement = (root) => focusTargetElement(root, "first", { includeNegativeTabIndex: true });
100
101
  export const focusLastElement = (root) => focusTargetElement(root, "last", { includeNegativeTabIndex: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reshaped",
3
3
  "description": "Professionally crafted design system in React & Figma for building products of any scale and complexity",
4
- "version": "3.8.0-canary.11",
4
+ "version": "3.8.0-canary.13",
5
5
  "license": "MIT",
6
6
  "email": "hello@reshaped.so",
7
7
  "homepage": "https://reshaped.so",
@@ -1,21 +0,0 @@
1
- declare const _default: {
2
- title: string;
3
- component: import("react").FC<import("./..").DropdownMenuProps> & {
4
- Dismissible: import("react").FC<import("../../Dismissible").DismissibleProps>;
5
- Trigger: import("react").FC<import("../../Flyout").FlyoutTriggerProps>;
6
- Content: import("react").FC<import("../DropdownMenu.types").ContentProps>;
7
- Section: import("react").FC<import("../DropdownMenu.types").SectionProps>;
8
- Item: import("react").FC<import("../DropdownMenu.types").ItemProps>;
9
- SubMenu: import("react").FC<import("../DropdownMenu.types").SubMenuProps>;
10
- SubTrigger: import("react").FC<import("../DropdownMenu.types").SubTriggerProps>;
11
- };
12
- parameters: {
13
- iframe: {
14
- url: string;
15
- };
16
- chromatic: {
17
- disableSnapshot: boolean;
18
- };
19
- };
20
- };
21
- export default _default;
@@ -1,11 +0,0 @@
1
- import DropdownMenu from "../index.js";
2
- export default {
3
- title: "Components/DropdownMenu/tests",
4
- component: DropdownMenu,
5
- parameters: {
6
- iframe: {
7
- url: "https://reshaped.so/docs/components/dropdown-menu",
8
- },
9
- chromatic: { disableSnapshot: true },
10
- },
11
- };
@@ -1,17 +0,0 @@
1
- declare const _default: {
2
- title: string;
3
- component: import("react").ForwardRefExoticComponent<Pick<import("../../Actionable").ActionableProps, "children" | "disabled" | "className" | "attributes" | "render" | "type" | "onClick" | "href" | "stopPropagation"> & {
4
- icon?: import("../../Icon").IconProps["svg"];
5
- color?: "inherit" | "critical" | "primary" | "positive" | "warning";
6
- variant?: "plain" | "underline";
7
- } & import("react").RefAttributes<import("../../Actionable").ActionableRef>>;
8
- parameters: {
9
- iframe: {
10
- url: string;
11
- };
12
- chromatic: {
13
- disableSnapshot: boolean;
14
- };
15
- };
16
- };
17
- export default _default;
@@ -1,11 +0,0 @@
1
- import Link from "../index.js";
2
- export default {
3
- title: "Components/Link/tests",
4
- component: Link,
5
- parameters: {
6
- iframe: {
7
- url: "https://reshaped.so/docs/components/breadcrumbs",
8
- },
9
- chromatic: { disableSnapshot: true },
10
- },
11
- };
@@ -1,13 +0,0 @@
1
- declare const _default: {
2
- title: string;
3
- component: import("react").FC<import("./..").LoaderProps>;
4
- parameters: {
5
- iframe: {
6
- url: string;
7
- };
8
- chromatic: {
9
- disableSnapshot: boolean;
10
- };
11
- };
12
- };
13
- export default _default;
@@ -1,11 +0,0 @@
1
- import Loader from "../index.js";
2
- export default {
3
- title: "Components/Loader/tests",
4
- component: Loader,
5
- parameters: {
6
- iframe: {
7
- url: "https://reshaped.so/docs/components/loader",
8
- },
9
- chromatic: { disableSnapshot: true },
10
- },
11
- };
@@ -1,19 +0,0 @@
1
- declare const _default: {
2
- title: string;
3
- component: import("react").FC<import("./..").TableProps> & {
4
- Cell: import("react").FC<import("./..").TableCellProps>;
5
- Heading: import("react").FC<import("./..").TableHeadingProps>;
6
- Row: import("react").FC<import("./..").TableRowProps>;
7
- Body: import("react").FC<import("./..").TableBodyProps>;
8
- Head: import("react").FC<import("./..").TableHeadProps>;
9
- };
10
- parameters: {
11
- iframe: {
12
- url: string;
13
- };
14
- chromatic: {
15
- disableSnapshot: boolean;
16
- };
17
- };
18
- };
19
- export default _default;
@@ -1,11 +0,0 @@
1
- import Table from "../index.js";
2
- export default {
3
- title: "Components/Table/tests",
4
- component: Table,
5
- parameters: {
6
- iframe: {
7
- url: "https://reshaped.so/docs/components/table",
8
- },
9
- chromatic: { disableSnapshot: true },
10
- },
11
- };
@@ -1,15 +0,0 @@
1
- declare const _default: {
2
- title: string;
3
- component: import("react").FC<import("./..").TextFieldProps> & {
4
- Aligner: import("react").FC<import("../../_private/Aligner").AlignerProps>;
5
- };
6
- parameters: {
7
- iframe: {
8
- url: string;
9
- };
10
- chromatic: {
11
- disableSnapshot: boolean;
12
- };
13
- };
14
- };
15
- export default _default;
@@ -1,11 +0,0 @@
1
- import TextField from "../index.js";
2
- export default {
3
- title: "Components/TextField/tests",
4
- component: TextField,
5
- parameters: {
6
- iframe: {
7
- url: "https://reshaped.so/docs/components/text-area",
8
- },
9
- chromatic: { disableSnapshot: true },
10
- },
11
- };
@@ -1,15 +0,0 @@
1
- declare const _default: {
2
- title: string;
3
- component: import("react").FC<import("./..").TimelineProps> & {
4
- Item: import("react").FC<import("./..").TimelineItemProps>;
5
- };
6
- parameters: {
7
- iframe: {
8
- url: string;
9
- };
10
- chromatic: {
11
- disableSnapshot: boolean;
12
- };
13
- };
14
- };
15
- export default _default;
@@ -1,11 +0,0 @@
1
- import Timeline from "../index.js";
2
- export default {
3
- title: "Components/Timeline/tests",
4
- component: Timeline,
5
- parameters: {
6
- iframe: {
7
- url: "https://reshaped.so/docs/components/timeline",
8
- },
9
- chromatic: { disableSnapshot: true },
10
- },
11
- };
@@ -1,13 +0,0 @@
1
- declare const _default: {
2
- title: string;
3
- component: import("react").FC<import("./..").TooltipProps>;
4
- parameters: {
5
- iframe: {
6
- url: string;
7
- };
8
- chromatic: {
9
- disableSnapshot: boolean;
10
- };
11
- };
12
- };
13
- export default _default;
@@ -1,11 +0,0 @@
1
- import Tooltip from "../index.js";
2
- export default {
3
- title: "Components/Tooltip/tests",
4
- component: Tooltip,
5
- parameters: {
6
- iframe: {
7
- url: "https://reshaped.so/docs/components/tooltip",
8
- },
9
- chromatic: { disableSnapshot: true },
10
- },
11
- };