@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,14 +1,16 @@
1
1
  import React from "react";
2
- import classNames from "classnames";
3
2
  import Overlay from "react-overlays/Overlay";
4
3
  import { useId } from "@reach/auto-id";
5
4
 
6
5
  import { KEY_CODE, PopperPlacement } from "../../types";
7
6
  import { useDisclosure, useKeyPress } from "../../hooks";
8
- import { mergeEventHandlers } from "../../utilities";
7
+ import { bemHOF, mergeEventHandlers } from "../../utilities";
8
+ import { tokens } from "../../style-dictionary/dist/tokens";
9
9
 
10
10
  import { Box } from "../Box";
11
11
 
12
+ const cn = bemHOF("Tooltip");
13
+
12
14
  /**
13
15
  * Tooltip.Arrow
14
16
  * =============================================================================
@@ -23,19 +25,19 @@ const TooltipArrow = React.forwardRef<HTMLDivElement, TooltipArrowProps>(
23
25
  ({ placement, style }, forwaredRef) => {
24
26
  const generatePositionStyles = () => {
25
27
  if (placement.startsWith("top")) {
26
- return { bottom: "-4px", left: 0 };
28
+ return { bottom: `-${tokens.spacing[1]}`, left: 0 };
27
29
  }
28
30
 
29
31
  if (placement.startsWith("right")) {
30
- return { left: "-4px", top: 0 };
32
+ return { left: `-${tokens.spacing[1]}`, top: 0 };
31
33
  }
32
34
 
33
35
  if (placement.startsWith("bottom")) {
34
- return { top: "-4px", left: 0 };
36
+ return { top: `-${tokens.spacing[1]}`, left: 0 };
35
37
  }
36
38
 
37
39
  if (placement.startsWith("left")) {
38
- return { right: "-4px", top: 0 };
40
+ return { right: `-${tokens.spacing[1]}`, top: 0 };
39
41
  }
40
42
 
41
43
  return {};
@@ -46,18 +48,13 @@ const TooltipArrow = React.forwardRef<HTMLDivElement, TooltipArrowProps>(
46
48
  return (
47
49
  <Box
48
50
  ref={forwaredRef}
49
- className="absolute w-2 h-2 z-below"
51
+ className={cn({ e: "arrow" })}
50
52
  style={{
51
53
  ...style,
52
54
  ...positionStyles,
53
55
  }}
54
56
  >
55
- <Box
56
- className="absolute w-2 h-2 top-0 left-0 bg-gray-900"
57
- style={{
58
- transform: "rotate(45deg)",
59
- }}
60
- />
57
+ <Box />
61
58
  </Box>
62
59
  );
63
60
  },
@@ -171,11 +168,14 @@ export const Tooltip = ({
171
168
  onMouseDown: mergeEventHandlers(onMouseDown, onHideDelay),
172
169
  onFocus: mergeEventHandlers(onFocus, onShow),
173
170
  onBlur: mergeEventHandlers(onBlur, onHide),
174
- onKeyDown: mergeEventHandlers(onKeyDown, (event) => {
175
- if (event.key === "Enter" || event.key === " ") {
176
- onHide();
177
- }
178
- }),
171
+ onKeyDown: mergeEventHandlers(
172
+ onKeyDown,
173
+ (event: React.KeyboardEvent<HTMLElement>) => {
174
+ if (event.key === "Enter" || event.key === " ") {
175
+ onHide();
176
+ }
177
+ },
178
+ ),
179
179
  ...rest,
180
180
  });
181
181
 
@@ -194,7 +194,7 @@ export const Tooltip = ({
194
194
  }
195
195
  };
196
196
 
197
- return (
197
+ return content ? (
198
198
  <Box ref={rootRef}>
199
199
  {React.cloneElement(React.Children.only(children), {
200
200
  ...triggerProps(children.props),
@@ -219,14 +219,8 @@ export const Tooltip = ({
219
219
  return (
220
220
  <Box
221
221
  id={id}
222
- className={classNames([
223
- "bg-gray-900 text-white",
224
- "text-bodySm leading-normal",
225
- "inline-flex items-center",
226
- "rounded shadow-popover",
227
- "px-3 py-2",
228
- "relative z-popup",
229
- ])}
222
+ className={cn()}
223
+ data-component="tooltip"
230
224
  onMouseEnter={handlePopoverMouseEnter}
231
225
  onMouseLeave={handlePopoverMouseLeave}
232
226
  {...contentProps}
@@ -243,5 +237,7 @@ export const Tooltip = ({
243
237
  </Overlay>
244
238
  )}
245
239
  </Box>
240
+ ) : (
241
+ children
246
242
  );
247
243
  };
@@ -0,0 +1,31 @@
1
+ .ads-Tooltip {
2
+ @apply bg-gray-900
3
+ text-white
4
+ text-bodySm
5
+ leading-normal
6
+ inline-flex
7
+ items-center
8
+ rounded
9
+ shadow-popover
10
+ px-3
11
+ py-2
12
+ z-popup
13
+ max-w-64;
14
+ }
15
+
16
+ .ads-Tooltip-arrow {
17
+ @apply w-2
18
+ h-2
19
+ z-below;
20
+ }
21
+
22
+ .ads-Tooltip-arrow > div {
23
+ @apply absolute
24
+ w-2
25
+ h-2
26
+ top-0
27
+ left-0
28
+ bg-gray-900;
29
+
30
+ transform: rotate(45deg);
31
+ }
@@ -0,0 +1,54 @@
1
+ import {
2
+ Story,
3
+ Preview,
4
+ Props,
5
+ Meta,
6
+ SourceState,
7
+ } from "@storybook/addon-docs/blocks";
8
+ import { Box } from "../Box";
9
+ import { Icon, ICON_TYPE } from "../Icon";
10
+ import { VisuallyHidden } from "./VisuallyHidden";
11
+
12
+ <Meta
13
+ title="Components/Disclosure/Visually Hidden"
14
+ component={VisuallyHidden}
15
+ />
16
+
17
+ # VisuallyHidden
18
+
19
+ `VisuallyHidden` is a way to show content to screen readers but hide it from the
20
+ screen.
21
+
22
+ ## Installation
23
+
24
+ ```jsx
25
+ import { VisuallyHidden } from "@conveyorhq/arrow-ds";
26
+ ```
27
+
28
+ ## Basic usage
29
+
30
+ <Preview withSource={SourceState.OPEN}>
31
+ <Story name="VisuallyHidden">
32
+ <Box>Visible content</Box>
33
+ <VisuallyHidden>Hidden content</VisuallyHidden>
34
+ </Story>
35
+ </Preview>
36
+
37
+ ## API
38
+
39
+ Extends `BoxProps`
40
+
41
+ <Props of={VisuallyHidden} />
42
+
43
+ ## Demos
44
+
45
+ Providing more context to an icon.
46
+
47
+ <Preview withSource={SourceState.OPEN}>
48
+ <Story name="VisuallyHidden icon">
49
+ <Box>
50
+ <Icon icon={ICON_TYPE.COG} />
51
+ <VisuallyHidden>Settings</VisuallyHidden>
52
+ </Box>
53
+ </Story>
54
+ </Preview>
@@ -1,8 +1,13 @@
1
1
  import React from "react";
2
- import cn from "classnames";
2
+ import classNames from "classnames";
3
3
  import { Box, BoxProps } from "../Box";
4
+ import { bemHOF } from "../../utilities";
4
5
 
5
- export const VisuallyHidden = (props: BoxProps) => {
6
- const { className, ...rest } = props;
7
- return <Box {...rest} className={cn("visually-hidden", className)} />;
8
- };
6
+ const cn = bemHOF("VisuallyHidden");
7
+
8
+ export const VisuallyHidden: React.FunctionComponent<BoxProps> = React.forwardRef<
9
+ HTMLDivElement,
10
+ BoxProps
11
+ >(({ className, ...rest }, forwardedRef) => (
12
+ <Box ref={forwardedRef} className={classNames(cn(), className)} {...rest} />
13
+ ));
@@ -0,0 +1,3 @@
1
+ .ads-VisuallyHidden {
2
+ @apply visually-hidden;
3
+ }
@@ -49,4 +49,6 @@
49
49
  @import "../components/Toast";
50
50
  @import "../components/Toggle";
51
51
  @import "../components/Token";
52
+ @import "../components/Tooltip";
52
53
  @import "../components/Truncate";
54
+ @import "../components/VisuallyHidden";
@@ -1,8 +1,8 @@
1
1
  import { Meta, ColorPalette, ColorItem } from "@storybook/addon-docs/blocks";
2
2
  import { CustomColorPalette } from "../storybook-components/CustomColorPalette";
3
- import { colors } from "../tokens";
3
+ import { tokens } from "../style-dictionary/dist/tokens";
4
4
 
5
- <Meta title="Tokens/Colors" />
5
+ <Meta title="Styles/Colors" />
6
6
 
7
7
  export const palette = (color, range = [200, 600]) => {
8
8
  const offset = (range[0] - 100) / 100;
@@ -12,15 +12,15 @@ export const palette = (color, range = [200, 600]) => {
12
12
  const object = {};
13
13
  array.forEach((n) => {
14
14
  Object.assign(object, {
15
- [n * 100]: colors[color][n * 100],
15
+ [n * 100]: tokens.color[color][n * 100],
16
16
  });
17
17
  });
18
18
  return object;
19
19
  };
20
20
 
21
21
  export const bw = {
22
- black: colors.black,
23
- white: colors.white,
22
+ black: tokens.color.black,
23
+ white: tokens.color.white,
24
24
  };
25
25
 
26
26
  export const grays = palette("gray", [100, 900]);
@@ -35,26 +35,26 @@ export const cyan = palette("cyan");
35
35
  export const purple = palette("purple");
36
36
 
37
37
  export const lighten = {
38
- 100: colors.lighten["100"],
39
- 200: colors.lighten["200"],
40
- 300: colors.lighten["300"],
38
+ 100: tokens.color.lighten["100"],
39
+ 200: tokens.color.lighten["200"],
40
+ 300: tokens.color.lighten["300"],
41
41
  };
42
42
 
43
43
  export const functional = {
44
44
  border: {
45
- border: colors.border,
45
+ border: tokens.color.border,
46
46
  },
47
47
  link: {
48
- link: colors.link,
48
+ link: tokens.color.link,
49
49
  },
50
50
  success: {
51
- success: colors.success,
51
+ success: tokens.color.success,
52
52
  },
53
53
  failure: {
54
- failure: colors.failure,
54
+ failure: tokens.color.failure,
55
55
  },
56
56
  caution: {
57
- caution: colors.caution,
57
+ caution: tokens.color.caution,
58
58
  },
59
59
  };
60
60
 
@@ -1,8 +1,7 @@
1
1
  import { Meta } from "@storybook/addon-docs/blocks";
2
- import { padding } from "../tokens/padding";
3
2
  import { SimpleTable } from "../components/SimpleTable";
4
3
 
5
- <Meta title="Tokens/Spacing" />
4
+ <Meta title="Styles/Spacing" />
6
5
 
7
6
  export const Table = ({ children, columns }) => (
8
7
  <SimpleTable className="w-1/2">
@@ -35,22 +34,7 @@ The follow values can be used for `margin`, `padding` and `gap`.
35
34
 
36
35
  `margin` also includes a negative scale and the `auto` keyword.
37
36
 
38
- <Table columns={["Key", "Value"]}>
39
- {Object.keys(padding).map((key) => (
40
- <Row key={key}>
41
- <Cell>
42
- <code>{key}</code>
43
- </Cell>
44
- <Cell>
45
- <code>{padding[key]}</code>
46
- </Cell>
47
- </Row>
48
- ))}
49
- </Table>
50
-
51
- ## Using spacing tokens
52
-
53
- ### Margin
37
+ ## Margin
54
38
 
55
39
  Margin controls the spacing on the outside of an element.
56
40
 
@@ -99,7 +83,7 @@ Margin controls the spacing on the outside of an element.
99
83
  </Row>
100
84
  </Table>
101
85
 
102
- ### Padding
86
+ ## Padding
103
87
 
104
88
  Padding controls the spacing on the inside of an element.
105
89
 
@@ -148,7 +132,7 @@ Padding controls the spacing on the inside of an element.
148
132
  </Row>
149
133
  </Table>
150
134
 
151
- ### Gap
135
+ ## Gap
152
136
 
153
137
  Gap is used to space items within grid and flexbox layouts.
154
138
 
@@ -0,0 +1,230 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+ import { tokens } from "../style-dictionary/dist/tokens";
3
+ import { Button, SimpleTable, Tooltip, BUTTON_VARIANT, ICON_TYPE } from "../..";
4
+
5
+ <Meta title="Documentation/Tokens" />
6
+
7
+ export const categories = Object.keys(tokens);
8
+
9
+ export const copyToClipboard = (text) => {
10
+ navigator.clipboard.writeText(text);
11
+ };
12
+
13
+ export const ClickToCopy = ({ text }) => {
14
+ const [copied, setCopied] = React.useState(false);
15
+ const renderProps = {
16
+ onMouseOut: () => setCopied(false),
17
+ onBlur: () => setCopied(false),
18
+ onClick: () => {
19
+ copyToClipboard(text);
20
+ setCopied(true);
21
+ },
22
+ };
23
+ return (
24
+ <Tooltip
25
+ placement="top"
26
+ referenceElement={
27
+ <Button
28
+ variant={BUTTON_VARIANT.MINIMAL}
29
+ icon={ICON_TYPE.CLIPBOARD}
30
+ {...renderProps}
31
+ />
32
+ }
33
+ >
34
+ {copied ? "Copied!" : "Copy token path"}
35
+ </Tooltip>
36
+ );
37
+ };
38
+
39
+ export const Swatch = ({ color }) => (
40
+ <div
41
+ style={{
42
+ width: "21px",
43
+ height: "21px",
44
+ borderRadius: "3px",
45
+ backgroundColor: color,
46
+ }}
47
+ />
48
+ );
49
+
50
+ export const Table = ({ children, columns }) => (
51
+ <SimpleTable style={{ width: "100%" }}>
52
+ {columns && (
53
+ <SimpleTable.Row>
54
+ {columns.map((column, i) => (
55
+ <SimpleTable.HeaderCell
56
+ key={column}
57
+ style={{
58
+ width: i === columns.length - 1 ? "auto" : "50%",
59
+ }}
60
+ >
61
+ {column}
62
+ </SimpleTable.HeaderCell>
63
+ ))}
64
+ </SimpleTable.Row>
65
+ )}
66
+ {children}
67
+ </SimpleTable>
68
+ );
69
+
70
+ export const Row = ({ children, style }) => (
71
+ <SimpleTable.Row
72
+ style={{
73
+ borderBottom: `1px solid ${tokens.color.gray[300]}`,
74
+ verticalAlign: "top",
75
+ ...style,
76
+ }}
77
+ >
78
+ {children}
79
+ </SimpleTable.Row>
80
+ );
81
+
82
+ export const Cell = ({ children, ...rest }) => (
83
+ <SimpleTable.Cell {...rest}>{children}</SimpleTable.Cell>
84
+ );
85
+
86
+ # Tokens
87
+
88
+ These tokens are normally used in JavaScript. In almost all cases, you’ll
89
+ want to use the Tailwind CSS utility classnames instead.
90
+
91
+ ## Usage
92
+
93
+ ```js
94
+ import { tokens } from "@conveyorhq/design-tokens";
95
+ ```
96
+
97
+ export const titleize = (string) => {
98
+ const title = string.replace(/([A-Z])/g, " $1").toLowerCase();
99
+ return `${title.charAt(0).toUpperCase()}${title.slice(1)}`;
100
+ };
101
+
102
+ <ul
103
+ style={{
104
+ listStyle: "none",
105
+ padding: 0,
106
+ }}
107
+ >
108
+ {categories.map((category) => (
109
+ <li key={category}>
110
+ <a href={`#${category}`}>
111
+ {titleize(category)}
112
+ {category === "leading" && " (line height)"}
113
+ {category === "screenWidth" && " (breakpoints)"}
114
+ {category === "tracking" && " (letter spacing)"}
115
+ {category === "type" && " (font family)"}
116
+ </a>
117
+ </li>
118
+ ))}
119
+ </ul>
120
+
121
+ <div>
122
+ <br />
123
+ <br />
124
+ {categories.map((category) => (
125
+ <div key={category} id={category}>
126
+ <h2>
127
+ {titleize(category)}
128
+ {category === "leading" && " (line height)"}
129
+ {category === "screenWidth" && " (breakpoints)"}
130
+ {category === "tracking" && " (letter spacing)"}
131
+ {category === "type" && " (font family)"}
132
+ </h2>
133
+ <p>
134
+ {category === "color" ? (
135
+ <>
136
+ <code>tokens.{category}[key]</code> or{" "}
137
+ <code>tokens.{category}[key][key]</code>
138
+ </>
139
+ ) : (
140
+ <code>tokens.{category}[key]</code>
141
+ )}
142
+ </p>
143
+ {category === "fontWeight" && (
144
+ <p>Weight can only be applied to Neue Montreal.</p>
145
+ )}
146
+ <Table columns={["Key", "Value", ""]}>
147
+ {Object.keys(tokens[category]).map((key) => (
148
+ <Row key={key}>
149
+ <Cell>
150
+ <code>{key}</code>
151
+ </Cell>
152
+ <Cell
153
+ colspan={typeof tokens[category][key] === "object" ? 2 : null}
154
+ >
155
+ {typeof tokens[category][key] === "object" ? (
156
+ <Table>
157
+ {Object.keys(tokens[category][key]).map((k, i) => (
158
+ <Row
159
+ key={k}
160
+ style={
161
+ i === Object.keys(tokens[category][key]).length - 1
162
+ ? {
163
+ borderBottom: 0,
164
+ }
165
+ : {}
166
+ }
167
+ >
168
+ <Cell style={{ width: "50%" }}>
169
+ <code>{k}</code>
170
+ </Cell>
171
+ <Cell style={{ width: "50%" }}>
172
+ <div style={{ display: "flex", gap: "4px" }}>
173
+ <code>{tokens[category][key][k]}</code>
174
+ {category === "color" && (
175
+ <Swatch color={tokens[category][key][k]} />
176
+ )}
177
+ </div>
178
+ </Cell>
179
+ <Cell style={{ width: "auto" }}>
180
+ {typeof tokens[category][key][k] !== "object" && (
181
+ <>
182
+ {isNaN(parseInt(k, 10)) ? (
183
+ <ClickToCopy
184
+ text={`tokens.${category}.${key}.${k}`}
185
+ />
186
+ ) : (
187
+ <ClickToCopy
188
+ text={`tokens.${category}.${key}[${k}]`}
189
+ />
190
+ )}
191
+ </>
192
+ )}
193
+ </Cell>
194
+ </Row>
195
+ ))}
196
+ </Table>
197
+ ) : (
198
+ <div style={{ display: "flex", gap: "4px" }}>
199
+ {category === "type" ? (
200
+ <code>
201
+ <pre style={{ fontSize: "inherit" }}>
202
+ {tokens[category][key].replaceAll(", ", ",\n")}
203
+ </pre>
204
+ </code>
205
+ ) : (
206
+ <code>{tokens[category][key]}</code>
207
+ )}
208
+ {category === "color" && (
209
+ <Swatch color={tokens[category][key]} />
210
+ )}
211
+ </div>
212
+ )}
213
+ </Cell>
214
+ {typeof tokens[category][key] !== "object" && (
215
+ <Cell style={{ textAlign: "right" }}>
216
+ {isNaN(parseInt(key, 10)) ? (
217
+ <ClickToCopy text={`tokens.${category}.${key}`} />
218
+ ) : (
219
+ <ClickToCopy text={`tokens.${category}[${key}]`} />
220
+ )}
221
+ </Cell>
222
+ )}
223
+ </Row>
224
+ ))}
225
+ </Table>
226
+ <br />
227
+ <br />
228
+ </div>
229
+ ))}
230
+ </div>