@node-core/ui-components 0.0.1 → 1.0.1-df203d0fe21ee5d80d258c60dc821e8ac0601ce4

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 (186) hide show
  1. package/Common/AlertBox/index.module.css +76 -0
  2. package/Common/AlertBox/index.stories.tsx +73 -0
  3. package/Common/AlertBox/index.tsx +24 -0
  4. package/Common/AvatarGroup/Avatar/index.module.css +40 -0
  5. package/Common/AvatarGroup/Avatar/index.stories.tsx +22 -0
  6. package/Common/AvatarGroup/Avatar/index.tsx +67 -0
  7. package/Common/AvatarGroup/Overlay/index.module.css +31 -0
  8. package/Common/AvatarGroup/Overlay/index.stories.tsx +33 -0
  9. package/Common/AvatarGroup/Overlay/index.tsx +37 -0
  10. package/Common/AvatarGroup/__tests__/index.test.jsx +55 -0
  11. package/Common/AvatarGroup/index.module.css +25 -0
  12. package/Common/AvatarGroup/index.stories.tsx +56 -0
  13. package/Common/AvatarGroup/index.tsx +87 -0
  14. package/Common/Badge/index.module.css +38 -0
  15. package/Common/Badge/index.stories.tsx +38 -0
  16. package/Common/Badge/index.tsx +35 -0
  17. package/Common/BadgeGroup/index.module.css +77 -0
  18. package/Common/BadgeGroup/index.stories.tsx +35 -0
  19. package/Common/BadgeGroup/index.tsx +35 -0
  20. package/Common/Banner/index.module.css +42 -0
  21. package/Common/Banner/index.stories.tsx +29 -0
  22. package/Common/Banner/index.tsx +18 -0
  23. package/Common/BaseActiveLink/__tests__/index.test.jsx +52 -0
  24. package/Common/BaseActiveLink/index.tsx +34 -0
  25. package/Common/BaseButton/index.module.css +142 -0
  26. package/Common/BaseButton/index.stories.tsx +67 -0
  27. package/Common/BaseButton/index.tsx +59 -0
  28. package/Common/BaseCodeBox/index.module.css +84 -0
  29. package/Common/BaseCodeBox/index.stories.tsx +39 -0
  30. package/Common/BaseCodeBox/index.tsx +133 -0
  31. package/Common/BaseCrossLink/index.module.css +51 -0
  32. package/Common/BaseCrossLink/index.stories.tsx +38 -0
  33. package/Common/BaseCrossLink/index.tsx +46 -0
  34. package/Common/BaseLinkTabs/index.module.css +43 -0
  35. package/Common/BaseLinkTabs/index.stories.tsx +34 -0
  36. package/Common/BaseLinkTabs/index.tsx +53 -0
  37. package/Common/BasePagination/Ellipsis/index.module.css +10 -0
  38. package/Common/BasePagination/Ellipsis/index.stories.tsx +10 -0
  39. package/Common/BasePagination/Ellipsis/index.tsx +11 -0
  40. package/Common/BasePagination/PaginationListItem/__tests__/index.test.jsx +58 -0
  41. package/Common/BasePagination/PaginationListItem/index.module.css +27 -0
  42. package/Common/BasePagination/PaginationListItem/index.stories.tsx +40 -0
  43. package/Common/BasePagination/PaginationListItem/index.tsx +39 -0
  44. package/Common/BasePagination/PrevNextArrow.tsx +15 -0
  45. package/Common/BasePagination/__tests__/index.test.jsx +180 -0
  46. package/Common/BasePagination/index.module.css +39 -0
  47. package/Common/BasePagination/index.stories.tsx +67 -0
  48. package/Common/BasePagination/index.tsx +77 -0
  49. package/Common/BasePagination/useGetPageElements.tsx +132 -0
  50. package/Common/Blockquote/index.module.css +29 -0
  51. package/Common/Blockquote/index.stories.tsx +45 -0
  52. package/Common/Blockquote/index.tsx +11 -0
  53. package/Common/Breadcrumbs/BreadcrumbHomeLink/index.module.css +5 -0
  54. package/Common/Breadcrumbs/BreadcrumbHomeLink/index.tsx +30 -0
  55. package/Common/Breadcrumbs/BreadcrumbItem/index.module.css +41 -0
  56. package/Common/Breadcrumbs/BreadcrumbItem/index.tsx +42 -0
  57. package/Common/Breadcrumbs/BreadcrumbLink/index.module.css +22 -0
  58. package/Common/Breadcrumbs/BreadcrumbLink/index.tsx +37 -0
  59. package/Common/Breadcrumbs/BreadcrumbRoot/index.module.css +9 -0
  60. package/Common/Breadcrumbs/BreadcrumbRoot/index.tsx +20 -0
  61. package/Common/Breadcrumbs/BreadcrumbTruncatedItem/index.tsx +9 -0
  62. package/Common/Breadcrumbs/index.stories.tsx +94 -0
  63. package/Common/Breadcrumbs/index.tsx +81 -0
  64. package/Common/CodeTabs/index.module.css +56 -0
  65. package/Common/CodeTabs/index.stories.tsx +74 -0
  66. package/Common/CodeTabs/index.tsx +16 -0
  67. package/Common/GlowingBackdrop/index.module.css +32 -0
  68. package/Common/GlowingBackdrop/index.stories.tsx +10 -0
  69. package/Common/GlowingBackdrop/index.tsx +13 -0
  70. package/Common/LanguageDropDown/index.module.css +53 -0
  71. package/Common/LanguageDropDown/index.stories.tsx +19 -0
  72. package/Common/LanguageDropDown/index.tsx +56 -0
  73. package/Common/Modal/index.module.css +79 -0
  74. package/Common/Modal/index.stories.tsx +32 -0
  75. package/Common/Modal/index.tsx +48 -0
  76. package/Common/NodejsLogo/index.module.css +6 -0
  77. package/Common/NodejsLogo/index.stories.tsx +14 -0
  78. package/Common/NodejsLogo/index.tsx +26 -0
  79. package/Common/Notification/index.module.css +20 -0
  80. package/Common/Notification/index.stories.tsx +36 -0
  81. package/Common/Notification/index.tsx +34 -0
  82. package/Common/Preview/index.module.css +79 -0
  83. package/Common/Preview/index.stories.tsx +44 -0
  84. package/Common/Preview/index.tsx +25 -0
  85. package/Common/ProgressionSidebar/ProgressionSidebarGroup/index.module.css +47 -0
  86. package/Common/ProgressionSidebar/ProgressionSidebarGroup/index.tsx +35 -0
  87. package/Common/ProgressionSidebar/ProgressionSidebarIcon/index.tsx +16 -0
  88. package/Common/ProgressionSidebar/ProgressionSidebarItem/index.module.css +39 -0
  89. package/Common/ProgressionSidebar/ProgressionSidebarItem/index.tsx +32 -0
  90. package/Common/ProgressionSidebar/index.module.css +30 -0
  91. package/Common/ProgressionSidebar/index.stories.tsx +79 -0
  92. package/Common/ProgressionSidebar/index.tsx +59 -0
  93. package/Common/Select/__tests__/index.test.jsx +67 -0
  94. package/Common/Select/index.module.css +161 -0
  95. package/Common/Select/index.stories.tsx +111 -0
  96. package/Common/Select/index.tsx +187 -0
  97. package/Common/Separator/index.module.css +16 -0
  98. package/Common/Separator/index.stories.tsx +32 -0
  99. package/Common/Separator/index.tsx +27 -0
  100. package/Common/Skeleton/index.module.css +30 -0
  101. package/Common/Skeleton/index.tsx +39 -0
  102. package/Common/Tabs/__tests__/index.test.jsx +52 -0
  103. package/Common/Tabs/index.module.css +54 -0
  104. package/Common/Tabs/index.stories.tsx +50 -0
  105. package/Common/Tabs/index.tsx +54 -0
  106. package/Common/ThemeToggle/__tests__/index.test.jsx +35 -0
  107. package/Common/ThemeToggle/index.module.css +15 -0
  108. package/Common/ThemeToggle/index.stories.tsx +10 -0
  109. package/Common/ThemeToggle/index.tsx +15 -0
  110. package/Common/Tooltip/index.module.css +43 -0
  111. package/Common/Tooltip/index.stories.tsx +73 -0
  112. package/Common/Tooltip/index.tsx +48 -0
  113. package/Containers/Article/index.module.css +70 -0
  114. package/Containers/Article/index.stories.tsx +39 -0
  115. package/Containers/Article/index.tsx +9 -0
  116. package/Containers/Footer/index.module.css +46 -0
  117. package/Containers/Footer/index.stories.tsx +27 -0
  118. package/Containers/Footer/index.tsx +95 -0
  119. package/Containers/MetaBar/__tests__/index.test.jsx +63 -0
  120. package/Containers/MetaBar/index.module.css +91 -0
  121. package/Containers/MetaBar/index.stories.tsx +80 -0
  122. package/Containers/MetaBar/index.tsx +72 -0
  123. package/Containers/NavBar/NavItem/index.module.css +60 -0
  124. package/Containers/NavBar/NavItem/index.stories.tsx +38 -0
  125. package/Containers/NavBar/NavItem/index.tsx +44 -0
  126. package/Containers/NavBar/index.module.css +125 -0
  127. package/Containers/NavBar/index.stories.tsx +45 -0
  128. package/Containers/NavBar/index.tsx +94 -0
  129. package/Containers/Sidebar/SidebarGroup/index.module.css +26 -0
  130. package/Containers/Sidebar/SidebarGroup/index.stories.tsx +36 -0
  131. package/Containers/Sidebar/SidebarGroup/index.tsx +30 -0
  132. package/Containers/Sidebar/SidebarItem/index.module.css +35 -0
  133. package/Containers/Sidebar/SidebarItem/index.stories.tsx +15 -0
  134. package/Containers/Sidebar/SidebarItem/index.tsx +26 -0
  135. package/Containers/Sidebar/index.module.css +31 -0
  136. package/Containers/Sidebar/index.stories.tsx +84 -0
  137. package/Containers/Sidebar/index.tsx +58 -0
  138. package/Icons/HexagonGrid.stories.tsx +10 -0
  139. package/Icons/HexagonGrid.tsx +1434 -0
  140. package/Icons/InstallationMethod/Choco.tsx +78 -0
  141. package/Icons/InstallationMethod/Devbox.tsx +21 -0
  142. package/Icons/InstallationMethod/Docker.tsx +20 -0
  143. package/Icons/InstallationMethod/FNM.tsx +132 -0
  144. package/Icons/InstallationMethod/Homebrew.tsx +69 -0
  145. package/Icons/InstallationMethod/N.tsx +32 -0
  146. package/Icons/InstallationMethod/NVM.tsx +63 -0
  147. package/Icons/InstallationMethod/Volta.tsx +34 -0
  148. package/Icons/InstallationMethod/index.ts +10 -0
  149. package/Icons/Logos/JsGreen.tsx +24 -0
  150. package/Icons/Logos/JsWhite.tsx +37 -0
  151. package/Icons/Logos/Nodejs.tsx +188 -0
  152. package/Icons/Logos/NodejsStackedBlack.tsx +98 -0
  153. package/Icons/Logos/NodejsStackedDark.tsx +124 -0
  154. package/Icons/Logos/NodejsStackedLight.tsx +123 -0
  155. package/Icons/Logos/NodejsStackedWhite.tsx +98 -0
  156. package/Icons/Logos/index.ts +17 -0
  157. package/Icons/OperatingSystem/AIX.tsx +46 -0
  158. package/Icons/OperatingSystem/Apple.tsx +23 -0
  159. package/Icons/OperatingSystem/Linux.tsx +969 -0
  160. package/Icons/OperatingSystem/Microsoft.tsx +19 -0
  161. package/Icons/OperatingSystem/index.ts +6 -0
  162. package/Icons/PackageManager/Npm.tsx +21 -0
  163. package/Icons/PackageManager/Pnpm.tsx +22 -0
  164. package/Icons/PackageManager/Yarn.tsx +22 -0
  165. package/Icons/PackageManager/index.ts +5 -0
  166. package/Icons/Social/Bluesky.tsx +19 -0
  167. package/Icons/Social/Discord.tsx +20 -0
  168. package/Icons/Social/GitHub.tsx +16 -0
  169. package/Icons/Social/LinkedIn.tsx +16 -0
  170. package/Icons/Social/Mastodon.tsx +36 -0
  171. package/Icons/Social/Slack.tsx +31 -0
  172. package/Icons/Social/X.tsx +16 -0
  173. package/Icons/Social/index.ts +9 -0
  174. package/LICENSE +21 -0
  175. package/package.json +89 -5
  176. package/stylelint/__tests__/index.test.mjs +80 -0
  177. package/stylelint/one-utility-class-per-line.mjs +64 -0
  178. package/stylelint/utils.mjs +53 -0
  179. package/styles/animations.css +47 -0
  180. package/styles/base.css +17 -0
  181. package/styles/effects.css +12 -0
  182. package/styles/index.css +38 -0
  183. package/styles/markdown.css +173 -0
  184. package/styles/theme.css +175 -0
  185. package/types.ts +25 -0
  186. package/README.md +0 -1
@@ -0,0 +1,79 @@
1
+ import type { Meta as MetaObj, StoryObj } from '@storybook/react';
2
+
3
+ import ProgressionSidebar from '#ui/Common/ProgressionSidebar';
4
+
5
+ type Story = StoryObj<typeof ProgressionSidebar>;
6
+ type Meta = MetaObj<typeof ProgressionSidebar>;
7
+
8
+ export const Default: Story = {
9
+ args: {
10
+ groups: [
11
+ {
12
+ groupName: 'Getting Started',
13
+ items: [
14
+ {
15
+ label: 'Introduction to Node.js',
16
+ link: '/',
17
+ },
18
+ {
19
+ label: 'How to install Node.js',
20
+ link: '/how-to-install-nodejs',
21
+ },
22
+ {
23
+ label: 'How much JavaScript do you need to know to use Node.js?',
24
+ link: '/how-much-javascript-do-you-need-to-know-to-use-nodejs',
25
+ },
26
+ {
27
+ label: 'Differences between Node.js and the Browser',
28
+ link: '/differences-between-nodejs-and-the-browser',
29
+ },
30
+ {
31
+ label: 'The V8 JavaScript Engine',
32
+ link: '/the-v8-javascript-engine',
33
+ },
34
+ {
35
+ label: 'An introduction to the npm package manager',
36
+ link: '/an-introduction-to-the-npm-package-manager',
37
+ },
38
+ ],
39
+ },
40
+ {
41
+ groupName: 'Asynchronous Work',
42
+ items: [
43
+ {
44
+ label: 'Asynchronous flow control',
45
+ link: '/asynchronous-flow-control',
46
+ },
47
+ {
48
+ label: 'Overview of Blocking vs Non-Blocking',
49
+ link: '/overview-of-blocking-vs-non-blocking',
50
+ },
51
+ ],
52
+ },
53
+ {
54
+ groupName: 'Manipulating Files',
55
+ items: [
56
+ {
57
+ label: 'Node.js file stats',
58
+ link: '/nodejs-file-stats',
59
+ },
60
+ {
61
+ label: 'Node.js File Paths',
62
+ link: '/nodejs-file-paths',
63
+ },
64
+ ],
65
+ },
66
+ {
67
+ groupName: 'Single item',
68
+ items: [
69
+ {
70
+ label: 'Item',
71
+ link: '/item',
72
+ },
73
+ ],
74
+ },
75
+ ],
76
+ },
77
+ };
78
+
79
+ export default { component: ProgressionSidebar } as Meta;
@@ -0,0 +1,59 @@
1
+ 'use client';
2
+
3
+ import { useRef, type ComponentProps, type FC } from 'react';
4
+
5
+ import ProgressionSidebarGroup from '#ui/Common/ProgressionSidebar/ProgressionSidebarGroup';
6
+ import Select from '#ui/Common/Select';
7
+ import type { LinkLike } from '#ui/types';
8
+
9
+ import styles from './index.module.css';
10
+
11
+ type ProgressionSidebarProps = {
12
+ groups: Array<ComponentProps<typeof ProgressionSidebarGroup>>;
13
+ pathname?: string;
14
+ title: string;
15
+ onSelect: (value: string) => void;
16
+ as?: LinkLike;
17
+ };
18
+
19
+ const ProgressionSidebar: FC<ProgressionSidebarProps> = ({
20
+ groups,
21
+ pathname,
22
+ title,
23
+ onSelect,
24
+ as,
25
+ }) => {
26
+ const ref = useRef<HTMLElement>(null);
27
+ const selectItems = groups.map(({ items, groupName }) => ({
28
+ label: groupName,
29
+ items: items.map(({ label, link }) => ({ value: link, label })),
30
+ }));
31
+
32
+ const currentItem = selectItems
33
+ .map(item => item.items)
34
+ .flat()
35
+ .find(item => pathname === item.value);
36
+
37
+ return (
38
+ <nav className={styles.wrapper} ref={ref}>
39
+ <Select
40
+ label={title}
41
+ onChange={onSelect}
42
+ values={selectItems}
43
+ defaultValue={currentItem?.value}
44
+ />
45
+
46
+ {groups.map(({ groupName, items }) => (
47
+ <ProgressionSidebarGroup
48
+ key={groupName.toString()}
49
+ groupName={groupName}
50
+ items={items}
51
+ as={as}
52
+ pathname={pathname}
53
+ />
54
+ ))}
55
+ </nav>
56
+ );
57
+ };
58
+
59
+ export default ProgressionSidebar;
@@ -0,0 +1,67 @@
1
+ import { render } from '@testing-library/react';
2
+ import { describe, it } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import Select from '..';
5
+
6
+ const noop = () => {};
7
+
8
+ describe('Select', () => {
9
+ const values = ['Option 1', 'Option 2', 'Option 3'];
10
+ const defaultValue = 'Option 1';
11
+ const placeholder = 'Select an option';
12
+ const dropdownLabel = 'Dropdown label';
13
+ const label = 'Option label';
14
+
15
+ global.ResizeObserver = class {
16
+ observe = noop;
17
+ unobserve = noop;
18
+ disconnect = noop;
19
+ };
20
+
21
+ it('renders the label when provided', () => {
22
+ const { getByLabelText } = render(
23
+ <Select
24
+ values={values}
25
+ defaultValue={defaultValue}
26
+ placeholder={placeholder}
27
+ dropdownLabel={dropdownLabel}
28
+ label={label}
29
+ onChange={noop}
30
+ />
31
+ );
32
+
33
+ const element = getByLabelText(label);
34
+ assert.ok(element.ownerDocument);
35
+ });
36
+
37
+ it('renders the default value when provided', () => {
38
+ const { getByText } = render(
39
+ <Select
40
+ values={values}
41
+ defaultValue={defaultValue}
42
+ placeholder={placeholder}
43
+ dropdownLabel={dropdownLabel}
44
+ label={label}
45
+ onChange={noop}
46
+ />
47
+ );
48
+
49
+ const element = getByText(defaultValue);
50
+ assert.ok(element.ownerDocument);
51
+ });
52
+
53
+ it('renders the placeholder when default value is not provided', () => {
54
+ const { getByText } = render(
55
+ <Select
56
+ values={values}
57
+ placeholder={placeholder}
58
+ dropdownLabel={dropdownLabel}
59
+ label={label}
60
+ onChange={noop}
61
+ />
62
+ );
63
+
64
+ const element = getByText(placeholder);
65
+ assert.ok(element.ownerDocument);
66
+ });
67
+ });
@@ -0,0 +1,161 @@
1
+ @reference "../../styles/index.css";
2
+
3
+ .select {
4
+ @apply inline-flex
5
+ flex-col
6
+ gap-1.5;
7
+
8
+ .label {
9
+ @apply block
10
+ w-full
11
+ text-sm
12
+ font-medium
13
+ text-neutral-800
14
+ dark:text-neutral-200;
15
+ }
16
+
17
+ .trigger {
18
+ @apply shadow-xs
19
+ outline-hidden
20
+ inline-flex
21
+ h-11
22
+ w-full
23
+ min-w-[17rem]
24
+ items-center
25
+ justify-between
26
+ gap-2
27
+ rounded-sm
28
+ border
29
+ border-neutral-300
30
+ bg-white
31
+ px-3.5
32
+ py-2.5
33
+ text-left
34
+ text-base
35
+ font-medium
36
+ text-neutral-900
37
+ focus:border-neutral-500
38
+ focus:ring-1
39
+ focus:ring-neutral-500
40
+ data-[placeholder]:text-neutral-800
41
+ dark:border-neutral-800
42
+ dark:bg-neutral-950
43
+ dark:text-white
44
+ dark:focus:border-neutral-600
45
+ dark:focus:ring-neutral-600
46
+ dark:data-[placeholder]:text-neutral-200;
47
+ }
48
+
49
+ .trigger span {
50
+ @apply flex
51
+ h-5
52
+ items-center
53
+ gap-2;
54
+ }
55
+
56
+ .icon {
57
+ @apply size-5
58
+ text-neutral-600
59
+ dark:text-neutral-400;
60
+ }
61
+ }
62
+
63
+ .dropdown {
64
+ @apply max-h-48
65
+ max-w-xs
66
+ overflow-hidden
67
+ overflow-y-auto
68
+ rounded-md
69
+ border
70
+ border-neutral-200
71
+ bg-white
72
+ shadow-lg
73
+ dark:border-neutral-800
74
+ dark:bg-neutral-950;
75
+
76
+ .item {
77
+ @apply select-none
78
+ truncate
79
+ px-2.5
80
+ py-1.5
81
+ text-sm
82
+ font-medium;
83
+ }
84
+
85
+ .text {
86
+ @apply data-[highlighted]:outline-hidden
87
+ text-neutral-800
88
+ data-[highlighted]:bg-green-500
89
+ data-[highlighted]:text-white
90
+ dark:text-neutral-200
91
+ dark:data-[highlighted]:bg-green-600
92
+ dark:data-[highlighted]:text-white;
93
+ }
94
+
95
+ .text > span {
96
+ @apply flex
97
+ items-center
98
+ gap-2;
99
+ }
100
+
101
+ .text > span > span {
102
+ @apply max-w-64
103
+ truncate
104
+ text-wrap;
105
+ }
106
+
107
+ .label {
108
+ @apply text-neutral-600
109
+ dark:text-neutral-400;
110
+ }
111
+ }
112
+
113
+ .dropdown:has(.label) .text > span {
114
+ &:has(svg) > svg {
115
+ @apply ml-3;
116
+ }
117
+
118
+ &:not(&:has(svg)) > span {
119
+ @apply ml-3;
120
+ }
121
+ }
122
+
123
+ .inline {
124
+ .trigger {
125
+ @apply h-auto
126
+ min-w-fit
127
+ px-2.5
128
+ py-2
129
+ text-sm
130
+ font-medium;
131
+ }
132
+
133
+ .icon {
134
+ @apply size-4;
135
+ }
136
+
137
+ .text {
138
+ @apply text-neutral-900
139
+ data-[highlighted]:bg-neutral-100
140
+ data-[disabled]:text-neutral-600
141
+ data-[highlighted]:text-neutral-900
142
+ dark:text-white
143
+ dark:data-[highlighted]:bg-neutral-900
144
+ dark:data-[disabled]:text-neutral-700
145
+ dark:data-[highlighted]:text-white;
146
+ }
147
+
148
+ &.dropdown {
149
+ @apply mt-1
150
+ w-[calc(100%+1.5rem)]
151
+ rounded;
152
+ }
153
+ }
154
+
155
+ .scrollIcon {
156
+ @apply mx-auto
157
+ my-1
158
+ size-4
159
+ text-neutral-700
160
+ dark:text-neutral-200;
161
+ }
@@ -0,0 +1,111 @@
1
+ import type { Meta as MetaObj, StoryObj } from '@storybook/react';
2
+
3
+ import Select from '#ui/Common/Select';
4
+ import * as OSIcons from '#ui/Icons/OperatingSystem';
5
+
6
+ type Story = StoryObj<typeof Select>;
7
+ type Meta = MetaObj<typeof Select>;
8
+
9
+ export const Default: Story = {
10
+ args: {
11
+ values: ['v20.8.0', 'v19.9.0', 'v18.18.0', 'v17.9.1', 'v16.20.2'],
12
+ defaultValue: 'v16.20.2',
13
+ label: 'Node.js version',
14
+ },
15
+ };
16
+
17
+ export const WithoutLabel: Story = {
18
+ args: {
19
+ values: ['v20.8.0', 'v19.9.0', 'v18.18.0', 'v17.9.1', 'v16.20.2'],
20
+ defaultValue: 'v16.20.2',
21
+ },
22
+ };
23
+
24
+ export const WithScrollButtons: Story = {
25
+ args: {
26
+ values: Array.from({ length: 100 }, (_, i) => `Item ${i}`),
27
+ defaultValue: 'Item 50',
28
+ },
29
+ };
30
+
31
+ export const DropdownLabel: Story = {
32
+ args: {
33
+ values: [
34
+ {
35
+ label: 'Getting Started',
36
+ items: [
37
+ {
38
+ value: 'section-1',
39
+ label: 'Getting Started',
40
+ },
41
+ {
42
+ value: 'section-2',
43
+ label: 'How to install Node.js',
44
+ },
45
+ {
46
+ value: 'section-3',
47
+ label: 'How much JavaScript do you need to know to use Node.js?',
48
+ },
49
+ {
50
+ value: 'section-4',
51
+ label: 'Differences between Node.js and the Browser',
52
+ },
53
+ {
54
+ value: 'section-5',
55
+ label: 'The V8 JavaScript Engine',
56
+ },
57
+ {
58
+ value: 'section-6',
59
+ label: 'An introduction to the npm package manager',
60
+ },
61
+ {
62
+ value: 'section-7',
63
+ label: 'ECMAScript 2015 (ES6) and beyond',
64
+ },
65
+ {
66
+ value: 'section-8',
67
+ label: 'Node.js, the difference between development and production',
68
+ },
69
+ ],
70
+ },
71
+ ],
72
+ placeholder: 'Select a guide',
73
+ label: 'Getting Started',
74
+ },
75
+ };
76
+
77
+ export const InlineSelect: Story = {
78
+ args: {
79
+ values: [
80
+ {
81
+ label: 'Platform',
82
+ items: [
83
+ {
84
+ value: 'linux',
85
+ label: 'Linux',
86
+ iconImage: <OSIcons.Linux width={16} height={16} />,
87
+ },
88
+ {
89
+ value: 'macos',
90
+ label: 'macOS',
91
+ iconImage: <OSIcons.Apple width={16} height={16} />,
92
+ },
93
+ {
94
+ value: 'windows',
95
+ label: 'Windows',
96
+ iconImage: <OSIcons.Microsoft width={16} height={16} />,
97
+ },
98
+ {
99
+ value: 'aix',
100
+ label: 'AIX',
101
+ iconImage: <OSIcons.AIX width={16} height={16} />,
102
+ },
103
+ ],
104
+ },
105
+ ],
106
+ defaultValue: 'macos',
107
+ inline: true,
108
+ },
109
+ };
110
+
111
+ export default { component: Select } as Meta;
@@ -0,0 +1,187 @@
1
+ 'use client';
2
+
3
+ import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline';
4
+ import * as SelectPrimitive from '@radix-ui/react-select';
5
+ import classNames from 'classnames';
6
+ import { useEffect, useId, useMemo, useState } from 'react';
7
+ import type { ReactElement, ReactNode } from 'react';
8
+
9
+ import Skeleton from '#ui/Common/Skeleton';
10
+ import type { FormattedMessage } from '#ui/types';
11
+
12
+ import styles from './index.module.css';
13
+
14
+ export type SelectValue<T extends string> = {
15
+ label: FormattedMessage | string;
16
+ value: T;
17
+ iconImage?: ReactElement<SVGSVGElement>;
18
+ disabled?: boolean;
19
+ };
20
+
21
+ export type SelectGroup<T extends string> = {
22
+ label?: FormattedMessage | string;
23
+ items: Array<SelectValue<T>>;
24
+ };
25
+
26
+ const isStringArray = (values: Array<unknown>): values is Array<string> =>
27
+ Boolean(values[0] && typeof values[0] === 'string');
28
+
29
+ const isValuesArray = <T extends string>(
30
+ values: Array<unknown>
31
+ ): values is Array<SelectValue<T>> =>
32
+ Boolean(values[0] && typeof values[0] === 'object' && 'value' in values[0]);
33
+
34
+ type SelectProps<T extends string> = {
35
+ values: Array<SelectGroup<T>> | Array<T> | Array<SelectValue<T>>;
36
+ defaultValue?: T;
37
+ placeholder?: string;
38
+ label?: string;
39
+ inline?: boolean;
40
+ onChange?: (value: T) => void;
41
+ className?: string;
42
+ ariaLabel?: string;
43
+ loading?: boolean;
44
+ disabled?: boolean;
45
+ };
46
+
47
+ const Select = <T extends string>({
48
+ values = [],
49
+ defaultValue,
50
+ placeholder,
51
+ label,
52
+ inline,
53
+ onChange,
54
+ className,
55
+ ariaLabel,
56
+ loading = false,
57
+ disabled = false,
58
+ }: SelectProps<T>): ReactNode => {
59
+ const id = useId();
60
+ const [value, setValue] = useState(defaultValue);
61
+
62
+ useEffect(() => setValue(defaultValue), [defaultValue]);
63
+
64
+ const mappedValues = useMemo(() => {
65
+ let mappedValues = values;
66
+
67
+ if (isStringArray(mappedValues)) {
68
+ mappedValues = mappedValues.map(value => ({ label: value, value }));
69
+ }
70
+
71
+ if (isValuesArray(mappedValues)) {
72
+ return [{ items: mappedValues }];
73
+ }
74
+
75
+ return mappedValues as Array<SelectGroup<T>>;
76
+ }, [values]);
77
+
78
+ // We render the actual item slotted to fix/prevent the issue
79
+ // of the tirgger flashing on the initial render
80
+ const currentItem = useMemo(
81
+ () =>
82
+ mappedValues
83
+ .flatMap(({ items }) => items)
84
+ .find(item => item.value === value),
85
+ [mappedValues, value]
86
+ );
87
+
88
+ const memoizedMappedValues = useMemo(() => {
89
+ return mappedValues.map(({ label, items }, key) => (
90
+ <SelectPrimitive.Group key={label?.toString() ?? key}>
91
+ {label && (
92
+ <SelectPrimitive.Label
93
+ className={classNames(styles.item, styles.label)}
94
+ >
95
+ {label}
96
+ </SelectPrimitive.Label>
97
+ )}
98
+
99
+ {items.map(({ value, label, iconImage, disabled }) => (
100
+ <SelectPrimitive.Item
101
+ key={value}
102
+ value={value}
103
+ disabled={disabled}
104
+ className={classNames(styles.item, styles.text)}
105
+ >
106
+ <SelectPrimitive.ItemText>
107
+ {iconImage}
108
+ <span>{label}</span>
109
+ </SelectPrimitive.ItemText>
110
+ </SelectPrimitive.Item>
111
+ ))}
112
+ </SelectPrimitive.Group>
113
+ ));
114
+ // We explicitly want to recalculate these values only when the values themselves changed
115
+ // This is to prevent re-rendering and re-calcukating the values on every render
116
+ }, [JSON.stringify(values)]);
117
+
118
+ // Both change the internal state and emit the change event
119
+ const handleChange = (value: T) => {
120
+ setValue(value);
121
+
122
+ if (typeof onChange === 'function') {
123
+ onChange(value);
124
+ }
125
+ };
126
+
127
+ return (
128
+ <Skeleton loading={loading}>
129
+ <span
130
+ className={classNames(
131
+ styles.select,
132
+ { [styles.inline]: inline },
133
+ className
134
+ )}
135
+ >
136
+ {label && (
137
+ <label className={styles.label} htmlFor={id}>
138
+ {label}
139
+ </label>
140
+ )}
141
+
142
+ <SelectPrimitive.Root
143
+ value={currentItem !== undefined ? value : undefined}
144
+ onValueChange={handleChange}
145
+ disabled={disabled}
146
+ >
147
+ <SelectPrimitive.Trigger
148
+ className={styles.trigger}
149
+ aria-label={ariaLabel}
150
+ id={id}
151
+ >
152
+ <SelectPrimitive.Value placeholder={placeholder}>
153
+ {currentItem !== undefined && (
154
+ <>
155
+ {currentItem.iconImage}
156
+ <span>{currentItem.label}</span>
157
+ </>
158
+ )}
159
+ </SelectPrimitive.Value>
160
+ <ChevronDownIcon className={styles.icon} />
161
+ </SelectPrimitive.Trigger>
162
+
163
+ <SelectPrimitive.Portal>
164
+ <SelectPrimitive.Content
165
+ position={inline ? 'popper' : 'item-aligned'}
166
+ className={classNames(styles.dropdown, {
167
+ [styles.inline]: inline,
168
+ })}
169
+ >
170
+ <SelectPrimitive.ScrollUpButton>
171
+ <ChevronUpIcon className={styles.scrollIcon} />
172
+ </SelectPrimitive.ScrollUpButton>
173
+ <SelectPrimitive.Viewport>
174
+ {memoizedMappedValues}
175
+ </SelectPrimitive.Viewport>
176
+ <SelectPrimitive.ScrollDownButton>
177
+ <ChevronDownIcon className={styles.scrollIcon} />
178
+ </SelectPrimitive.ScrollDownButton>
179
+ </SelectPrimitive.Content>
180
+ </SelectPrimitive.Portal>
181
+ </SelectPrimitive.Root>
182
+ </span>
183
+ </Skeleton>
184
+ );
185
+ };
186
+
187
+ export default Select;
@@ -0,0 +1,16 @@
1
+ @reference "../../styles/index.css";
2
+
3
+ .root {
4
+ @apply shrink-0
5
+ bg-neutral-800;
6
+
7
+ &.horizontal {
8
+ @apply h-px
9
+ w-full;
10
+ }
11
+
12
+ &.vertical {
13
+ @apply h-full
14
+ w-px;
15
+ }
16
+ }
@@ -0,0 +1,32 @@
1
+ import type { Meta as MetaObj, StoryObj } from '@storybook/react';
2
+
3
+ import Separator from '#ui/Common/Separator';
4
+
5
+ type Story = StoryObj<typeof Separator>;
6
+ type Meta = MetaObj<typeof Separator>;
7
+
8
+ export const Horizontal: Story = {
9
+ args: {
10
+ orientation: 'horizontal',
11
+ },
12
+ };
13
+
14
+ export const Vertical: Story = {
15
+ args: {
16
+ orientation: 'vertical',
17
+ },
18
+ };
19
+
20
+ export default {
21
+ component: Separator,
22
+ parameters: {
23
+ layout: 'centered',
24
+ },
25
+ decorators: [
26
+ Story => (
27
+ <div className="size-32">
28
+ <Story />
29
+ </div>
30
+ ),
31
+ ],
32
+ } as Meta;