@iota/apps-ui-kit 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/index.d.ts +1622 -0
  3. package/dist/index.es.js +8805 -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 +5 -2
  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 +14 -0
  37. package/src/lib/components/atoms/info-box/infoBox.enums.ts +12 -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 +14 -0
  62. package/src/lib/components/atoms/snackbar/snackbar.enums.tsx +7 -0
  63. package/src/lib/components/atoms/tooltip/Tooltip.tsx +34 -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 +93 -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 +78 -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 +189 -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 +126 -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 +111 -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 +122 -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 +127 -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 +136 -0
  148. package/src/lib/tailwind/base.presets.ts +47 -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/responsive.presets.ts +36 -0
  156. package/src/lib/tailwind/static.presets.ts +25 -0
  157. package/src/lib/tailwind/types.ts +6 -0
  158. package/src/lib/utils/format.ts +8 -0
  159. package/src/lib/utils/index.ts +4 -0
  160. package/src/storybook/blocks/Showcase.tsx +20 -0
  161. package/src/storybook/blocks/TypeSet.tsx +34 -0
  162. package/src/storybook/blocks/TypeSetItem.tsx +74 -0
  163. package/src/storybook/blocks/index.ts +6 -0
  164. package/src/storybook/constants/index.ts +5 -0
  165. package/src/storybook/constants/typeset.constants.ts +39 -0
  166. package/src/storybook/constants/variableSpacing.constants.ts +6 -0
  167. package/src/storybook/helpers/getFontSizeLabel.ts +15 -0
  168. package/src/storybook/helpers/index.ts +4 -0
  169. package/src/storybook/stories/atoms/Badge.stories.tsx +32 -0
  170. package/src/storybook/stories/atoms/Button.stories.tsx +45 -0
  171. package/src/storybook/stories/atoms/ButtonSegment.stories.tsx +45 -0
  172. package/src/storybook/stories/atoms/Checkbox.stories.tsx +34 -0
  173. package/src/storybook/stories/atoms/CustomScrollbar.stories.tsx +22 -0
  174. package/src/storybook/stories/atoms/Divider.stories.tsx +41 -0
  175. package/src/storybook/stories/atoms/Header.stories.tsx +58 -0
  176. package/src/storybook/stories/atoms/InfoBox.stories.tsx +67 -0
  177. package/src/storybook/stories/atoms/KeyValueInfo.stories.tsx +59 -0
  178. package/src/storybook/stories/atoms/LabelText.stories.tsx +55 -0
  179. package/src/storybook/stories/atoms/ListItem.stories.tsx +41 -0
  180. package/src/storybook/stories/atoms/LoadingIndicator.stories.tsx +32 -0
  181. package/src/storybook/stories/atoms/Panel.stories.tsx +36 -0
  182. package/src/storybook/stories/atoms/Placeholder.stories.tsx +33 -0
  183. package/src/storybook/stories/atoms/RadioButton.stories.tsx +51 -0
  184. package/src/storybook/stories/atoms/Skeleton.stories.tsx +33 -0
  185. package/src/storybook/stories/atoms/Snackbar.stories.tsx +42 -0
  186. package/src/storybook/stories/atoms/Tooltip.stories.tsx +57 -0
  187. package/src/storybook/stories/atoms/VisualAssetCard.stories.tsx +56 -0
  188. package/src/storybook/stories/components/VariableSpacingShowcase.tsx +46 -0
  189. package/src/storybook/stories/components/index.ts +4 -0
  190. package/src/storybook/stories/design-tokens/colors.stories.mdx +23 -0
  191. package/src/storybook/stories/design-tokens/icons.stories.mdx +17 -0
  192. package/src/storybook/stories/design-tokens/typeset.stories.mdx +15 -0
  193. package/src/storybook/stories/design-tokens/variable-spacing.stories.mdx +10 -0
  194. package/src/storybook/stories/molecules/Account.stories.tsx +69 -0
  195. package/src/storybook/stories/molecules/Address.stories.tsx +39 -0
  196. package/src/storybook/stories/molecules/Card.stories.tsx +115 -0
  197. package/src/storybook/stories/molecules/Chip.stories.tsx +122 -0
  198. package/src/storybook/stories/molecules/DisplayStats.stories.tsx +63 -0
  199. package/src/storybook/stories/molecules/Dropdown.stories.tsx +38 -0
  200. package/src/storybook/stories/molecules/Input.stories.tsx +161 -0
  201. package/src/storybook/stories/molecules/NavbarItem.stories.tsx +45 -0
  202. package/src/storybook/stories/molecules/Search.stories.tsx +100 -0
  203. package/src/storybook/stories/molecules/SegmentedButton.stories.tsx +107 -0
  204. package/src/storybook/stories/molecules/Select.stories.tsx +102 -0
  205. package/src/storybook/stories/molecules/TableCell.stories.tsx +46 -0
  206. package/src/storybook/stories/molecules/TableHeaderCell.stories.tsx +34 -0
  207. package/src/storybook/stories/molecules/TextArea.stories.tsx +80 -0
  208. package/src/storybook/stories/molecules/Title.stories.tsx +76 -0
  209. package/src/storybook/stories/organisms/Accordion.stories.tsx +70 -0
  210. package/src/storybook/stories/organisms/Dialog.stories.tsx +103 -0
  211. package/src/storybook/stories/organisms/Navbar.stories.tsx +77 -0
  212. package/src/storybook/stories/organisms/Table.stories.tsx +154 -0
@@ -0,0 +1,38 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Meta, StoryObj } from '@storybook/react';
5
+ import { Dropdown, ListItem } from '@/components';
6
+ import { ComponentProps } from 'react';
7
+
8
+ const meta = {
9
+ component: Dropdown,
10
+ tags: ['autodocs'],
11
+ render: (props) => {
12
+ return <Dropdown {...props} />;
13
+ },
14
+ } satisfies Meta<typeof Dropdown>;
15
+
16
+ export default meta;
17
+
18
+ type Story = StoryObj<typeof meta>;
19
+
20
+ export const Default: Story = {
21
+ args: {},
22
+ render: (args) => {
23
+ const options: ComponentProps<typeof ListItem>[] = new Array(5).fill(0).map((_, index) => ({
24
+ children: `Option ${index + 1}`,
25
+ onClick: () => {
26
+ alert(`Option ${index + 1} clicked`);
27
+ },
28
+ }));
29
+
30
+ return (
31
+ <Dropdown {...args}>
32
+ {options.map((option, index) => (
33
+ <ListItem key={index} {...option} hideBottomBorder />
34
+ ))}
35
+ </Dropdown>
36
+ );
37
+ },
38
+ };
@@ -0,0 +1,161 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Meta, StoryObj } from '@storybook/react';
5
+
6
+ import { Input, InputType } from '@/lib/components/molecules/input';
7
+ import { PlaceholderReplace } from '@iota/apps-ui-icons';
8
+ import { ComponentProps, useCallback, useEffect, useState } from 'react';
9
+ import { ButtonPill } from '@/lib/components/atoms/button';
10
+
11
+ type CustomStoryProps = {
12
+ withLeadingIcon?: boolean;
13
+ };
14
+
15
+ function InputStory({
16
+ withLeadingIcon,
17
+ value,
18
+ onClearInput,
19
+ type,
20
+ ...props
21
+ }: ComponentProps<typeof Input> & CustomStoryProps): JSX.Element {
22
+ const [inputValue, setInputValue] = useState(value ?? '');
23
+
24
+ useEffect(() => {
25
+ setInputValue(value ?? '');
26
+ }, [value]);
27
+
28
+ return (
29
+ <Input
30
+ {...props}
31
+ onChange={(e) => setInputValue(e.target.value)}
32
+ value={inputValue}
33
+ onClearInput={() => setInputValue('')}
34
+ leadingIcon={withLeadingIcon ? <PlaceholderReplace /> : undefined}
35
+ type={type}
36
+ />
37
+ );
38
+ }
39
+
40
+ const meta = {
41
+ component: Input,
42
+ tags: ['autodocs'],
43
+ } satisfies Meta<typeof Input>;
44
+
45
+ export default meta;
46
+
47
+ type Story = StoryObj<typeof meta>;
48
+
49
+ export const Default: Story = {
50
+ args: {
51
+ label: 'Label',
52
+ caption: 'Caption',
53
+ type: InputType.Text,
54
+ },
55
+ argTypes: {
56
+ amountCounter: {
57
+ control: {
58
+ type: 'text',
59
+ },
60
+ },
61
+ type: {
62
+ control: {
63
+ type: 'select',
64
+ options: Object.values(InputType),
65
+ },
66
+ },
67
+ onValueChange: {
68
+ control: {
69
+ type: 'none',
70
+ },
71
+ },
72
+ },
73
+ render: (props) => <InputStory {...props} />,
74
+ };
75
+
76
+ export const WithLeadingElement: Story = {
77
+ args: {
78
+ type: InputType.Text,
79
+ placeholder: 'Placeholder',
80
+ amountCounter: '10',
81
+ caption: 'Caption',
82
+ },
83
+ render: (props) => <InputStory {...props} withLeadingIcon />,
84
+ };
85
+
86
+ export const WithMaxTrailingButton: Story = {
87
+ args: {
88
+ type: InputType.Number,
89
+ placeholder: 'Send IOTAs',
90
+ amountCounter: 'Max 10 IOTA',
91
+ caption: 'Enter token amount',
92
+ supportingText: 'IOTA',
93
+ trailingElement: <PlaceholderReplace />,
94
+ },
95
+ render: ({ value, ...props }) => {
96
+ const [inputValue, setInputValue] = useState<string>('');
97
+ const [error, setError] = useState<string | undefined>();
98
+
99
+ function onMaxClick() {
100
+ setInputValue('10');
101
+ checkInputValidity(inputValue);
102
+ }
103
+
104
+ const onChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
105
+ setInputValue(e.target.value);
106
+ }, []);
107
+
108
+ function checkInputValidity(value: string) {
109
+ if (Number(value) < 0) {
110
+ setError('Value must be greater than 0');
111
+ } else if (Number(value) > 10) {
112
+ setError('Value must be less than 10');
113
+ } else {
114
+ setError(undefined);
115
+ }
116
+ }
117
+
118
+ useEffect(() => {
119
+ checkInputValidity(inputValue);
120
+ }, [inputValue]);
121
+
122
+ return (
123
+ <Input
124
+ {...props}
125
+ required
126
+ label="Send Tokens"
127
+ value={inputValue}
128
+ trailingElement={<ButtonPill onClick={onMaxClick}>Max</ButtonPill>}
129
+ errorMessage={error}
130
+ onChange={onChange}
131
+ onClearInput={() => setInputValue('')}
132
+ />
133
+ );
134
+ },
135
+ };
136
+
137
+ export const NumericFormatInput: Story = {
138
+ args: {
139
+ type: InputType.NumericFormat,
140
+ placeholder: 'Enter the IOTA Amount',
141
+ amountCounter: '10',
142
+ caption: 'Caption',
143
+ suffix: ' IOTA',
144
+ prefix: '~ ',
145
+ },
146
+ render: (props) => {
147
+ const [inputValue, setInputValue] = useState<string>('');
148
+
149
+ function onMaxClick() {
150
+ setInputValue('10');
151
+ }
152
+
153
+ return (
154
+ <InputStory
155
+ {...props}
156
+ value={inputValue}
157
+ trailingElement={<ButtonPill onClick={onMaxClick}>Max</ButtonPill>}
158
+ />
159
+ );
160
+ },
161
+ };
@@ -0,0 +1,45 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Meta, StoryObj } from '@storybook/react';
5
+ import { NavbarItem, NavbarItemType } from '@/components';
6
+ import { Home } from '@iota/apps-ui-icons';
7
+
8
+ const meta: Meta<typeof NavbarItem> = {
9
+ component: NavbarItem,
10
+ tags: ['autodocs'],
11
+ render: (props) => {
12
+ return <NavbarItem {...props} />;
13
+ },
14
+ } satisfies Meta<typeof NavbarItem>;
15
+
16
+ export default meta;
17
+
18
+ type Story = StoryObj<typeof meta>;
19
+
20
+ export const Default: Story = {
21
+ args: {
22
+ icon: <Home />,
23
+ },
24
+ argTypes: {
25
+ text: {
26
+ control: 'text',
27
+ },
28
+ icon: {
29
+ control: 'none',
30
+ },
31
+ hasBadge: {
32
+ control: 'boolean',
33
+ },
34
+ isSelected: {
35
+ control: 'boolean',
36
+ },
37
+ type: {
38
+ control: 'select',
39
+ options: Object.values(NavbarItemType),
40
+ },
41
+ isDisabled: {
42
+ control: 'boolean',
43
+ },
44
+ },
45
+ };
@@ -0,0 +1,100 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { useState } from 'react';
5
+ import type { Meta, StoryObj } from '@storybook/react';
6
+ import { ListItem, Search, SearchBarType, Suggestion } from '@/components';
7
+ import cx from 'classnames';
8
+
9
+ const meta: Meta<typeof Search> = {
10
+ component: Search,
11
+ tags: ['autodocs'],
12
+ render: (props) => {
13
+ const [searchValue, setSearchValue] = useState<string>('');
14
+ const [filteredSuggestions, setFilteredSuggestions] = useState<Suggestion[]>([]);
15
+
16
+ const handleSearchValueChange = (value: string) => {
17
+ setSearchValue(value);
18
+ const filtered =
19
+ props.suggestions?.filter((suggestion) =>
20
+ suggestion.label.toLowerCase().includes(value.toLowerCase()),
21
+ ) || [];
22
+ setFilteredSuggestions(filtered);
23
+ };
24
+
25
+ const handleSuggestionClick = (suggestion: Suggestion) => {
26
+ setSearchValue(suggestion.label);
27
+ setFilteredSuggestions([]);
28
+ };
29
+
30
+ return (
31
+ <div className="h-60">
32
+ <Search
33
+ {...props}
34
+ searchValue={searchValue}
35
+ suggestions={filteredSuggestions}
36
+ onSearchValueChange={handleSearchValueChange}
37
+ onSuggestionClick={handleSuggestionClick}
38
+ renderSuggestion={(suggestion) => (
39
+ <ListItem
40
+ key={suggestion.id}
41
+ showRightIcon={false}
42
+ onClick={() => handleSuggestionClick(suggestion)}
43
+ hideBottomBorder
44
+ >
45
+ <div
46
+ className={cx(
47
+ 'flex w-full flex-row items-center gap-xs',
48
+ suggestion.supportingText ? 'justify-between' : 'justify-start',
49
+ )}
50
+ >
51
+ <span className="text-body-lg text-neutral-10 dark:text-neutral-92">
52
+ {suggestion.label}
53
+ </span>
54
+ <span className="text-body-md text-neutral-40 dark:text-neutral-60">
55
+ {suggestion.supportingText}
56
+ </span>
57
+ </div>
58
+ </ListItem>
59
+ )}
60
+ />
61
+ </div>
62
+ );
63
+ },
64
+ };
65
+
66
+ export default meta;
67
+
68
+ type Story = StoryObj<typeof meta>;
69
+
70
+ export const Default: Story = {
71
+ args: {
72
+ suggestions: [
73
+ { id: '1', label: 'Dashboard', supportingText: 'Caption' },
74
+ { id: '2', label: 'Wallet' },
75
+ { id: '3', label: 'Explorer' },
76
+ { id: '4', label: 'SDK' },
77
+ ],
78
+ placeholder: 'Search for tooling apps',
79
+ },
80
+ argTypes: {
81
+ suggestions: {
82
+ control: 'object',
83
+ },
84
+ onSuggestionClick: {
85
+ action: 'suggestionClicked',
86
+ },
87
+ placeholder: {
88
+ control: 'text',
89
+ },
90
+ onSearchValueChange: {
91
+ action: 'searchValueChanged',
92
+ },
93
+ type: {
94
+ control: {
95
+ type: 'select',
96
+ options: Object.values(SearchBarType),
97
+ },
98
+ },
99
+ },
100
+ };
@@ -0,0 +1,107 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Meta, StoryObj } from '@storybook/react';
5
+
6
+ import {
7
+ ButtonSegment,
8
+ ButtonSegmentType,
9
+ SegmentedButton,
10
+ SegmentedButtonType,
11
+ } from '@/components';
12
+ import { ComponentProps, useState } from 'react';
13
+ import { PlaceholderReplace } from '@iota/apps-ui-icons';
14
+
15
+ const meta: Meta<typeof SegmentedButton> = {
16
+ component: SegmentedButton,
17
+ tags: ['autodocs'],
18
+ render: (props) => {
19
+ const [elements, setElements] = useState<ComponentProps<typeof ButtonSegment>[]>([
20
+ { label: 'Label 1', selected: true },
21
+ { label: 'Label 2', icon: <PlaceholderReplace /> },
22
+ { label: 'Label 3', disabled: true },
23
+ { label: 'Label 4' },
24
+ ]);
25
+
26
+ const handleElementClick = (clickedIndex: number) => {
27
+ const updatedElements = elements.map((element, index) => ({
28
+ ...element,
29
+ selected: index === clickedIndex,
30
+ }));
31
+ setElements(updatedElements);
32
+ };
33
+
34
+ return (
35
+ <div className="flex flex-col items-start">
36
+ <SegmentedButton type={props.type} shape={props.shape}>
37
+ {elements.map((element, index) => (
38
+ <ButtonSegment
39
+ key={element.label}
40
+ type={props.shape}
41
+ onClick={() => handleElementClick(index)}
42
+ {...element}
43
+ />
44
+ ))}
45
+ </SegmentedButton>
46
+ </div>
47
+ );
48
+ },
49
+ } satisfies Meta<typeof SegmentedButton>;
50
+
51
+ export default meta;
52
+
53
+ type Story = StoryObj<typeof meta>;
54
+
55
+ export const Default: Story = {
56
+ argTypes: {
57
+ type: {
58
+ control: {
59
+ type: 'select',
60
+ options: Object.values(SegmentedButtonType),
61
+ },
62
+ },
63
+ shape: {
64
+ control: {
65
+ type: 'select',
66
+ options: Object.values(ButtonSegmentType),
67
+ },
68
+ },
69
+ },
70
+ };
71
+
72
+ export const Underlined: Story = {
73
+ args: {
74
+ type: SegmentedButtonType.Transparent,
75
+ shape: ButtonSegmentType.Underlined,
76
+ },
77
+ render: (props) => {
78
+ const [elements, setElements] = useState<ComponentProps<typeof ButtonSegment>[]>([
79
+ { label: 'Label 1', selected: true, type: ButtonSegmentType.Underlined },
80
+ { label: 'Label 2', icon: <PlaceholderReplace />, type: ButtonSegmentType.Underlined },
81
+ { label: 'Label 3', type: ButtonSegmentType.Underlined },
82
+ { label: 'Label 4', disabled: true, type: ButtonSegmentType.Underlined },
83
+ ]);
84
+
85
+ const handleElementClick = (clickedIndex: number) => {
86
+ const updatedElements = elements.map((element, index) => ({
87
+ ...element,
88
+ selected: index === clickedIndex,
89
+ }));
90
+ setElements(updatedElements);
91
+ };
92
+
93
+ return (
94
+ <div className="flex flex-col items-start">
95
+ <SegmentedButton type={props.type} shape={props.shape}>
96
+ {elements.map((element, index) => (
97
+ <ButtonSegment
98
+ key={element.label}
99
+ onClick={() => handleElementClick(index)}
100
+ {...element}
101
+ />
102
+ ))}
103
+ </SegmentedButton>
104
+ </div>
105
+ );
106
+ },
107
+ };
@@ -0,0 +1,102 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Meta, StoryObj } from '@storybook/react';
5
+ import { Select, SelectOption } from '@/components/molecules/select/Select';
6
+ import { useState } from 'react';
7
+ import { IotaLogoMark, PlaceholderReplace } from '@iota/apps-ui-icons';
8
+
9
+ const meta: Meta<typeof Select> = {
10
+ component: Select,
11
+ tags: ['autodocs'],
12
+ } satisfies Meta<typeof Select>;
13
+
14
+ export default meta;
15
+
16
+ type Story = StoryObj<typeof meta>;
17
+
18
+ const dropdownOptions: SelectOption[] = ['Option 1', 'Option 2', 'Option 3', 'Invalid Option'];
19
+
20
+ export const Default: Story = {
21
+ args: {
22
+ label: 'Select Input',
23
+ supportingText: 'Info',
24
+ caption: 'Caption',
25
+ placeholder: 'Placeholder',
26
+ options: dropdownOptions,
27
+ },
28
+ argTypes: {
29
+ placeholder: {
30
+ control: {
31
+ type: 'text',
32
+ },
33
+ },
34
+ },
35
+ render: (args) => {
36
+ const [selected, setSelected] = useState('Option 1');
37
+ const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);
38
+
39
+ const onChange = (id: string) => {
40
+ if (id === 'Invalid Option') {
41
+ setErrorMessage('Invalid Option Selected');
42
+ } else {
43
+ setSelected(id);
44
+ setErrorMessage(undefined);
45
+ }
46
+ };
47
+
48
+ return (
49
+ <div className="h-60">
50
+ <Select
51
+ {...args}
52
+ value={selected}
53
+ onValueChange={onChange}
54
+ errorMessage={errorMessage}
55
+ />
56
+ </div>
57
+ );
58
+ },
59
+ };
60
+
61
+ export const CustomOptions: Story = {
62
+ args: {
63
+ label: 'Send Coins',
64
+ placeholder: 'Select a coin',
65
+ options: [],
66
+ },
67
+ render: ({ options, ...args }) => {
68
+ const [selected, setSelected] = useState('iota');
69
+
70
+ const customOptions: SelectOption[] = [
71
+ {
72
+ id: 'iota',
73
+ renderLabel: () => (
74
+ <div className="flex items-center gap-2">
75
+ <IotaLogoMark />
76
+ IOTA
77
+ </div>
78
+ ),
79
+ },
80
+ {
81
+ id: 'other coin',
82
+ renderLabel: () => (
83
+ <div className="flex items-center gap-2">
84
+ <PlaceholderReplace />
85
+ Other Coin
86
+ </div>
87
+ ),
88
+ },
89
+ ];
90
+
91
+ return (
92
+ <div className="h-60">
93
+ <Select
94
+ {...args}
95
+ value={selected}
96
+ onValueChange={setSelected}
97
+ options={customOptions}
98
+ />
99
+ </div>
100
+ );
101
+ },
102
+ };
@@ -0,0 +1,46 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Meta, StoryObj } from '@storybook/react';
5
+ import { TableCellBase, TableCellText } from '@/components';
6
+
7
+ const meta = {
8
+ component: TableCellText,
9
+ tags: ['autodocs'],
10
+ render: (props) => {
11
+ return (
12
+ <table>
13
+ <thead>
14
+ <tr>
15
+ <TableCellBase>
16
+ <Avatar />
17
+ </TableCellBase>
18
+ <TableCellBase>
19
+ <TableCellText>Mr. Crab</TableCellText>
20
+ </TableCellBase>
21
+ </tr>
22
+ </thead>
23
+ </table>
24
+ );
25
+ },
26
+ } satisfies Meta<typeof TableCellText>;
27
+
28
+ export default meta;
29
+
30
+ type Story = StoryObj<typeof meta>;
31
+
32
+ const Avatar = () => {
33
+ return (
34
+ <svg
35
+ xmlns="http://www.w3.org/2000/svg"
36
+ width="33"
37
+ height="32"
38
+ viewBox="0 0 33 32"
39
+ fill="none"
40
+ >
41
+ <circle cx="16.5" cy="16" r="16" className="fill-primary-40" />
42
+ </svg>
43
+ );
44
+ };
45
+
46
+ export const Default: Story = {};
@@ -0,0 +1,34 @@
1
+ // Copyright (c) 2024 IOTA Stiftung
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Meta, StoryObj } from '@storybook/react';
5
+ import { TableHeaderCell } from '@/components';
6
+
7
+ const meta = {
8
+ component: TableHeaderCell,
9
+ tags: ['autodocs'],
10
+ render: (props) => {
11
+ return (
12
+ <div className="w-56">
13
+ <table>
14
+ <thead>
15
+ <tr>
16
+ <TableHeaderCell {...props} />
17
+ </tr>
18
+ </thead>
19
+ </table>
20
+ </div>
21
+ );
22
+ },
23
+ } satisfies Meta<typeof TableHeaderCell>;
24
+
25
+ export default meta;
26
+
27
+ type Story = StoryObj<typeof meta>;
28
+
29
+ export const Default: Story = {
30
+ args: {
31
+ label: 'Label',
32
+ columnKey: '1',
33
+ },
34
+ };