@conveyorhq/arrow-ds 2.0.0-beta.7 → 2.0.0-beta.9

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 (181) hide show
  1. package/package.json +15 -14
  2. package/public/components/Accordion/Accordion.js +8 -10
  3. package/public/components/Avatar/Avatar.js +20 -19
  4. package/public/components/Button/Button.js +2 -2
  5. package/public/components/ConveyorLogo/ConveyorLogo.js +6 -6
  6. package/public/components/Drawer/Drawer.js +7 -7
  7. package/public/components/Frame/Frame.d.ts +1 -1
  8. package/public/components/Icon/Icon.d.ts +1 -0
  9. package/public/components/Icon/Icon.js +3 -1
  10. package/public/components/MenuRenderer/MenuRenderer.js +4 -7
  11. package/public/components/Modal/Modal.js +1 -1
  12. package/public/components/OptionButton/OptionButton.js +18 -13
  13. package/public/components/Select/Select.js +4 -4
  14. package/public/components/Select/SelectPopover.js +6 -6
  15. package/public/components/Select/index.d.ts +2 -0
  16. package/public/components/Select/index.js +3 -0
  17. package/public/components/Select/theme.js +22 -22
  18. package/public/components/Svg/Svg.d.ts +3 -3
  19. package/public/components/Svg/Svg.js +1 -2
  20. package/public/components/Tooltip/Tooltip.js +11 -19
  21. package/public/components/VisuallyHidden/VisuallyHidden.d.ts +2 -1
  22. package/public/components/VisuallyHidden/VisuallyHidden.js +3 -5
  23. package/public/css/styles.css +139 -59
  24. package/public/css/styles.min.css +1 -1
  25. package/public/css/styles.min.css.map +1 -1
  26. package/public/hooks/index.d.ts +3 -0
  27. package/public/hooks/index.js +7 -1
  28. package/public/hooks/useMatchMedia.d.ts +1 -0
  29. package/public/hooks/useMatchMedia.js +27 -0
  30. package/public/hooks/usePrefersReducedMotion.d.ts +1 -0
  31. package/public/hooks/usePrefersReducedMotion.js +9 -0
  32. package/public/hooks/useScreenOrientation.d.ts +1 -0
  33. package/public/hooks/useScreenOrientation.js +24 -0
  34. package/public/{style-dictionary → src/style-dictionary}/dist/tokens.css +1 -0
  35. package/public/src/style-dictionary/dist/tokens.d.ts +428 -0
  36. package/public/src/style-dictionary/dist/tokens.js +428 -0
  37. package/public/src/style-dictionary/dist/tokens.module.js +428 -0
  38. package/public/src/style-dictionary/tailwind.config.js +87 -0
  39. package/public/storybook-components/EnumTable.js +2 -1
  40. package/public/storybook-components/Story.d.ts +2 -1
  41. package/public/storybook-components/Story.js +4 -1
  42. package/public/style-dictionary/dist/tokens.d.ts +428 -422
  43. package/public/style-dictionary/dist/tokens.js +415 -416
  44. package/public/style-dictionary/dist/tokens.module.d.ts +431 -0
  45. package/public/style-dictionary/dist/tokens.module.js +412 -415
  46. package/public/style-dictionary/src/border-radius.d.ts +31 -0
  47. package/public/style-dictionary/src/border-radius.js +10 -9
  48. package/public/style-dictionary/src/border-width.d.ts +21 -0
  49. package/public/style-dictionary/src/border-width.js +9 -8
  50. package/public/style-dictionary/src/color.d.ts +249 -0
  51. package/public/style-dictionary/src/color.js +97 -95
  52. package/public/style-dictionary/src/font-size.d.ts +45 -0
  53. package/public/style-dictionary/src/font-size.js +14 -13
  54. package/public/style-dictionary/src/font-weight.d.ts +13 -0
  55. package/public/style-dictionary/src/font-weight.js +6 -5
  56. package/public/style-dictionary/src/height.d.ts +215 -0
  57. package/public/style-dictionary/src/height.js +10 -10
  58. package/public/style-dictionary/src/leading.d.ts +17 -0
  59. package/public/style-dictionary/src/leading.js +7 -6
  60. package/public/style-dictionary/src/screen-width.d.ts +17 -0
  61. package/public/style-dictionary/src/screen-width.js +7 -6
  62. package/public/style-dictionary/src/shadow.d.ts +63 -0
  63. package/public/style-dictionary/src/shadow.js +19 -18
  64. package/public/style-dictionary/src/spacing.d.ts +197 -0
  65. package/public/style-dictionary/src/spacing.js +68 -67
  66. package/public/style-dictionary/src/tracking.d.ts +13 -0
  67. package/public/style-dictionary/src/tracking.js +6 -5
  68. package/public/style-dictionary/src/type.d.ts +13 -0
  69. package/public/style-dictionary/src/type.js +32 -31
  70. package/public/style-dictionary/src/width.d.ts +287 -0
  71. package/public/style-dictionary/src/width.js +29 -29
  72. package/public/style-dictionary/src/z-index.d.ts +53 -0
  73. package/public/style-dictionary/src/z-index.js +20 -19
  74. package/public/style-dictionary/tailwind.config.d.ts +392 -0
  75. package/public/style-dictionary/tailwind.config.js +51 -72
  76. package/src/components/Accordion/Accordion.tsx +39 -27
  77. package/src/components/Avatar/Avatar.tsx +20 -19
  78. package/src/components/Button/Button.tsx +3 -3
  79. package/src/components/Button/index.css +12 -1
  80. package/src/components/Card/Card.story.mdx +45 -37
  81. package/src/components/ConveyorLogo/ConveyorLogo.tsx +6 -6
  82. package/src/components/Drawer/Drawer.tsx +1 -1
  83. package/src/components/Frame/Frame.story.mdx +140 -5
  84. package/src/components/Frame/Frame.tsx +1 -1
  85. package/src/components/Frame/index.css +8 -13
  86. package/src/components/Icon/Icon.tsx +3 -0
  87. package/src/components/MenuRenderer/MenuRenderer.tsx +7 -9
  88. package/src/components/Modal/Modal.tsx +1 -1
  89. package/src/components/Modal/index.css +8 -3
  90. package/src/components/OptionButton/OptionButton.story.mdx +91 -36
  91. package/src/components/OptionButton/OptionButton.tsx +19 -18
  92. package/src/components/OptionButton/index.css +13 -0
  93. package/src/components/Overlay/Overlay.story.mdx +26 -0
  94. package/src/components/Select/Select.tsx +4 -4
  95. package/src/components/Select/SelectPopover.tsx +6 -6
  96. package/src/components/Select/index.ts +14 -0
  97. package/src/components/Select/theme.ts +22 -22
  98. package/src/components/Svg/Svg.story.mdx +36 -0
  99. package/src/components/Svg/Svg.tsx +6 -4
  100. package/src/components/Text/Text.story.mdx +34 -0
  101. package/src/components/Tooltip/Tooltip.story.mdx +21 -0
  102. package/src/components/Tooltip/Tooltip.tsx +23 -27
  103. package/src/components/Tooltip/index.css +31 -0
  104. package/src/components/VisuallyHidden/VisuallyHidden.story.mdx +54 -0
  105. package/src/components/VisuallyHidden/VisuallyHidden.tsx +10 -5
  106. package/src/components/VisuallyHidden/index.css +3 -0
  107. package/src/css/components.css +2 -0
  108. package/src/docs/Colors.story.mdx +13 -13
  109. package/src/docs/Spacing.story.mdx +4 -20
  110. package/src/docs/Tokens.story.mdx +230 -0
  111. package/src/docs/Typography.story.mdx +17 -94
  112. package/src/docs/hooks/useDisclosureHook.story.mdx +58 -0
  113. package/src/docs/hooks/useKeyPressHook.story.mdx +54 -0
  114. package/src/docs/hooks/useMatchMediaHook.story.mdx +42 -0
  115. package/src/docs/hooks/useOutsideClickHook.story.mdx +56 -0
  116. package/src/docs/hooks/usePrefersReducedMotion.story.mdx +61 -0
  117. package/src/docs/hooks/useScreenOrientationHook.story.mdx +56 -0
  118. package/src/docs/hooks/useStepHook.story.mdx +102 -0
  119. package/src/hooks/index.ts +3 -0
  120. package/src/hooks/useMatchMedia.ts +40 -0
  121. package/src/hooks/usePrefersReducedMotion.ts +9 -0
  122. package/src/hooks/useScreenOrientation.ts +27 -0
  123. package/src/storybook-components/EnumTable.tsx +3 -2
  124. package/src/storybook-components/Story.tsx +13 -1
  125. package/src/style-dictionary/dist/tokens.css +378 -0
  126. package/src/style-dictionary/dist/tokens.d.ts +428 -0
  127. package/src/style-dictionary/dist/tokens.js +428 -0
  128. package/src/style-dictionary/dist/tokens.module.js +428 -0
  129. package/src/style-dictionary/src/border-radius.js +11 -0
  130. package/src/style-dictionary/src/border-width.js +10 -0
  131. package/src/style-dictionary/src/color.js +98 -0
  132. package/src/style-dictionary/src/font-size.js +15 -0
  133. package/src/style-dictionary/src/font-weight.js +7 -0
  134. package/src/style-dictionary/src/height.js +13 -0
  135. package/src/style-dictionary/src/leading.js +8 -0
  136. package/src/style-dictionary/src/screen-width.js +8 -0
  137. package/src/style-dictionary/src/shadow.js +19 -0
  138. package/src/style-dictionary/src/spacing.js +69 -0
  139. package/src/style-dictionary/src/tracking.js +7 -0
  140. package/src/style-dictionary/src/type.js +34 -0
  141. package/src/style-dictionary/src/width.js +32 -0
  142. package/src/style-dictionary/src/z-index.js +21 -0
  143. package/src/style-dictionary/tailwind.config.js +87 -0
  144. package/src/tokens/borders.ts +6 -0
  145. package/src/tokens/box-shadow.ts +3 -0
  146. package/src/tokens/colors.ts +6 -0
  147. package/src/tokens/font-family.ts +3 -0
  148. package/src/tokens/font-size.ts +3 -0
  149. package/src/tokens/font-weight.ts +3 -0
  150. package/src/tokens/height.ts +3 -0
  151. package/src/tokens/index.ts +3 -2
  152. package/src/tokens/letter-spacing.ts +3 -0
  153. package/src/tokens/line-height.ts +3 -0
  154. package/src/tokens/margin.ts +3 -0
  155. package/src/tokens/padding.ts +3 -0
  156. package/src/tokens/screens.ts +3 -0
  157. package/src/tokens/sizing-scale.ts +6 -0
  158. package/src/tokens/width.ts +9 -0
  159. package/src/tokens/will-change.ts +3 -0
  160. package/src/tokens/z-index.ts +3 -0
  161. package/src/types/index.ts +3 -0
  162. package/public/components/Overlay/Overlay.story.d.ts +0 -1
  163. package/public/components/Overlay/Overlay.story.js +0 -12
  164. package/public/components/Svg/Svg.story.d.ts +0 -1
  165. package/public/components/Svg/Svg.story.js +0 -14
  166. package/public/components/Text/Text.story.d.ts +0 -1
  167. package/public/components/Text/Text.story.js +0 -31
  168. package/public/components/VisuallyHidden/VisuallyHidden.story.d.ts +0 -1
  169. package/public/components/VisuallyHidden/VisuallyHidden.story.js +0 -36
  170. package/public/components/useStep/ExampleSetupWizard.d.ts +0 -4
  171. package/public/components/useStep/ExampleSetupWizard.js +0 -33
  172. package/src/components/Overlay/Overlay.md +0 -14
  173. package/src/components/Overlay/Overlay.story.tsx +0 -12
  174. package/src/components/Svg/Svg.md +0 -14
  175. package/src/components/Svg/Svg.story.tsx +0 -15
  176. package/src/components/Text/Text.md +0 -14
  177. package/src/components/Text/Text.story.tsx +0 -12
  178. package/src/components/VisuallyHidden/VisuallyHidden.md +0 -23
  179. package/src/components/VisuallyHidden/VisuallyHidden.story.tsx +0 -19
  180. package/src/components/useStep/ExampleSetupWizard.tsx +0 -63
  181. package/src/components/useStep/useStep.story.mdx +0 -76
@@ -1,41 +1,15 @@
1
1
  import { Meta, Typeset } from "@storybook/addon-docs/blocks";
2
- import { fontFamily } from "../tokens/font-family";
3
- import { fontSize } from "../tokens/font-size";
4
- import { fontWeight } from "../tokens/font-weight";
5
- import { SimpleTable } from "../components/SimpleTable";
6
-
7
- <Meta title="Tokens/Typography" />
8
-
9
- export const Table = ({ children, columns }) => (
10
- <SimpleTable className="w-1/2">
11
- <SimpleTable.Row>
12
- {columns.map((column) => (
13
- <SimpleTable.HeaderCell key={column} className="w-1/2">
14
- {column}
15
- </SimpleTable.HeaderCell>
16
- ))}
17
- </SimpleTable.Row>
18
- {children}
19
- </SimpleTable>
20
- );
21
-
22
- export const Row = ({ children }) => (
23
- <SimpleTable.Row className="border-b border-gray-300">
24
- {children}
25
- </SimpleTable.Row>
26
- );
27
-
28
- export const Cell = ({ children }) => (
29
- <SimpleTable.Cell>{children}</SimpleTable.Cell>
30
- );
2
+ import { tokens } from "../style-dictionary/dist/tokens";
3
+
4
+ <Meta title="Styles/Typography" />
31
5
 
32
6
  export const fontSizes = [
33
- fontSize.h1,
34
- fontSize.h2,
35
- fontSize.h3,
36
- fontSize.h4,
37
- fontSize.h5,
38
- fontSize.h6,
7
+ tokens.fontSize.h1,
8
+ tokens.fontSize.h2,
9
+ tokens.fontSize.h3,
10
+ tokens.fontSize.h4,
11
+ tokens.fontSize.h5,
12
+ tokens.fontSize.h6,
39
13
  ].map((size) => Number(size.replace("px", "")));
40
14
 
41
15
  export const sampleText = "The quick brown fox jumps over the lazy dog.";
@@ -48,8 +22,8 @@ export const sampleText = "The quick brown fox jumps over the lazy dog.";
48
22
 
49
23
  <Typeset
50
24
  fontSizes={fontSizes}
51
- fontWeight={fontWeight.regular}
52
- fontFamily={fontFamily.sans}
25
+ fontWeight={tokens.fontWeight.regular}
26
+ fontFamily={tokens.type.sans.split(", ")}
53
27
  sampleText={sampleText}
54
28
  />
55
29
 
@@ -57,8 +31,8 @@ export const sampleText = "The quick brown fox jumps over the lazy dog.";
57
31
 
58
32
  <Typeset
59
33
  fontSizes={fontSizes}
60
- fontWeight={fontWeight.medium}
61
- fontFamily={fontFamily.sans}
34
+ fontWeight={tokens.fontWeight.medium}
35
+ fontFamily={tokens.type.sans.split(", ")}
62
36
  sampleText={sampleText}
63
37
  />
64
38
 
@@ -66,8 +40,8 @@ export const sampleText = "The quick brown fox jumps over the lazy dog.";
66
40
 
67
41
  <Typeset
68
42
  fontSizes={fontSizes}
69
- fontWeight={fontWeight.bold}
70
- fontFamily={fontFamily.sans}
43
+ fontWeight={tokens.fontWeight.bold}
44
+ fontFamily={tokens.type.sans.split(", ")}
71
45
  sampleText={sampleText}
72
46
  />
73
47
 
@@ -77,7 +51,7 @@ export const sampleText = "The quick brown fox jumps over the lazy dog.";
77
51
 
78
52
  <Typeset
79
53
  fontSizes={fontSizes}
80
- fontFamily={fontFamily.serif}
54
+ fontFamily={tokens.type.serif.split(", ")}
81
55
  sampleText={sampleText}
82
56
  />
83
57
 
@@ -87,57 +61,6 @@ export const sampleText = "The quick brown fox jumps over the lazy dog.";
87
61
 
88
62
  <Typeset
89
63
  fontSizes={fontSizes}
90
- fontFamily={fontFamily.mono}
64
+ fontFamily={tokens.type.mono.split(", ")}
91
65
  sampleText={sampleText}
92
66
  />
93
-
94
- <hr />
95
-
96
- ## Tokens
97
-
98
- ### Font family
99
-
100
- <Table columns={["Key", "Value"]}>
101
- {Object.keys(fontFamily).map((key) => (
102
- <Row key={key}>
103
- <Cell>
104
- <code>{key}</code>
105
- </Cell>
106
- <Cell>
107
- <code>{fontFamily[key].join(", ")}</code>
108
- </Cell>
109
- </Row>
110
- ))}
111
- </Table>
112
-
113
- ### Font size
114
-
115
- <Table columns={["Key", "Value"]}>
116
- {Object.keys(fontSize).map((key) => (
117
- <Row key={key}>
118
- <Cell>
119
- <code>{key}</code>
120
- </Cell>
121
- <Cell>
122
- <code>{fontSize[key]}</code>
123
- </Cell>
124
- </Row>
125
- ))}
126
- </Table>
127
-
128
- ### Font weight
129
-
130
- Weight can only be applied to Neue Montreal.
131
-
132
- <Table columns={["Key", "Value"]}>
133
- {Object.keys(fontWeight).map((key) => (
134
- <Row key={key}>
135
- <Cell>
136
- <code>{key}</code>
137
- </Cell>
138
- <Cell>
139
- <code>{fontWeight[key].toString()}</code>
140
- </Cell>
141
- </Row>
142
- ))}
143
- </Table>
@@ -0,0 +1,58 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="Hooks/use-disclosure" />
4
+
5
+ # use-disclosure hook
6
+
7
+ Control the visibility of content.
8
+
9
+ ## Purpose
10
+
11
+ The use-disclosure hook is used to detect and control the visibility of a
12
+ component by providing events `onOpen`, `onClose`, and `onToggle` which alter
13
+ the `isOpen` state.
14
+
15
+ By default, `isOpen` is false, but you can pass `true` to the hook to change
16
+ the initial state.
17
+
18
+ ## Usage
19
+
20
+ The most common scenario is the combination of a toggle button outside of the
21
+ disclosed component and a close button on the inside.
22
+
23
+ ```jsx
24
+ import React from "react";
25
+ import { useDisclosure } from "@conveyorhq/arrow-ds";
26
+
27
+ export const Component = () => {
28
+ const initialState = true; // optional, false otherwise
29
+ const { isOpen, onClose, onToggle } = useDisclosure(initialState);
30
+
31
+ return (
32
+ <Box>
33
+ <Button onClick={onToggle}>Toggle box</Button>
34
+ <Box hidden={isOpen}>
35
+ <Button onClick={onClose}>Close box</Button>
36
+ <Paragraph>Box content</Paragraph>
37
+ </Box>
38
+ </Box>
39
+ );
40
+ };
41
+ ```
42
+
43
+ ## Return values
44
+
45
+ - `isOpen`: whether or not the content has been disclosed
46
+ - `onOpen`: function to show the content; sets `isOpen` to `true`
47
+ - `onClose`: function to hide the content; sets `isOpen` to `false`
48
+ - `onToggle`: function to either show or hide the content based on the value of `isOpen`
49
+
50
+ ## API
51
+
52
+ ### defaultIsOpen
53
+
54
+ Determines the default visibility
55
+
56
+ Required: No<br />
57
+ Default value: `false`<br />
58
+ Type: `boolean`
@@ -0,0 +1,54 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="Hooks/use-key-press" />
4
+
5
+ # use-key-press hook
6
+
7
+ Call a function when a key is pressed.
8
+
9
+ ## Purpose
10
+
11
+ The use-key-press hook is used to call a function when a specific key is
12
+ pressed. This is useful when you want to add a simple keyboard command to a
13
+ component.
14
+
15
+ ## Usage
16
+
17
+ A common scenario is pressing the escape key to close a popover. In the example
18
+ below, this is paired with `useDisclosure`.
19
+
20
+ ```jsx
21
+ import React from "react";
22
+ import { useKeyPress, KEY_CODE, useDisclosure } from "@conveyorhq/arrow-ds";
23
+
24
+ export const Component = () => {
25
+ const { isOpen, onOpen, onClose } = useDisclosure();
26
+
27
+ useKeyPress(KEY_CODE.ESC, onClose);
28
+
29
+ return (
30
+ <Box>
31
+ <Button onClick={onOpen}>Open Popover</Button>
32
+ {isOpen && <Box>Popover; press escape to close</Box>}
33
+ </Box>
34
+ );
35
+ };
36
+ ```
37
+
38
+ ## API
39
+
40
+ ### targetKeyCode
41
+
42
+ The key being pressed
43
+
44
+ Required: Yes<br />
45
+ Default value: N/A<br />
46
+ Type: `number`, `KEY_CODE`
47
+
48
+ ### callback
49
+
50
+ The function to call
51
+
52
+ Required: Yes<br />
53
+ Default value: N/A<br />
54
+ Type: `function`
@@ -0,0 +1,42 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="Hooks/use-match-media" />
4
+
5
+ # use-match-media hook
6
+
7
+ Detect whether or not a media query matches.
8
+
9
+ ## Purpose
10
+
11
+ The use-match-media hook uses the native JavaScript API
12
+ [window.matchMedia](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia)
13
+ to determine if the document matches a given media query string. It also
14
+ monitors the document when it’s being resized to check when it matches (or stops
15
+ matching) the media query.
16
+
17
+ ## Usage
18
+
19
+ ```jsx
20
+ import React from "react";
21
+ import { useMatchMedia } from "@conveyorhq/arrow-ds";
22
+
23
+ export const Component = () => {
24
+ const isMobile = useMatchMedia("(max-width: 768px)");
25
+
26
+ return (
27
+ <Box className={isMobile ? "mobile" : "desktop"}>
28
+ The current layout is {isMobile ? "mobile" : "desktop"}.
29
+ </Box>
30
+ );
31
+ };
32
+ ```
33
+
34
+ ## API
35
+
36
+ ### query
37
+
38
+ Media query to check
39
+
40
+ Required: Yes<br />
41
+ Default value: N/A<br />
42
+ Type: `string`
@@ -0,0 +1,56 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="Hooks/use-outside-click" />
4
+
5
+ # use-outside-click hook
6
+
7
+ Call a function when a click happens outside the bounds of a component.
8
+
9
+ ## Purpose
10
+
11
+ The use-outside-click hook detects when a click happens outside of a given
12
+ element and calls a function.
13
+
14
+ ## Usage
15
+
16
+ A common scenario is clicking on a backdrop to close a popover. In the example
17
+ below, this is paired with `useDisclosure`.
18
+
19
+ ```jsx
20
+ import React from "react";
21
+ import { useOutsideClick, useDisclosure } from "@conveyorhq/arrow-ds";
22
+
23
+ export const Component = () => {
24
+ const { isOpen, onOpen, onClose } = useDisclosure();
25
+ const popoverRef = React.useRef(null);
26
+
27
+ useOutsideClick(popoverRef, () => {
28
+ onClose();
29
+ });
30
+
31
+ return (
32
+ <Box>
33
+ <Button onClick={onOpen}>Open Popover</Button>
34
+ {isOpen && <Box ref={popoverRef}>Popover; click outside to close</Box>}
35
+ </Box>
36
+ );
37
+ };
38
+ ```
39
+
40
+ ## API
41
+
42
+ ### refs
43
+
44
+ Ref(s) of the element(s) where the outside click is going to happen
45
+
46
+ Required: Yes<br />
47
+ Default value: N/A<br />
48
+ Type: `RefObject`, `Array<RefObject>`
49
+
50
+ ### callback
51
+
52
+ The function to call
53
+
54
+ Required: Yes<br />
55
+ Default value: N/A<br />
56
+ Type: `function`
@@ -0,0 +1,61 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="Hooks/use-prefers-reduced-motion" />
4
+
5
+ # use-prefers-reduced-motion hook
6
+
7
+ Detect whether or not a system preference is set to reduce motion.
8
+
9
+ ## Purpose
10
+
11
+ The use-prefers-reduced-motion hook uses a
12
+ [CSS media query](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion)
13
+ to detect if a system-level preference has been set by the user to reduce the
14
+ amount of non-essential motion.
15
+
16
+ This hook can be used to allow people to “opt-out” of transitions and animations
17
+ that they may find disorienting or distracting.
18
+
19
+ ## Usage
20
+
21
+ ```jsx
22
+ import React from "react";
23
+ import { usePrefersReducedMotion } from "@conveyorhq/arrow-ds";
24
+
25
+ export const Component = () => {
26
+ const prefersReducedMotion = usePrefersReducedMotion();
27
+
28
+ return (
29
+ <Box className={prefersReducedMotion ? "no-animation" : "animation"}>
30
+ The CSS animation will run if no preference is set.
31
+ </Box>
32
+ );
33
+ };
34
+ ```
35
+
36
+ In combination with `react-spring`
37
+
38
+ ```jsx
39
+ import React from "react";
40
+ import { animated, useSpring } from "@react-spring/web";
41
+ import { usePrefersReducedMotion } from "@conveyorhq/arrow-ds";
42
+
43
+ export const Component = () => {
44
+ const prefersReducedMotion = usePrefersReducedMotion();
45
+ const [viz, setViz] = React.useState(false);
46
+ const props = useSpring({
47
+ opacity: viz ? 1 : 0,
48
+ immediate: prefersReducedMotion,
49
+ });
50
+
51
+ return (
52
+ <animated.div style={opacity}>
53
+ The opacity will transition if no preference is set.
54
+ </animated.div>
55
+ );
56
+ };
57
+ ```
58
+
59
+ ## API
60
+
61
+ This hook accepts no props.
@@ -0,0 +1,56 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="Hooks/use-screen-orientation" />
4
+
5
+ # use-screen-orientation hook
6
+
7
+ Call a function when a click happens outside the bounds of a component.
8
+
9
+ ## Purpose
10
+
11
+ The use-outside-click hook detects when a click happens outside of a given
12
+ element and calls a function.
13
+
14
+ ## Usage
15
+
16
+ A common scenario is clicking on a backdrop to close a popover. In the example
17
+ below, this is paired with `useDisclosure`.
18
+
19
+ ```jsx
20
+ import React from "react";
21
+ import { useOutsideClick, useDisclosure } from "@conveyorhq/arrow-ds";
22
+
23
+ export const Component = () => {
24
+ const { isOpen, onOpen, onClose } = useDisclosure();
25
+ const popoverRef = React.useRef(null);
26
+
27
+ useOutsideClick(popoverRef, () => {
28
+ onClose();
29
+ });
30
+
31
+ return (
32
+ <Box>
33
+ <Button onClick={onOpen}>Open Popover</Button>
34
+ {isOpen && <Box ref={popoverRef}>Popover; click outside to close</Box>}
35
+ </Box>
36
+ );
37
+ };
38
+ ```
39
+
40
+ ## API
41
+
42
+ ### refs
43
+
44
+ Ref(s) of the element(s) where the outside click is going to happen
45
+
46
+ Required: Yes<br />
47
+ Default value: N/A<br />
48
+ Type: `RefObject`, `Array<RefObject>`
49
+
50
+ ### callback
51
+
52
+ The function to call
53
+
54
+ Required: Yes<br />
55
+ Default value: N/A<br />
56
+ Type: `function`
@@ -0,0 +1,102 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="Hooks/use-step" />
4
+
5
+ # use-step hook
6
+
7
+ Manage a multiple step sequence
8
+
9
+ ## Purpose
10
+
11
+ The use-step hook provides a way to track a multiple step sequence. The hook
12
+ needs to know how many total steps are in the sequence and then it will keep
13
+ track of which step is current and provide methods for navigating between each
14
+ step. The UI is up to you.
15
+
16
+ ## Usage
17
+
18
+ To see an example within a modal, look at the [modal story](/?path=/docs/components-modal--default#set-up-wizard-example).
19
+
20
+ ```jsx
21
+ export const Component = () => {
22
+ const { step, goToNextStep, goToPreviousStep, goToStep } = useStep({
23
+ steps: 4,
24
+ initialStep: 2,
25
+ });
26
+
27
+ return (
28
+ <Box>
29
+ <Box className="p-8">
30
+ {step === 1 && <>Step 1</>}
31
+ {step === 2 && <>Step 2</>}
32
+ {step === 3 && <>Step 3</>}
33
+ {step === 4 && <>Step 4</>}
34
+ </Panel>
35
+
36
+ <Button.Group className="mt-4 justify-end">
37
+ {step !== 1 && (
38
+ <Button.Group className="mr-auto">
39
+ <Button
40
+ variant={BUTTON_VARIANT.SECONDARY}
41
+ onClick={goToPreviousStep}
42
+ >
43
+ Previous Step
44
+ </Button>
45
+ </Button.Group>
46
+ )}
47
+
48
+ <Button
49
+ variant={BUTTON_VARIANT.SECONDARY}
50
+ onClick={() => {
51
+ goToStep(1);
52
+ }}
53
+ >
54
+ Cancel
55
+ </Button>
56
+
57
+ {step === 4 ? (
58
+ <Button
59
+ onClick={() => {
60
+ console.log("Create button clicked");
61
+ }}
62
+ >
63
+ Create
64
+ </Button>
65
+ ) : (
66
+ <Button onClick={goToNextStep}>Next Step</Button>
67
+ )}
68
+ </Button.Group>
69
+ </Box>
70
+ );
71
+ };
72
+ ```
73
+
74
+ ## Return values
75
+
76
+ - `step`: the current step, a `number`
77
+ - `goToNextStep`: function to advance to the next step, `step + 1`
78
+ - `goToPreviousStep`: function to advance to the previous step, `step - 1`
79
+ - `goToStep`: function to advance to a specific step; accepts the argument `newStep`, a `number`
80
+ - `currentStepIndex`: the index value of the current step, `step - 1`
81
+ - `nextStepIndex`: the index value of the next step, `currentStepIndex + 1`
82
+ - `previousStepIndex`: the index value of the previous step, `currentStepIndex - 1`
83
+ - `isFirstStep`: boolean to determine if the current step is the first step in the sequence
84
+ - `isLastStep`: boolean to determine if the current step is the last step in the sequence
85
+
86
+ ## API
87
+
88
+ ### steps
89
+
90
+ Total number of steps
91
+
92
+ Required: No<br />
93
+ Default value: `1`<br />
94
+ Type: `number`
95
+
96
+ ### initialStep
97
+
98
+ The step on which to begin; should not exceed `steps`
99
+
100
+ Required: No<br />
101
+ Default value: `1`<br />
102
+ Type: `number`
@@ -1,5 +1,8 @@
1
1
  export { useCopyToClipboard } from "./useCopyToClipboard";
2
2
  export { useDisclosure } from "./useDisclosure";
3
3
  export { useKeyPress } from "./useKeyPress";
4
+ export { useMatchMedia } from "./useMatchMedia";
4
5
  export { useOutsideClick } from "./useOutsideClick";
6
+ export { usePrefersReducedMotion } from "./usePrefersReducedMotion";
7
+ export { useScreenOrientation } from "./useScreenOrientation";
5
8
  export { useStep } from "./useStep";
@@ -0,0 +1,40 @@
1
+ import { useLayoutEffect, useState } from "react";
2
+
3
+ export function useMatchMedia(query: string): boolean {
4
+ const getMatches = (q: string) => {
5
+ if (typeof window !== "undefined") {
6
+ return window.matchMedia(q).matches;
7
+ }
8
+
9
+ return false;
10
+ };
11
+
12
+ const [matches, setMatches] = useState(getMatches(query));
13
+
14
+ useLayoutEffect(() => {
15
+ const mediaQueryList = window.matchMedia(query);
16
+ const onChange = (event: MediaQueryListEvent) => setMatches(event.matches);
17
+
18
+ /**
19
+ * 1. Safari currently doesn't support add/removeEventListener, so we use
20
+ * add/removeListener
21
+ * 2. add/removeListener are maybe marked as deprecated, but that could be
22
+ * wrong, see https://github.com/microsoft/TypeScript/issues/32210
23
+ * 3. This change came about due to error being captured in Sentry, see
24
+ * https://sentry.io/organizations/conveyorhq/issues/2733251662/?project=5829161
25
+ * 4. Change to `mediaQueryList.addEventListener("change", onChange)` when
26
+ * supported
27
+ */
28
+ if (mediaQueryList) {
29
+ mediaQueryList.addListener(onChange);
30
+ }
31
+
32
+ return () => {
33
+ if (mediaQueryList) {
34
+ mediaQueryList.removeListener(onChange);
35
+ }
36
+ };
37
+ }, [query]);
38
+
39
+ return matches;
40
+ }
@@ -0,0 +1,9 @@
1
+ import { useMatchMedia } from "./useMatchMedia";
2
+
3
+ export function usePrefersReducedMotion() {
4
+ const hasNoPreference = useMatchMedia(
5
+ "(prefers-reduced-motion: no-preference)",
6
+ );
7
+
8
+ return !hasNoPreference;
9
+ }
@@ -0,0 +1,27 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+
3
+ export const useScreenOrientation = () => {
4
+ const getOrientation = () => {
5
+ if (typeof window !== "undefined") {
6
+ return window.screen.orientation.type;
7
+ }
8
+
9
+ return undefined;
10
+ };
11
+
12
+ const [orientation, setOrientation] = useState(getOrientation());
13
+
14
+ const updateOrientation = useCallback(() => {
15
+ setOrientation(getOrientation());
16
+ }, []);
17
+
18
+ useEffect(() => {
19
+ window.addEventListener("orientationchange", updateOrientation);
20
+
21
+ return () => {
22
+ window.removeEventListener("orientationchange", updateOrientation);
23
+ };
24
+ }, [updateOrientation]);
25
+
26
+ return orientation;
27
+ };
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
- import { Box, Flex, SimpleTable, tokens } from "..";
2
+ import { Box, Flex, SimpleTable } from "..";
3
+ import { tokens } from "../style-dictionary/dist/tokens";
3
4
  import { Code } from "./Code";
4
5
 
5
6
  interface EnumItemObject {
@@ -31,7 +32,7 @@ export const EnumTable = ({ enums }: EnumTableProps) => {
31
32
  <code className="mr-6 mt-1 block">{enumName}</code>
32
33
  </SimpleTable.Cell>
33
34
  <SimpleTable.Cell className="whitespace-normal">
34
- <Flex className="flex-wrap" style={{ gap: tokens.margin[1] }}>
35
+ <Flex className="flex-wrap" style={{ gap: tokens.spacing[1] }}>
35
36
  {Object.keys(enums[enumName]).map((enumValue) => (
36
37
  <Box key={enumValue}>
37
38
  <Code>{enumValue}</Code>