@iota/apps-ui-kit 0.2.0 → 0.3.0

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 (213) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/index.d.ts +1636 -0
  3. package/dist/index.es.js +8909 -0
  4. package/dist/index.es.js.map +1 -0
  5. package/dist/index.umd.js +198 -0
  6. package/dist/index.umd.js.map +1 -0
  7. package/dist/style.css +1 -0
  8. package/package.json +6 -3
  9. package/src/lib/components/atoms/badge/Badge.tsx +37 -0
  10. package/src/lib/components/atoms/badge/badge.classes.ts +24 -0
  11. package/src/lib/components/atoms/badge/badge.enums.ts +8 -0
  12. package/src/lib/components/atoms/badge/index.ts +6 -0
  13. package/src/lib/components/atoms/button/Button.tsx +99 -0
  14. package/src/lib/components/atoms/button/button-variants/ButtonPill.tsx +23 -0
  15. package/src/lib/components/atoms/button/button-variants/ButtonUnstyled.tsx +27 -0
  16. package/src/lib/components/atoms/button/button-variants/buttonVariants.types.ts +11 -0
  17. package/src/lib/components/atoms/button/button-variants/index.ts +5 -0
  18. package/src/lib/components/atoms/button/button.classes.ts +53 -0
  19. package/src/lib/components/atoms/button/button.enums.ts +21 -0
  20. package/src/lib/components/atoms/button/index.ts +7 -0
  21. package/src/lib/components/atoms/button-segment/ButtonSegment.tsx +86 -0
  22. package/src/lib/components/atoms/button-segment/buttonSegment.classes.ts +45 -0
  23. package/src/lib/components/atoms/button-segment/buttonSegment.enums.ts +7 -0
  24. package/src/lib/components/atoms/button-segment/index.ts +5 -0
  25. package/src/lib/components/atoms/checkbox/Checkbox.tsx +114 -0
  26. package/src/lib/components/atoms/checkbox/index.ts +4 -0
  27. package/src/lib/components/atoms/divider/Divider.tsx +48 -0
  28. package/src/lib/components/atoms/divider/divider.classes.ts +11 -0
  29. package/src/lib/components/atoms/divider/divider.enums.ts +7 -0
  30. package/src/lib/components/atoms/divider/index.ts +6 -0
  31. package/src/lib/components/atoms/header/Header.tsx +73 -0
  32. package/src/lib/components/atoms/header/index.ts +4 -0
  33. package/src/lib/components/atoms/index.ts +22 -0
  34. package/src/lib/components/atoms/info-box/InfoBox.tsx +73 -0
  35. package/src/lib/components/atoms/info-box/index.ts +5 -0
  36. package/src/lib/components/atoms/info-box/infoBox.classes.ts +19 -0
  37. package/src/lib/components/atoms/info-box/infoBox.enums.ts +14 -0
  38. package/src/lib/components/atoms/key-value-info/KeyValueInfo.tsx +156 -0
  39. package/src/lib/components/atoms/key-value-info/index.ts +6 -0
  40. package/src/lib/components/atoms/key-value-info/keyValue.enums.ts +7 -0
  41. package/src/lib/components/atoms/label-text/LabelText.tsx +93 -0
  42. package/src/lib/components/atoms/label-text/index.ts +5 -0
  43. package/src/lib/components/atoms/label-text/labelText.classes.ts +22 -0
  44. package/src/lib/components/atoms/label-text/labelText.enums.ts +8 -0
  45. package/src/lib/components/atoms/list-item/ListItem.tsx +89 -0
  46. package/src/lib/components/atoms/list-item/index.ts +4 -0
  47. package/src/lib/components/atoms/loading-indicator/LoadingIndicator.tsx +38 -0
  48. package/src/lib/components/atoms/loading-indicator/index.ts +4 -0
  49. package/src/lib/components/atoms/panel/Panel.tsx +30 -0
  50. package/src/lib/components/atoms/panel/index.ts +4 -0
  51. package/src/lib/components/atoms/placeholder/Placeholder.tsx +27 -0
  52. package/src/lib/components/atoms/placeholder/index.ts +4 -0
  53. package/src/lib/components/atoms/radio-button/RadioButton.tsx +68 -0
  54. package/src/lib/components/atoms/radio-button/index.ts +4 -0
  55. package/src/lib/components/atoms/secondary-text/SecondaryText.tsx +28 -0
  56. package/src/lib/components/atoms/secondary-text/index.ts +4 -0
  57. package/src/lib/components/atoms/skeleton/Skeleton.tsx +47 -0
  58. package/src/lib/components/atoms/skeleton/index.ts +4 -0
  59. package/src/lib/components/atoms/snackbar/Snackbar.tsx +69 -0
  60. package/src/lib/components/atoms/snackbar/index.ts +5 -0
  61. package/src/lib/components/atoms/snackbar/snackbar.classes.ts +18 -0
  62. package/src/lib/components/atoms/snackbar/snackbar.enums.tsx +9 -0
  63. package/src/lib/components/atoms/tooltip/Tooltip.tsx +37 -0
  64. package/src/lib/components/atoms/tooltip/index.ts +5 -0
  65. package/src/lib/components/atoms/tooltip/tooltip.classes.ts +11 -0
  66. package/src/lib/components/atoms/tooltip/tooltip.enums.ts +9 -0
  67. package/src/lib/components/atoms/visual-asset-card/VisualAssetCard.tsx +101 -0
  68. package/src/lib/components/atoms/visual-asset-card/index.ts +5 -0
  69. package/src/lib/components/atoms/visual-asset-card/visualAssetCard.enums.ts +7 -0
  70. package/src/lib/components/index.ts +8 -0
  71. package/src/lib/components/molecules/account/Account.tsx +174 -0
  72. package/src/lib/components/molecules/account/index.ts +4 -0
  73. package/src/lib/components/molecules/address/Address.tsx +101 -0
  74. package/src/lib/components/molecules/address/index.ts +4 -0
  75. package/src/lib/components/molecules/card/Card.tsx +70 -0
  76. package/src/lib/components/molecules/card/CardAction.tsx +80 -0
  77. package/src/lib/components/molecules/card/CardBody.tsx +61 -0
  78. package/src/lib/components/molecules/card/CardImage.tsx +43 -0
  79. package/src/lib/components/molecules/card/CardImagePlaceholder.tsx +146 -0
  80. package/src/lib/components/molecules/card/card.classes.ts +26 -0
  81. package/src/lib/components/molecules/card/card.enums.ts +25 -0
  82. package/src/lib/components/molecules/card/index.ts +8 -0
  83. package/src/lib/components/molecules/chip/Chip.tsx +105 -0
  84. package/src/lib/components/molecules/chip/chip.classes.ts +32 -0
  85. package/src/lib/components/molecules/chip/chip.enums.ts +7 -0
  86. package/src/lib/components/molecules/chip/index.ts +4 -0
  87. package/src/lib/components/molecules/display-stats/DisplayStats.tsx +104 -0
  88. package/src/lib/components/molecules/display-stats/displayStats.classes.ts +36 -0
  89. package/src/lib/components/molecules/display-stats/displayStats.enums.ts +13 -0
  90. package/src/lib/components/molecules/display-stats/index.ts +5 -0
  91. package/src/lib/components/molecules/dropdown/Dropdown.tsx +10 -0
  92. package/src/lib/components/molecules/dropdown/dropdownPosition.enums.ts +7 -0
  93. package/src/lib/components/molecules/dropdown/index.ts +5 -0
  94. package/src/lib/components/molecules/index.ts +17 -0
  95. package/src/lib/components/molecules/input/Input.tsx +245 -0
  96. package/src/lib/components/molecules/input/InputWrapper.tsx +97 -0
  97. package/src/lib/components/molecules/input/TextArea.tsx +149 -0
  98. package/src/lib/components/molecules/input/index.ts +8 -0
  99. package/src/lib/components/molecules/input/input.classes.ts +14 -0
  100. package/src/lib/components/molecules/input/input.enums.ts +14 -0
  101. package/src/lib/components/molecules/input/input.types.ts +29 -0
  102. package/src/lib/components/molecules/navbar-item/NavbarItem.tsx +48 -0
  103. package/src/lib/components/molecules/navbar-item/NavbarItemHorizontal.tsx +65 -0
  104. package/src/lib/components/molecules/navbar-item/NavbarItemVertical.tsx +54 -0
  105. package/src/lib/components/molecules/navbar-item/index.ts +5 -0
  106. package/src/lib/components/molecules/navbar-item/navbarItem.classes.ts +16 -0
  107. package/src/lib/components/molecules/navbar-item/navbarItem.enums.ts +7 -0
  108. package/src/lib/components/molecules/search/Search.tsx +220 -0
  109. package/src/lib/components/molecules/search/index.ts +5 -0
  110. package/src/lib/components/molecules/search/search.classes.ts +20 -0
  111. package/src/lib/components/molecules/search/search.enums.ts +7 -0
  112. package/src/lib/components/molecules/segmented-button/SegmentedButton.tsx +34 -0
  113. package/src/lib/components/molecules/segmented-button/index.ts +6 -0
  114. package/src/lib/components/molecules/segmented-button/segmentedButton.classes.ts +12 -0
  115. package/src/lib/components/molecules/segmented-button/segmentedButton.enums.ts +8 -0
  116. package/src/lib/components/molecules/select/Select.tsx +223 -0
  117. package/src/lib/components/molecules/select/index.ts +5 -0
  118. package/src/lib/components/molecules/select/select.enums.ts +7 -0
  119. package/src/lib/components/molecules/table-cell/TableCell.tsx +62 -0
  120. package/src/lib/components/molecules/table-cell/index.ts +4 -0
  121. package/src/lib/components/molecules/table-header-cell/TableHeaderCell.tsx +140 -0
  122. package/src/lib/components/molecules/table-header-cell/index.ts +5 -0
  123. package/src/lib/components/molecules/table-header-cell/tableHeaderCell.enums.ts +7 -0
  124. package/src/lib/components/molecules/title/Title.tsx +69 -0
  125. package/src/lib/components/molecules/title/index.ts +5 -0
  126. package/src/lib/components/molecules/title/titleClasses.constants.ts +14 -0
  127. package/src/lib/components/molecules/title/titleSize.enums.ts +7 -0
  128. package/src/lib/components/organisms/accordion/Accordion.tsx +109 -0
  129. package/src/lib/components/organisms/accordion/accordion.classes.ts +4 -0
  130. package/src/lib/components/organisms/accordion/index.ts +4 -0
  131. package/src/lib/components/organisms/dialog/Dialog.tsx +123 -0
  132. package/src/lib/components/organisms/dialog/dialog.enums.ts +7 -0
  133. package/src/lib/components/organisms/dialog/index.ts +5 -0
  134. package/src/lib/components/organisms/index.ts +7 -0
  135. package/src/lib/components/organisms/navbar/Navbar.tsx +100 -0
  136. package/src/lib/components/organisms/navbar/NavbarSlideout.tsx +58 -0
  137. package/src/lib/components/organisms/navbar/index.ts +5 -0
  138. package/src/lib/components/organisms/table/Table.tsx +224 -0
  139. package/src/lib/components/organisms/table/TableContext.tsx +55 -0
  140. package/src/lib/components/organisms/table/index.ts +4 -0
  141. package/src/lib/constants/colors.constants.ts +132 -0
  142. package/src/lib/constants/index.ts +4 -0
  143. package/src/lib/enums/index.ts +4 -0
  144. package/src/lib/enums/screenSize.enums.ts +9 -0
  145. package/src/lib/index.ts +8 -0
  146. package/src/lib/styles/fonts.css +5 -0
  147. package/src/lib/styles/index.css +149 -0
  148. package/src/lib/tailwind/base.presets.ts +49 -0
  149. package/src/lib/tailwind/constants/fontSizes.constants.ts +201 -0
  150. package/src/lib/tailwind/constants/index.ts +6 -0
  151. package/src/lib/tailwind/constants/scaling.constants.ts +41 -0
  152. package/src/lib/tailwind/constants/variableSpacing.constants.ts +66 -0
  153. package/src/lib/tailwind/helpers.ts +20 -0
  154. package/src/lib/tailwind/index.ts +5 -0
  155. package/src/lib/tailwind/plugins.ts +8 -0
  156. package/src/lib/tailwind/responsive.presets.ts +36 -0
  157. package/src/lib/tailwind/static.presets.ts +25 -0
  158. package/src/lib/tailwind/types.ts +6 -0
  159. package/src/lib/utils/format.ts +8 -0
  160. package/src/lib/utils/index.ts +4 -0
  161. package/src/storybook/blocks/Showcase.tsx +20 -0
  162. package/src/storybook/blocks/TypeSet.tsx +34 -0
  163. package/src/storybook/blocks/TypeSetItem.tsx +74 -0
  164. package/src/storybook/blocks/index.ts +6 -0
  165. package/src/storybook/constants/index.ts +5 -0
  166. package/src/storybook/constants/typeset.constants.ts +39 -0
  167. package/src/storybook/constants/variableSpacing.constants.ts +6 -0
  168. package/src/storybook/helpers/getFontSizeLabel.ts +15 -0
  169. package/src/storybook/helpers/index.ts +4 -0
  170. package/src/storybook/stories/atoms/Badge.stories.tsx +32 -0
  171. package/src/storybook/stories/atoms/Button.stories.tsx +45 -0
  172. package/src/storybook/stories/atoms/ButtonSegment.stories.tsx +45 -0
  173. package/src/storybook/stories/atoms/Checkbox.stories.tsx +34 -0
  174. package/src/storybook/stories/atoms/CustomScrollbar.stories.tsx +22 -0
  175. package/src/storybook/stories/atoms/Divider.stories.tsx +41 -0
  176. package/src/storybook/stories/atoms/Header.stories.tsx +58 -0
  177. package/src/storybook/stories/atoms/InfoBox.stories.tsx +67 -0
  178. package/src/storybook/stories/atoms/KeyValueInfo.stories.tsx +59 -0
  179. package/src/storybook/stories/atoms/LabelText.stories.tsx +55 -0
  180. package/src/storybook/stories/atoms/ListItem.stories.tsx +41 -0
  181. package/src/storybook/stories/atoms/LoadingIndicator.stories.tsx +32 -0
  182. package/src/storybook/stories/atoms/Panel.stories.tsx +36 -0
  183. package/src/storybook/stories/atoms/Placeholder.stories.tsx +33 -0
  184. package/src/storybook/stories/atoms/RadioButton.stories.tsx +51 -0
  185. package/src/storybook/stories/atoms/Skeleton.stories.tsx +33 -0
  186. package/src/storybook/stories/atoms/Snackbar.stories.tsx +42 -0
  187. package/src/storybook/stories/atoms/Tooltip.stories.tsx +57 -0
  188. package/src/storybook/stories/atoms/VisualAssetCard.stories.tsx +56 -0
  189. package/src/storybook/stories/components/VariableSpacingShowcase.tsx +46 -0
  190. package/src/storybook/stories/components/index.ts +4 -0
  191. package/src/storybook/stories/design-tokens/colors.stories.mdx +23 -0
  192. package/src/storybook/stories/design-tokens/icons.stories.mdx +17 -0
  193. package/src/storybook/stories/design-tokens/typeset.stories.mdx +15 -0
  194. package/src/storybook/stories/design-tokens/variable-spacing.stories.mdx +10 -0
  195. package/src/storybook/stories/molecules/Account.stories.tsx +69 -0
  196. package/src/storybook/stories/molecules/Address.stories.tsx +39 -0
  197. package/src/storybook/stories/molecules/Card.stories.tsx +115 -0
  198. package/src/storybook/stories/molecules/Chip.stories.tsx +122 -0
  199. package/src/storybook/stories/molecules/DisplayStats.stories.tsx +63 -0
  200. package/src/storybook/stories/molecules/Dropdown.stories.tsx +38 -0
  201. package/src/storybook/stories/molecules/Input.stories.tsx +161 -0
  202. package/src/storybook/stories/molecules/NavbarItem.stories.tsx +45 -0
  203. package/src/storybook/stories/molecules/Search.stories.tsx +100 -0
  204. package/src/storybook/stories/molecules/SegmentedButton.stories.tsx +107 -0
  205. package/src/storybook/stories/molecules/Select.stories.tsx +102 -0
  206. package/src/storybook/stories/molecules/TableCell.stories.tsx +46 -0
  207. package/src/storybook/stories/molecules/TableHeaderCell.stories.tsx +34 -0
  208. package/src/storybook/stories/molecules/TextArea.stories.tsx +80 -0
  209. package/src/storybook/stories/molecules/Title.stories.tsx +76 -0
  210. package/src/storybook/stories/organisms/Accordion.stories.tsx +70 -0
  211. package/src/storybook/stories/organisms/Dialog.stories.tsx +103 -0
  212. package/src/storybook/stories/organisms/Navbar.stories.tsx +77 -0
  213. package/src/storybook/stories/organisms/Table.stories.tsx +154 -0
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@iota/apps-ui-kit",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "github.com:iotaledger/iota.git"
7
7
  },
8
8
  "license": "Apache-2.0",
9
9
  "files": [
10
+ "CHANGELOG.md",
11
+ "LICENSE",
12
+ "src",
10
13
  "dist"
11
14
  ],
12
15
  "exports": {
@@ -27,7 +30,7 @@
27
30
  "react": "^18.3.1",
28
31
  "react-dom": "^18.3.1",
29
32
  "react-number-format": "^5.2.2",
30
- "@iota/apps-ui-icons": "0.2.0"
33
+ "@iota/apps-ui-icons": "0.2.2"
31
34
  },
32
35
  "devDependencies": {
33
36
  "@chromatic-com/storybook": "^1.6.0",
@@ -51,7 +54,7 @@
51
54
  "storybook-dark-mode": "^4.0.2",
52
55
  "tailwindcss": "^3.3.3",
53
56
  "typescript": "^5.5.3",
54
- "vite": "^5.3.3",
57
+ "vite": "^5.4.12",
55
58
  "vite-plugin-dts": "^4.3.0",
56
59
  "vite-tsconfig-paths": "^4.2.0"
57
60
  },
@@ -0,0 +1,37 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import cx from 'classnames';
5
+ import { BadgeType } from './badge.enums';
6
+ import { BACKGROUND_COLORS, BADGE_TEXT_CLASS, BORDER_COLORS, TEXT_COLORS } from './badge.classes';
7
+
8
+ interface BadgeProps {
9
+ /**
10
+ * The type of the badge.
11
+ */
12
+ type: BadgeType;
13
+ /**
14
+ * The label of the badge.
15
+ */
16
+ label?: string;
17
+ }
18
+
19
+ export function Badge({ type, label }: BadgeProps): React.JSX.Element {
20
+ const backgroundClasses = BACKGROUND_COLORS[type];
21
+ const textClasses = TEXT_COLORS[type];
22
+ const borderClasses = BORDER_COLORS[type];
23
+ const labelClasses = label ? 'px-xs py-xxs' : 'h-1.5 w-1.5';
24
+
25
+ return (
26
+ <div
27
+ className={cx(
28
+ 'inline-flex items-center space-x-2 rounded-full border disabled:opacity-30',
29
+ backgroundClasses,
30
+ borderClasses,
31
+ labelClasses,
32
+ )}
33
+ >
34
+ <span className={cx(BADGE_TEXT_CLASS, textClasses)}>{label}</span>
35
+ </div>
36
+ );
37
+ }
@@ -0,0 +1,24 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { BadgeType } from './badge.enums';
5
+
6
+ export const BACKGROUND_COLORS = {
7
+ [BadgeType.PrimarySolid]: 'bg-primary-30',
8
+ [BadgeType.Neutral]: 'bg-neutral-92 dark:bg-neutral-12',
9
+ [BadgeType.PrimarySoft]: 'bg-primary-90 dark:bg-primary-10',
10
+ };
11
+
12
+ export const TEXT_COLORS: Record<BadgeType, string> = {
13
+ [BadgeType.PrimarySolid]: 'text-primary-100',
14
+ [BadgeType.Neutral]: 'text-neutral-10 dark:text-neutral-92',
15
+ [BadgeType.PrimarySoft]: 'text-primary-20 dark:text-primary-90',
16
+ };
17
+
18
+ export const BORDER_COLORS: Record<BadgeType, string> = {
19
+ [BadgeType.PrimarySolid]: 'border-primary-30',
20
+ [BadgeType.Neutral]: 'border-neutral-92 dark:border-neutral-12',
21
+ [BadgeType.PrimarySoft]: 'border-primary-90 dark:border-primary-10',
22
+ };
23
+
24
+ export const BADGE_TEXT_CLASS = 'text-label-md';
@@ -0,0 +1,8 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export enum BadgeType {
5
+ Neutral = 'neutral',
6
+ PrimarySolid = 'primary-solid',
7
+ PrimarySoft = 'primary-fill',
8
+ }
@@ -0,0 +1,6 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { Badge } from './Badge';
5
+
6
+ export * from './badge.enums';
@@ -0,0 +1,99 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ButtonHtmlType, ButtonSize, ButtonType } from './button.enums';
5
+ import {
6
+ PADDINGS,
7
+ PADDINGS_ONLY_ICON,
8
+ BACKGROUND_COLORS,
9
+ TEXT_COLORS,
10
+ TEXT_CLASSES,
11
+ TEXT_COLOR_DISABLED,
12
+ DISABLED_BACKGROUND_COLORS,
13
+ } from './button.classes';
14
+ import cx from 'classnames';
15
+
16
+ export interface ButtonProps {
17
+ /**
18
+ * The size of the button.
19
+ */
20
+ size?: ButtonSize;
21
+ /**
22
+ * The type of the button
23
+ */
24
+ type?: ButtonType;
25
+ /**
26
+ * The text of the button.
27
+ */
28
+ text?: string;
29
+ /**
30
+ The icon of the button
31
+ */
32
+ icon?: React.ReactNode;
33
+ /**
34
+ * Should the icon be after the text.
35
+ */
36
+ iconAfterText?: boolean;
37
+ /**
38
+ * The button is disabled or not.
39
+ */
40
+ disabled?: boolean;
41
+ /**
42
+ * The onClick event of the button.
43
+ */
44
+ onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
45
+ /**
46
+ * Whether the button should have the full width.
47
+ */
48
+ fullWidth?: boolean;
49
+ /**
50
+ * The type of the button. Available options are 'button', 'submit', 'reset'.
51
+ */
52
+ htmlType?: ButtonHtmlType;
53
+ /**
54
+ * The tab index of the button.
55
+ */
56
+ tabIndex?: number;
57
+ /**
58
+ * The 'data-testid' attribute value (used in e2e tests)
59
+ */
60
+ testId?: string;
61
+ }
62
+
63
+ export function Button({
64
+ icon,
65
+ text,
66
+ disabled,
67
+ onClick,
68
+ fullWidth,
69
+ htmlType = ButtonHtmlType.Button,
70
+ size = ButtonSize.Medium,
71
+ type = ButtonType.Primary,
72
+ iconAfterText = false,
73
+ tabIndex = 0,
74
+ testId,
75
+ }: ButtonProps): React.JSX.Element {
76
+ const paddingClasses = icon && !text ? PADDINGS_ONLY_ICON[size] : PADDINGS[size];
77
+ const textSizes = TEXT_CLASSES[size];
78
+ const backgroundColors = disabled ? DISABLED_BACKGROUND_COLORS[type] : BACKGROUND_COLORS[type];
79
+ const textColors = disabled ? TEXT_COLOR_DISABLED[type] : TEXT_COLORS[type];
80
+ return (
81
+ <button
82
+ onClick={onClick}
83
+ type={htmlType}
84
+ className={cx(
85
+ 'state-layer relative flex items-center justify-center gap-2 rounded-full transition-all duration-150 ease-in disabled:cursor-not-allowed disabled:opacity-40',
86
+ paddingClasses,
87
+ backgroundColors,
88
+ fullWidth && 'w-full',
89
+ !iconAfterText ? 'flex-row' : 'flex-row-reverse',
90
+ )}
91
+ disabled={disabled}
92
+ tabIndex={tabIndex}
93
+ data-testid={testId}
94
+ >
95
+ {icon && <span className={cx(textColors)}>{icon}</span>}
96
+ {text && <span className={cx('font-inter', textColors, textSizes)}>{text}</span>}
97
+ </button>
98
+ );
99
+ }
@@ -0,0 +1,23 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ButtonHtmlType } from '../button.enums';
5
+ import { ButtonVariantProps } from './buttonVariants.types';
6
+
7
+ export function ButtonPill({
8
+ htmlType = ButtonHtmlType.Button,
9
+ children,
10
+ tabIndex = 0,
11
+ ...buttonProps
12
+ }: Omit<ButtonVariantProps, 'className'>) {
13
+ return (
14
+ <button
15
+ className="flex items-center justify-center rounded-xl border border-neutral-70 px-sm text-body-md text-neutral-40 disabled:opacity-40 dark:border-neutral-40 dark:text-neutral-60"
16
+ type={htmlType}
17
+ tabIndex={tabIndex}
18
+ {...buttonProps}
19
+ >
20
+ {children}
21
+ </button>
22
+ );
23
+ }
@@ -0,0 +1,27 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ButtonHtmlType } from '../button.enums';
5
+ import { ButtonVariantProps } from './buttonVariants.types';
6
+ import cx from 'classnames';
7
+
8
+ export function ButtonUnstyled({
9
+ htmlType = ButtonHtmlType.Button,
10
+ children,
11
+ className,
12
+ tabIndex = 0,
13
+ testId,
14
+ ...buttonProps
15
+ }: ButtonVariantProps): React.JSX.Element {
16
+ return (
17
+ <button
18
+ type={htmlType}
19
+ {...buttonProps}
20
+ className={cx('appearance-none', className)}
21
+ tabIndex={tabIndex}
22
+ data-testid={testId}
23
+ >
24
+ {children}
25
+ </button>
26
+ );
27
+ }
@@ -0,0 +1,11 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ButtonProps } from '../Button';
5
+
6
+ type ButtonPickedProps = Pick<ButtonProps, 'htmlType' | 'testId'>;
7
+ type PropsFromButtonElement = Omit<React.HTMLProps<HTMLButtonElement>, 'type'>;
8
+
9
+ export interface ButtonVariantProps extends ButtonPickedProps, PropsFromButtonElement {
10
+ children: React.ReactNode;
11
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './ButtonPill';
5
+ export * from './ButtonUnstyled';
@@ -0,0 +1,53 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ButtonSize, ButtonType } from './button.enums';
5
+
6
+ export const PADDINGS: Record<ButtonSize, string> = {
7
+ [ButtonSize.Small]: 'px-md py-xs',
8
+ [ButtonSize.Medium]: 'px-md py-sm',
9
+ };
10
+
11
+ export const PADDINGS_ONLY_ICON: Record<ButtonSize, string> = {
12
+ [ButtonSize.Small]: 'p-xs',
13
+ [ButtonSize.Medium]: 'p-sm',
14
+ };
15
+
16
+ export const BACKGROUND_COLORS: Record<ButtonType, string> = {
17
+ [ButtonType.Primary]: 'bg-primary-30',
18
+ [ButtonType.Secondary]: 'bg-neutral-90 dark:bg-neutral-20',
19
+ [ButtonType.Ghost]: 'bg-transparent',
20
+ [ButtonType.Outlined]: 'bg-transparent border border-neutral-50',
21
+ [ButtonType.Destructive]: 'bg-error-90 dark:bg-error-20',
22
+ };
23
+
24
+ export const DISABLED_BACKGROUND_COLORS: Record<ButtonType, string> = {
25
+ [ButtonType.Primary]: 'bg-neutral-80 dark:bg-neutral-30',
26
+ [ButtonType.Secondary]: 'bg-neutral-90 dark:bg-neutral-20',
27
+ [ButtonType.Ghost]: 'bg-transparent',
28
+ [ButtonType.Outlined]: 'bg-transparent border border-neutral-50',
29
+ [ButtonType.Destructive]: 'bg-error-90 dark:bg-error-20',
30
+ };
31
+
32
+ const DEFAULT_TEXT_COLORS: string = 'text-neutral-10 dark:text-neutral-92';
33
+
34
+ export const TEXT_COLORS: Record<ButtonType, string> = {
35
+ [ButtonType.Primary]: 'text-primary-100',
36
+ [ButtonType.Secondary]: DEFAULT_TEXT_COLORS,
37
+ [ButtonType.Ghost]: DEFAULT_TEXT_COLORS,
38
+ [ButtonType.Outlined]: DEFAULT_TEXT_COLORS,
39
+ [ButtonType.Destructive]: 'text-error-20 dark:text-error-90',
40
+ };
41
+
42
+ export const TEXT_CLASSES: Record<ButtonSize, string> = {
43
+ [ButtonSize.Small]: 'text-label-md',
44
+ [ButtonSize.Medium]: 'text-label-lg',
45
+ };
46
+
47
+ export const TEXT_COLOR_DISABLED: Record<ButtonType, string> = {
48
+ [ButtonType.Primary]: DEFAULT_TEXT_COLORS,
49
+ [ButtonType.Secondary]: DEFAULT_TEXT_COLORS,
50
+ [ButtonType.Ghost]: DEFAULT_TEXT_COLORS,
51
+ [ButtonType.Outlined]: DEFAULT_TEXT_COLORS,
52
+ [ButtonType.Destructive]: 'text-error-20 dark:text-error-90',
53
+ };
@@ -0,0 +1,21 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export enum ButtonSize {
5
+ Small = 'small',
6
+ Medium = 'medium',
7
+ }
8
+
9
+ export enum ButtonType {
10
+ Primary = 'primary',
11
+ Secondary = 'secondary',
12
+ Ghost = 'ghost',
13
+ Outlined = 'outlined',
14
+ Destructive = 'destructive',
15
+ }
16
+
17
+ export enum ButtonHtmlType {
18
+ Button = 'button',
19
+ Submit = 'submit',
20
+ Reset = 'reset',
21
+ }
@@ -0,0 +1,7 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './Button';
5
+ export * from './button-variants';
6
+
7
+ export * from './button.enums';
@@ -0,0 +1,86 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ BACKGROUND_COLORS,
6
+ BACKGROUND_COLORS_SELECTED,
7
+ TEXT_COLORS,
8
+ TEXT_COLORS_SELECTED,
9
+ UNDERLINED,
10
+ UNDERLINED_SELECTED,
11
+ } from './buttonSegment.classes';
12
+ import cx from 'classnames';
13
+ import { ButtonSegmentType } from './buttonSegment.enums';
14
+ import { ButtonUnstyled } from '../button';
15
+
16
+ interface ButtonSegmentProps {
17
+ /**
18
+ * The label of the button.
19
+ */
20
+ label: string;
21
+ /**
22
+ The icon of the button
23
+ */
24
+ icon?: React.ReactNode;
25
+ /**
26
+ The selected flag of the button
27
+ */
28
+ selected?: boolean;
29
+ /**
30
+ * The button is disabled or not.
31
+ */
32
+ disabled?: boolean;
33
+ /**
34
+ * The onClick event of the button.
35
+ */
36
+ onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
37
+ /**
38
+ * The type of the button.
39
+ */
40
+ type?: ButtonSegmentType;
41
+ }
42
+
43
+ export function ButtonSegment({
44
+ icon,
45
+ label,
46
+ selected,
47
+ disabled,
48
+ onClick,
49
+ type = ButtonSegmentType.Rounded,
50
+ }: ButtonSegmentProps): React.JSX.Element {
51
+ const isUnderlined = type === ButtonSegmentType.Underlined;
52
+
53
+ const backgroundColors = selected
54
+ ? isUnderlined
55
+ ? 'bg-transparent'
56
+ : BACKGROUND_COLORS_SELECTED
57
+ : BACKGROUND_COLORS;
58
+
59
+ const underlined = isUnderlined ? (selected ? UNDERLINED_SELECTED : UNDERLINED) : '';
60
+ const textColors = selected ? TEXT_COLORS_SELECTED : TEXT_COLORS;
61
+ const padding = isUnderlined ? 'px-lg py-md' : 'px-sm py-[6px]';
62
+ const borderRadius = isUnderlined ? '' : 'rounded-full';
63
+ const textSize = isUnderlined ? 'text-title-md' : 'text-label-lg';
64
+ return (
65
+ <ButtonUnstyled
66
+ onClick={onClick}
67
+ className={cx(
68
+ 'enabled:state-layer relative flex items-center disabled:opacity-40',
69
+ backgroundColors,
70
+ textColors,
71
+ padding,
72
+ borderRadius,
73
+ underlined,
74
+ {
75
+ 'pl-xs': !!icon && !isUnderlined,
76
+ },
77
+ )}
78
+ disabled={disabled}
79
+ >
80
+ <div className={cx('flex flex-row items-center justify-center gap-2', textSize)}>
81
+ {icon && <span>{icon}</span>}
82
+ <span className="font-inter">{label}</span>
83
+ </div>
84
+ </ButtonUnstyled>
85
+ );
86
+ }
@@ -0,0 +1,45 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export const BACKGROUND_COLORS = 'bg-transparent';
5
+ export const BACKGROUND_COLORS_SELECTED = 'bg-primary-100 dark:bg-neutral-6';
6
+
7
+ const TEXT_COLOR = 'text-neutral-60 dark:text-neutral-40';
8
+ const TEXT_COLOR_HOVER = 'enabled:hover:text-neutral-40 enabled:dark:hover:text-neutral-60';
9
+ const TEXT_COLOR_FOCUSED = 'enabled:focused:text-neutral-40 enabled:dark:focused:text-neutral-60';
10
+
11
+ export const TEXT_COLORS = `${TEXT_COLOR} ${TEXT_COLOR_HOVER} ${TEXT_COLOR_FOCUSED}`;
12
+ export const TEXT_COLORS_SELECTED = 'text-neutral-10 dark:text-neutral-92';
13
+
14
+ export const UNDERLINED_SELECTED = `
15
+ relative
16
+ before:content-['']
17
+ border-b
18
+ border-shader-neutral-light-8
19
+ dark:border-shader-neutral-dark-8
20
+ before:block
21
+ before:w-full
22
+ before:border-b
23
+ before:absolute
24
+ before:bottom-[-0.8px]
25
+ before:left-0
26
+ enabled:before:w-[calc(100%-16px)]
27
+ enabled:before:left-2
28
+ enabled:before:border-primary-30
29
+ enabled:before:dark:border-primary-80`;
30
+
31
+ export const UNDERLINED = `
32
+ relative
33
+ before:content-['']
34
+ before:block
35
+ before:w-full
36
+ before:border-b
37
+ before:border-shader-neutral-light-8
38
+ before:dark:border-shader-neutral-dark-8
39
+ before:absolute
40
+ before:bottom-0
41
+ before:left-0
42
+ hover:before:w-[calc(100%-16px)]
43
+ hover:before:left-2
44
+ hover:before:border-neutral-70
45
+ hover:before:dark:border-neutral-40`;
@@ -0,0 +1,7 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export enum ButtonSegmentType {
5
+ Rounded = 'rounded',
6
+ Underlined = 'underlined',
7
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './ButtonSegment';
5
+ export * from './buttonSegment.enums';
@@ -0,0 +1,114 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { forwardRef, useEffect, useRef } from 'react';
5
+ import cx from 'classnames';
6
+ import { Dash, Checkmark } from '@iota/apps-ui-icons';
7
+
8
+ interface CheckboxProps {
9
+ /**
10
+ * The label of the checkbox.
11
+ */
12
+ label?: string | React.ReactNode;
13
+ /**
14
+ * The state of the checkbox.
15
+ */
16
+ isChecked?: boolean;
17
+ /**
18
+ * If true the checkbox will override the styles to show an indeterminate state.
19
+ */
20
+ isIndeterminate?: boolean;
21
+ /**
22
+ * Whether the label should be placed before the checkbox.
23
+ */
24
+ isLabelFirst?: boolean;
25
+ /**
26
+ * If true the checkbox will be disabled.
27
+ */
28
+ isDisabled?: boolean;
29
+ /**
30
+ * The callback to call when the checkbox is clicked.
31
+ */
32
+ onCheckedChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
33
+ /**
34
+ * The name of the checkbox.
35
+ */
36
+ name?: string;
37
+ }
38
+
39
+ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
40
+ (
41
+ {
42
+ isChecked,
43
+ isIndeterminate,
44
+ label,
45
+ isLabelFirst,
46
+ isDisabled,
47
+ onCheckedChange,
48
+ name,
49
+ }: CheckboxProps,
50
+ ref,
51
+ ) => {
52
+ const inputRef = useRef<HTMLInputElement | null>(null);
53
+
54
+ useEffect(() => {
55
+ if (inputRef.current) {
56
+ inputRef.current.indeterminate = isIndeterminate ?? false;
57
+ }
58
+ }, [isIndeterminate, inputRef]);
59
+
60
+ const CheckmarkIcon = isIndeterminate ? Dash : Checkmark;
61
+
62
+ function assignRefs(element: HTMLInputElement) {
63
+ if (ref) {
64
+ if (typeof ref === 'function') {
65
+ ref(element);
66
+ } else {
67
+ ref.current = element;
68
+ }
69
+ }
70
+ inputRef.current = element;
71
+ }
72
+
73
+ return (
74
+ <div
75
+ className={cx('group inline-flex', isLabelFirst ? 'flex-row-reverse' : 'flex-row', {
76
+ disabled: isDisabled,
77
+ 'gap-x-2': label,
78
+ })}
79
+ >
80
+ <input
81
+ id={name}
82
+ name={name}
83
+ type="checkbox"
84
+ className="peer hidden appearance-none"
85
+ checked={isChecked}
86
+ ref={assignRefs}
87
+ disabled={isDisabled}
88
+ onChange={(e) => {
89
+ onCheckedChange?.(e);
90
+ }}
91
+ />
92
+ <span
93
+ onClick={() => inputRef.current?.click()}
94
+ className="peer-enabled:state-layer relative inset-0 flex h-5 w-5 items-center justify-center rounded border border-neutral-80 text-neutral-40 group-[.disabled]:cursor-not-allowed peer-disabled:text-neutral-70 peer-disabled:text-opacity-40 peer-disabled:opacity-40 peer-[&:is(:checked,:indeterminate)]:border-primary-30 peer-[&:is(:checked,:indeterminate)]:bg-primary-30 peer-[&:is(:checked,:indeterminate)]:text-white peer-[&:not(:checked,:indeterminate)]:text-opacity-40 disabled:peer-[&:not(:checked,:indeterminate)]:border-neutral-70 dark:border-neutral-20 dark:text-neutral-60 dark:peer-disabled:text-neutral-30 dark:peer-disabled:text-opacity-40 dark:peer-disabled:peer-[&:not(:checked,:indeterminate)]:border-neutral-30 dark:peer-disabled:peer-[&:is(:checked,:indeterminate)]:bg-neutral-40 peer-disabled:[&:is(:checked,:indeterminate)]:border-neutral-60 peer-disabled:[&:is(:checked,:indeterminate)]:bg-neutral-60 dark:peer-disabled:[&:is(:checked,:indeterminate)]:border-neutral-40 [&_svg]:h-4 [&_svg]:w-4 peer-[&:not(:checked,:indeterminate)]:[&_svg]:hidden"
95
+ >
96
+ <CheckmarkIcon />
97
+ </span>
98
+
99
+ <LabelText label={label} name={name} />
100
+ </div>
101
+ );
102
+ },
103
+ );
104
+
105
+ function LabelText({ label, name }: Pick<CheckboxProps, 'label' | 'name'>) {
106
+ return (
107
+ <label
108
+ htmlFor={name}
109
+ className="text-label-lg text-neutral-40 group-[.disabled]:cursor-not-allowed group-[.disabled]:text-opacity-40 dark:text-neutral-60 group-[.disabled]:dark:text-opacity-40"
110
+ >
111
+ {label}
112
+ </label>
113
+ );
114
+ }
@@ -0,0 +1,4 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './Checkbox';