tharaday 0.1.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 (247) hide show
  1. package/.gitignore +30 -0
  2. package/.prettierrc.json +10 -0
  3. package/.storybook/main.ts +8 -0
  4. package/.storybook/preview.ts +50 -0
  5. package/.versionrc.json +6 -0
  6. package/README.md +73 -0
  7. package/dist/components/Accordion/Accordion.d.ts +2 -0
  8. package/dist/components/Accordion/Accordion.stories.d.ts +14 -0
  9. package/dist/components/Accordion/Accordion.types.d.ts +18 -0
  10. package/dist/components/Avatar/Avatar.d.ts +2 -0
  11. package/dist/components/Avatar/Avatar.stories.d.ts +14 -0
  12. package/dist/components/Avatar/Avatar.types.d.ts +10 -0
  13. package/dist/components/Badge/Badge.d.ts +2 -0
  14. package/dist/components/Badge/Badge.stories.d.ts +33 -0
  15. package/dist/components/Badge/Badge.types.d.ts +9 -0
  16. package/dist/components/Box/Box.d.ts +2 -0
  17. package/dist/components/Box/Box.stories.d.ts +38 -0
  18. package/dist/components/Box/Box.types.d.ts +49 -0
  19. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +3 -0
  20. package/dist/components/Breadcrumbs/Breadcrumbs.stories.d.ts +13 -0
  21. package/dist/components/Breadcrumbs/Breadcrumbs.types.d.ts +11 -0
  22. package/dist/components/Button/Button.d.ts +2 -0
  23. package/dist/components/Button/Button.stories.d.ts +22 -0
  24. package/dist/components/Button/Button.types.d.ts +12 -0
  25. package/dist/components/Card/Card.d.ts +5 -0
  26. package/dist/components/Card/Card.stories.d.ts +27 -0
  27. package/dist/components/Card/Card.types.d.ts +15 -0
  28. package/dist/components/Checkbox/Checkbox.d.ts +2 -0
  29. package/dist/components/Checkbox/Checkbox.stories.d.ts +17 -0
  30. package/dist/components/Checkbox/Checkbox.types.d.ts +6 -0
  31. package/dist/components/Dropdown/Dropdown.d.ts +2 -0
  32. package/dist/components/Dropdown/Dropdown.stories.d.ts +12 -0
  33. package/dist/components/Dropdown/Dropdown.types.d.ts +24 -0
  34. package/dist/components/Header/Header.d.ts +2 -0
  35. package/dist/components/Header/Header.stories.d.ts +18 -0
  36. package/dist/components/Header/Header.types.d.ts +14 -0
  37. package/dist/components/Input/Input.d.ts +2 -0
  38. package/dist/components/Input/Input.stories.d.ts +29 -0
  39. package/dist/components/Input/Input.types.d.ts +8 -0
  40. package/dist/components/Loader/Loader.d.ts +2 -0
  41. package/dist/components/Loader/Loader.stories.d.ts +25 -0
  42. package/dist/components/Loader/Loader.types.d.ts +8 -0
  43. package/dist/components/Modal/Modal.d.ts +2 -0
  44. package/dist/components/Modal/Modal.stories.d.ts +22 -0
  45. package/dist/components/Modal/Modal.types.d.ts +12 -0
  46. package/dist/components/NavBar/NavBar.d.ts +6 -0
  47. package/dist/components/NavBar/NavBar.stories.d.ts +8 -0
  48. package/dist/components/NavBar/NavBar.types.d.ts +34 -0
  49. package/dist/components/Notification/Notification.d.ts +2 -0
  50. package/dist/components/Notification/Notification.stories.d.ts +26 -0
  51. package/dist/components/Notification/Notification.types.d.ts +8 -0
  52. package/dist/components/Pagination/Pagination.d.ts +2 -0
  53. package/dist/components/Pagination/Pagination.stories.d.ts +21 -0
  54. package/dist/components/Pagination/Pagination.types.d.ts +34 -0
  55. package/dist/components/ProgressBar/ProgressBar.d.ts +2 -0
  56. package/dist/components/ProgressBar/ProgressBar.stories.d.ts +32 -0
  57. package/dist/components/ProgressBar/ProgressBar.types.d.ts +12 -0
  58. package/dist/components/RadioButton/RadioButton.d.ts +2 -0
  59. package/dist/components/RadioButton/RadioButton.stories.d.ts +30 -0
  60. package/dist/components/RadioButton/RadioButton.types.d.ts +8 -0
  61. package/dist/components/Select/Select.d.ts +2 -0
  62. package/dist/components/Select/Select.stories.d.ts +29 -0
  63. package/dist/components/Select/Select.types.d.ts +15 -0
  64. package/dist/components/Skeleton/Skeleton.d.ts +2 -0
  65. package/dist/components/Skeleton/Skeleton.stories.d.ts +15 -0
  66. package/dist/components/Skeleton/Skeleton.types.d.ts +8 -0
  67. package/dist/components/Stepper/Step.d.ts +2 -0
  68. package/dist/components/Stepper/Step.types.d.ts +17 -0
  69. package/dist/components/Stepper/Stepper.d.ts +2 -0
  70. package/dist/components/Stepper/Stepper.stories.d.ts +15 -0
  71. package/dist/components/Stepper/Stepper.types.d.ts +13 -0
  72. package/dist/components/Stepper/stepper.utils.d.ts +3 -0
  73. package/dist/components/Switch/Switch.d.ts +2 -0
  74. package/dist/components/Switch/Switch.stories.d.ts +16 -0
  75. package/dist/components/Switch/Switch.types.d.ts +5 -0
  76. package/dist/components/Table/Table.d.ts +8 -0
  77. package/dist/components/Table/Table.stories.d.ts +27 -0
  78. package/dist/components/Table/Table.types.d.ts +17 -0
  79. package/dist/components/Tabs/Tabs.d.ts +2 -0
  80. package/dist/components/Tabs/Tabs.stories.d.ts +14 -0
  81. package/dist/components/Tabs/Tabs.types.d.ts +16 -0
  82. package/dist/components/Text/Text.d.ts +2 -0
  83. package/dist/components/Text/Text.stories.d.ts +35 -0
  84. package/dist/components/Text/Text.types.d.ts +21 -0
  85. package/dist/components/Textarea/Textarea.d.ts +2 -0
  86. package/dist/components/Textarea/Textarea.stories.d.ts +29 -0
  87. package/dist/components/Textarea/Textarea.types.d.ts +9 -0
  88. package/dist/components/Tooltip/Tooltip.d.ts +2 -0
  89. package/dist/components/Tooltip/Tooltip.stories.d.ts +10 -0
  90. package/dist/components/Tooltip/Tooltip.types.d.ts +12 -0
  91. package/dist/ds.css +1 -0
  92. package/dist/ds.js +1930 -0
  93. package/dist/ds.umd.cjs +1 -0
  94. package/dist/index.d.ts +63 -0
  95. package/dist/layouts/AppLayout/AppLayout.d.ts +8 -0
  96. package/dist/layouts/AppLayout/AppLayout.stories.d.ts +19 -0
  97. package/dist/layouts/AppLayout/AppLayout.types.d.ts +50 -0
  98. package/dist/layouts/AuthLayout/AuthLayout.d.ts +2 -0
  99. package/dist/layouts/AuthLayout/AuthLayout.stories.d.ts +12 -0
  100. package/dist/layouts/AuthLayout/AuthLayout.types.d.ts +7 -0
  101. package/dist/layouts/DashboardLayout/DashboardLayout.d.ts +2 -0
  102. package/dist/layouts/DashboardLayout/DashboardLayout.stories.d.ts +17 -0
  103. package/dist/layouts/DashboardLayout/DashboardLayout.types.d.ts +15 -0
  104. package/dist/layouts/SettingsLayout/SettingsLayout.d.ts +2 -0
  105. package/dist/layouts/SettingsLayout/SettingsLayout.stories.d.ts +17 -0
  106. package/dist/layouts/SettingsLayout/SettingsLayout.types.d.ts +14 -0
  107. package/eslint.config.js +45 -0
  108. package/package.json +100 -0
  109. package/src/components/Accordion/Accordion.module.css +158 -0
  110. package/src/components/Accordion/Accordion.stories.tsx +133 -0
  111. package/src/components/Accordion/Accordion.tsx +68 -0
  112. package/src/components/Accordion/Accordion.types.ts +21 -0
  113. package/src/components/Avatar/Avatar.module.css +58 -0
  114. package/src/components/Avatar/Avatar.stories.tsx +41 -0
  115. package/src/components/Avatar/Avatar.tsx +64 -0
  116. package/src/components/Avatar/Avatar.types.ts +12 -0
  117. package/src/components/Badge/Badge.module.css +98 -0
  118. package/src/components/Badge/Badge.stories.tsx +108 -0
  119. package/src/components/Badge/Badge.tsx +22 -0
  120. package/src/components/Badge/Badge.types.ts +11 -0
  121. package/src/components/Box/Box.module.css +638 -0
  122. package/src/components/Box/Box.stories.tsx +109 -0
  123. package/src/components/Box/Box.tsx +95 -0
  124. package/src/components/Box/Box.types.ts +65 -0
  125. package/src/components/Breadcrumbs/Breadcrumbs.module.css +41 -0
  126. package/src/components/Breadcrumbs/Breadcrumbs.stories.tsx +40 -0
  127. package/src/components/Breadcrumbs/Breadcrumbs.tsx +54 -0
  128. package/src/components/Breadcrumbs/Breadcrumbs.types.ts +13 -0
  129. package/src/components/Button/Button.module.css +247 -0
  130. package/src/components/Button/Button.stories.tsx +93 -0
  131. package/src/components/Button/Button.tsx +31 -0
  132. package/src/components/Button/Button.types.ts +14 -0
  133. package/src/components/Card/Card.module.css +112 -0
  134. package/src/components/Card/Card.stories.tsx +86 -0
  135. package/src/components/Card/Card.tsx +70 -0
  136. package/src/components/Card/Card.types.ts +20 -0
  137. package/src/components/Checkbox/Checkbox.module.css +88 -0
  138. package/src/components/Checkbox/Checkbox.stories.tsx +65 -0
  139. package/src/components/Checkbox/Checkbox.tsx +57 -0
  140. package/src/components/Checkbox/Checkbox.types.ts +7 -0
  141. package/src/components/Dropdown/Dropdown.module.css +140 -0
  142. package/src/components/Dropdown/Dropdown.stories.tsx +86 -0
  143. package/src/components/Dropdown/Dropdown.tsx +251 -0
  144. package/src/components/Dropdown/Dropdown.types.ts +27 -0
  145. package/src/components/Header/Header.module.css +38 -0
  146. package/src/components/Header/Header.stories.tsx +53 -0
  147. package/src/components/Header/Header.tsx +49 -0
  148. package/src/components/Header/Header.types.ts +15 -0
  149. package/src/components/Input/Input.module.css +87 -0
  150. package/src/components/Input/Input.stories.tsx +101 -0
  151. package/src/components/Input/Input.tsx +41 -0
  152. package/src/components/Input/Input.types.ts +10 -0
  153. package/src/components/Loader/Loader.module.css +49 -0
  154. package/src/components/Loader/Loader.stories.tsx +75 -0
  155. package/src/components/Loader/Loader.tsx +15 -0
  156. package/src/components/Loader/Loader.types.ts +9 -0
  157. package/src/components/Modal/Modal.module.css +88 -0
  158. package/src/components/Modal/Modal.stories.tsx +94 -0
  159. package/src/components/Modal/Modal.tsx +115 -0
  160. package/src/components/Modal/Modal.types.ts +13 -0
  161. package/src/components/NavBar/NavBar.module.css +77 -0
  162. package/src/components/NavBar/NavBar.stories.tsx +55 -0
  163. package/src/components/NavBar/NavBar.tsx +50 -0
  164. package/src/components/NavBar/NavBar.types.ts +36 -0
  165. package/src/components/Notification/Notification.module.css +72 -0
  166. package/src/components/Notification/Notification.stories.tsx +81 -0
  167. package/src/components/Notification/Notification.tsx +34 -0
  168. package/src/components/Notification/Notification.types.ts +10 -0
  169. package/src/components/Pagination/Pagination.module.css +31 -0
  170. package/src/components/Pagination/Pagination.stories.tsx +128 -0
  171. package/src/components/Pagination/Pagination.tsx +245 -0
  172. package/src/components/Pagination/Pagination.types.ts +37 -0
  173. package/src/components/ProgressBar/ProgressBar.module.css +67 -0
  174. package/src/components/ProgressBar/ProgressBar.stories.tsx +91 -0
  175. package/src/components/ProgressBar/ProgressBar.tsx +49 -0
  176. package/src/components/ProgressBar/ProgressBar.types.ts +13 -0
  177. package/src/components/RadioButton/RadioButton.module.css +162 -0
  178. package/src/components/RadioButton/RadioButton.stories.tsx +114 -0
  179. package/src/components/RadioButton/RadioButton.tsx +43 -0
  180. package/src/components/RadioButton/RadioButton.types.ts +10 -0
  181. package/src/components/Select/Select.module.css +88 -0
  182. package/src/components/Select/Select.stories.tsx +99 -0
  183. package/src/components/Select/Select.tsx +51 -0
  184. package/src/components/Select/Select.types.ts +18 -0
  185. package/src/components/Skeleton/Skeleton.module.css +71 -0
  186. package/src/components/Skeleton/Skeleton.stories.tsx +54 -0
  187. package/src/components/Skeleton/Skeleton.tsx +32 -0
  188. package/src/components/Skeleton/Skeleton.types.ts +10 -0
  189. package/src/components/Stepper/Step.module.css +162 -0
  190. package/src/components/Stepper/Step.tsx +62 -0
  191. package/src/components/Stepper/Step.types.ts +19 -0
  192. package/src/components/Stepper/Stepper.module.css +39 -0
  193. package/src/components/Stepper/Stepper.stories.tsx +88 -0
  194. package/src/components/Stepper/Stepper.tsx +47 -0
  195. package/src/components/Stepper/Stepper.types.ts +16 -0
  196. package/src/components/Stepper/stepper.utils.ts +41 -0
  197. package/src/components/Switch/Switch.module.css +74 -0
  198. package/src/components/Switch/Switch.stories.tsx +56 -0
  199. package/src/components/Switch/Switch.tsx +36 -0
  200. package/src/components/Switch/Switch.types.ts +6 -0
  201. package/src/components/Table/Table.module.css +78 -0
  202. package/src/components/Table/Table.stories.tsx +124 -0
  203. package/src/components/Table/Table.tsx +75 -0
  204. package/src/components/Table/Table.types.ts +29 -0
  205. package/src/components/Tabs/Tabs.module.css +74 -0
  206. package/src/components/Tabs/Tabs.stories.tsx +48 -0
  207. package/src/components/Tabs/Tabs.tsx +113 -0
  208. package/src/components/Tabs/Tabs.types.ts +18 -0
  209. package/src/components/Text/Text.module.css +126 -0
  210. package/src/components/Text/Text.stories.tsx +128 -0
  211. package/src/components/Text/Text.tsx +50 -0
  212. package/src/components/Text/Text.types.ts +43 -0
  213. package/src/components/Textarea/Textarea.module.css +82 -0
  214. package/src/components/Textarea/Textarea.stories.tsx +99 -0
  215. package/src/components/Textarea/Textarea.tsx +43 -0
  216. package/src/components/Textarea/Textarea.types.ts +11 -0
  217. package/src/components/Tooltip/Tooltip.module.css +125 -0
  218. package/src/components/Tooltip/Tooltip.stories.tsx +68 -0
  219. package/src/components/Tooltip/Tooltip.tsx +87 -0
  220. package/src/components/Tooltip/Tooltip.types.ts +14 -0
  221. package/src/index.ts +132 -0
  222. package/src/layouts/AppLayout/AppLayout.module.css +17 -0
  223. package/src/layouts/AppLayout/AppLayout.stories.tsx +124 -0
  224. package/src/layouts/AppLayout/AppLayout.tsx +46 -0
  225. package/src/layouts/AppLayout/AppLayout.types.ts +50 -0
  226. package/src/layouts/AuthLayout/AuthLayout.module.css +49 -0
  227. package/src/layouts/AuthLayout/AuthLayout.stories.tsx +109 -0
  228. package/src/layouts/AuthLayout/AuthLayout.tsx +27 -0
  229. package/src/layouts/AuthLayout/AuthLayout.types.tsx +8 -0
  230. package/src/layouts/DashboardLayout/DashboardLayout.module.css +37 -0
  231. package/src/layouts/DashboardLayout/DashboardLayout.stories.tsx +144 -0
  232. package/src/layouts/DashboardLayout/DashboardLayout.tsx +41 -0
  233. package/src/layouts/DashboardLayout/DashboardLayout.types.tsx +14 -0
  234. package/src/layouts/SettingsLayout/SettingsLayout.module.css +39 -0
  235. package/src/layouts/SettingsLayout/SettingsLayout.stories.tsx +103 -0
  236. package/src/layouts/SettingsLayout/SettingsLayout.tsx +37 -0
  237. package/src/layouts/SettingsLayout/SettingsLayout.types.tsx +13 -0
  238. package/src/styles/ds.css +12 -0
  239. package/src/styles/semantic.css +56 -0
  240. package/src/styles/themes/dark.css +58 -0
  241. package/src/styles/themes/light.css +58 -0
  242. package/src/styles/themes/retro.css +58 -0
  243. package/src/styles/tokens.css +138 -0
  244. package/tsconfig.app.json +28 -0
  245. package/tsconfig.json +7 -0
  246. package/tsconfig.node.json +26 -0
  247. package/vite.config.ts +33 -0
@@ -0,0 +1,36 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ export interface NavBarItem {
4
+ id: string;
5
+ label: ReactNode;
6
+ href?: string;
7
+ disabled?: boolean;
8
+ }
9
+
10
+ export interface NavBarProps {
11
+ id?: string;
12
+ /**
13
+ * The list of navigation items
14
+ */
15
+ items: NavBarItem[];
16
+ /**
17
+ * The ID of the currently active item
18
+ */
19
+ activeId?: string;
20
+ /**
21
+ * Optional logo or branding element
22
+ */
23
+ logo?: ReactNode;
24
+ /**
25
+ * Optional elements to show on the right side (e.g., user menu, search)
26
+ */
27
+ actions?: ReactNode;
28
+ /**
29
+ * Callback fired when an item is clicked
30
+ */
31
+ onItemClick?: (id: string) => void;
32
+ /**
33
+ * Additional class names
34
+ */
35
+ className?: string;
36
+ }
@@ -0,0 +1,72 @@
1
+ .root {
2
+ display: flex;
3
+ position: relative;
4
+ padding: var(--ds-space-3) var(--ds-space-4);
5
+ border-radius: var(--ds-radius-md);
6
+ border-left: 0.25rem solid;
7
+ font-family: var(--ds-font-family-base);
8
+ gap: var(--ds-space-3);
9
+ box-shadow: var(--ds-shadow-sm);
10
+ max-width: 25rem;
11
+ }
12
+
13
+ .content {
14
+ flex: 1;
15
+ }
16
+
17
+ .title {
18
+ font-weight: var(--ds-font-weight-bold);
19
+ font-size: var(--ds-font-size-sm);
20
+ margin-bottom: var(--ds-space-1);
21
+ }
22
+
23
+ .message {
24
+ font-size: var(--ds-font-size-sm);
25
+ line-height: var(--ds-line-height-base);
26
+ }
27
+
28
+ .closeButton {
29
+ flex-shrink: 0;
30
+ margin-top: calc(var(--ds-space-1) * -1);
31
+ margin-right: calc(var(--ds-space-2) * -1);
32
+ padding: 0 !important;
33
+ width: var(--ds-space-6) !important;
34
+ height: var(--ds-space-6) !important;
35
+ min-width: unset !important;
36
+ opacity: 0.6;
37
+ }
38
+
39
+ .closeButton:hover {
40
+ opacity: 1;
41
+ }
42
+
43
+ /* Intents */
44
+ .neutral {
45
+ background-color: var(--ds-surface-1);
46
+ border-color: var(--ds-neutral);
47
+ color: var(--ds-text-1);
48
+ }
49
+
50
+ .info {
51
+ background-color: var(--ds-info-subtle);
52
+ border-color: var(--ds-info);
53
+ color: var(--ds-info-active);
54
+ }
55
+
56
+ .success {
57
+ background-color: var(--ds-success-subtle);
58
+ border-color: var(--ds-success);
59
+ color: var(--ds-success-active);
60
+ }
61
+
62
+ .warning {
63
+ background-color: var(--ds-warning-subtle);
64
+ border-color: var(--ds-warning);
65
+ color: var(--ds-warning-active);
66
+ }
67
+
68
+ .danger {
69
+ background-color: var(--ds-danger-subtle);
70
+ border-color: var(--ds-danger);
71
+ color: var(--ds-danger-active);
72
+ }
@@ -0,0 +1,81 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { fn } from 'storybook/test';
3
+
4
+ import { Notification } from './Notification.tsx';
5
+ import { Box } from '../Box/Box.tsx';
6
+
7
+ const meta = {
8
+ title: 'Components/Notification',
9
+ component: Notification,
10
+ tags: ['autodocs'],
11
+ parameters: {
12
+ layout: 'centered',
13
+ },
14
+ argTypes: {
15
+ intent: {
16
+ control: 'select',
17
+ options: ['neutral', 'success', 'warning', 'danger', 'info'],
18
+ },
19
+ },
20
+ args: {
21
+ onClose: fn(),
22
+ },
23
+ } satisfies Meta<typeof Notification>;
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ export const Info: Story = {
29
+ args: {
30
+ intent: 'info',
31
+ title: 'Update Available',
32
+ children: 'A new version of the software is available for download.',
33
+ },
34
+ };
35
+
36
+ export const Success: Story = {
37
+ args: {
38
+ intent: 'success',
39
+ title: 'Success!',
40
+ children: 'Your profile has been updated successfully.',
41
+ },
42
+ };
43
+
44
+ export const Warning: Story = {
45
+ args: {
46
+ intent: 'warning',
47
+ title: 'Storage almost full',
48
+ children: 'You have used 90% of your available storage space.',
49
+ },
50
+ };
51
+
52
+ export const Danger: Story = {
53
+ args: {
54
+ intent: 'danger',
55
+ title: 'Error',
56
+ children: 'An error occurred while saving your changes. Please try again.',
57
+ },
58
+ };
59
+
60
+ export const Neutral: Story = {
61
+ args: {
62
+ intent: 'neutral',
63
+ children: 'This is a simple notification message without a title.',
64
+ },
65
+ };
66
+
67
+ export const All: Story = {
68
+ args: {
69
+ children: '',
70
+ },
71
+ render: () => (
72
+ <Box display="flex" flexDirection="column" gap={4} width="500px">
73
+ {(['neutral', 'success', 'warning', 'danger', 'info'] as const).map((intent) => (
74
+ <Notification key={intent} intent={intent} title={intent.toUpperCase()}>
75
+ This is a {intent} notification with title and description.
76
+ </Notification>
77
+ ))}
78
+ <Notification intent="info">This is a notification without a title.</Notification>
79
+ </Box>
80
+ ),
81
+ };
@@ -0,0 +1,34 @@
1
+ import clsx from 'clsx';
2
+
3
+ import styles from './Notification.module.css';
4
+ import type { NotificationProps } from './Notification.types.ts';
5
+ import { Button } from '../Button/Button.tsx';
6
+
7
+ export const Notification = ({
8
+ intent = 'neutral',
9
+ title,
10
+ children,
11
+ onClose,
12
+ className,
13
+ ...props
14
+ }: NotificationProps) => {
15
+ return (
16
+ <div className={clsx(styles.root, styles[intent], className)} role="alert" {...props}>
17
+ <div className={styles.content}>
18
+ {title && <div className={styles.title}>{title}</div>}
19
+ <div className={styles.message}>{children}</div>
20
+ </div>
21
+ {onClose && (
22
+ <Button
23
+ variant="subtle"
24
+ size="xs"
25
+ onClick={onClose}
26
+ className={styles.closeButton}
27
+ aria-label="Close notification"
28
+ >
29
+
30
+ </Button>
31
+ )}
32
+ </div>
33
+ );
34
+ };
@@ -0,0 +1,10 @@
1
+ import type { HTMLAttributes, ReactNode } from 'react';
2
+
3
+ export type NotificationIntent = 'neutral' | 'success' | 'warning' | 'danger' | 'info';
4
+
5
+ export interface NotificationProps extends HTMLAttributes<HTMLDivElement> {
6
+ intent?: NotificationIntent;
7
+ title?: string;
8
+ children: ReactNode;
9
+ onClose?: () => void;
10
+ }
@@ -0,0 +1,31 @@
1
+ .root {
2
+ display: flex;
3
+ align-items: center;
4
+ }
5
+
6
+ .list {
7
+ display: flex;
8
+ align-items: center;
9
+ gap: var(--ds-space-2);
10
+ list-style: none;
11
+ margin: 0;
12
+ padding: 0;
13
+ }
14
+
15
+ .item {
16
+ display: flex;
17
+ }
18
+
19
+ .ellipsis {
20
+ display: inline-flex;
21
+ align-items: center;
22
+ justify-content: center;
23
+ min-width: var(--ds-space-8);
24
+ height: var(--ds-space-8);
25
+ color: var(--ds-text-2);
26
+ font-size: var(--ds-font-size-sm);
27
+ }
28
+
29
+ .pageButton {
30
+ min-width: var(--ds-space-8);
31
+ }
@@ -0,0 +1,128 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { useState } from 'react';
3
+
4
+ import { Pagination } from './Pagination.tsx';
5
+
6
+ const meta = {
7
+ title: 'Components/Pagination',
8
+ component: Pagination,
9
+ tags: ['autodocs'],
10
+ parameters: {
11
+ layout: 'centered',
12
+ },
13
+ } satisfies Meta<typeof Pagination>;
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof meta>;
17
+
18
+ export const Default: Story = {
19
+ args: {
20
+ count: 24,
21
+ page: 6,
22
+ },
23
+ };
24
+
25
+ export const Compact: Story = {
26
+ args: {
27
+ count: 12,
28
+ page: 5,
29
+ siblingCount: 0,
30
+ boundaryCount: 1,
31
+ showEllipsis: true,
32
+ size: 'xs',
33
+ },
34
+ };
35
+
36
+ export const Minimal: Story = {
37
+ args: {
38
+ count: 10,
39
+ page: 4,
40
+ showFirstLast: false,
41
+ showPrevNext: false,
42
+ showEllipsis: false,
43
+ },
44
+ };
45
+
46
+ export const WithEllipsis: Story = {
47
+ args: {
48
+ count: 40,
49
+ page: 20,
50
+ siblingCount: 1,
51
+ boundaryCount: 2,
52
+ showEllipsis: true,
53
+ },
54
+ };
55
+
56
+ export const FirstPage: Story = {
57
+ args: {
58
+ count: 12,
59
+ page: 1,
60
+ },
61
+ };
62
+
63
+ export const LastPage: Story = {
64
+ args: {
65
+ count: 12,
66
+ page: 12,
67
+ },
68
+ };
69
+
70
+ export const Disabled: Story = {
71
+ args: {
72
+ count: 18,
73
+ page: 7,
74
+ disabled: true,
75
+ },
76
+ };
77
+
78
+ export const CustomLabels: Story = {
79
+ args: {
80
+ count: 16,
81
+ page: 8,
82
+ labels: {
83
+ first: '<<',
84
+ prev: '<',
85
+ next: '>',
86
+ last: '>>',
87
+ },
88
+ },
89
+ };
90
+
91
+ export const VariantIntent: Story = {
92
+ args: {
93
+ count: 20,
94
+ page: 9,
95
+ variant: 'subtle',
96
+ intent: 'info',
97
+ activeVariant: 'solid',
98
+ activeIntent: 'info',
99
+ },
100
+ };
101
+
102
+ export const WithActions: Story = {
103
+ args: {
104
+ count: 24,
105
+ page: 6,
106
+ },
107
+ render: () => <WithActionsStory />,
108
+ };
109
+
110
+ const WithActionsStory = () => {
111
+ const [page, setPage] = useState(3);
112
+
113
+ return (
114
+ <Pagination
115
+ count={18}
116
+ page={page}
117
+ onPageChange={(nextPage) => {
118
+ setPage(nextPage);
119
+ console.log('onPageChange', nextPage);
120
+ }}
121
+ onFirstClick={(nextPage) => console.log('onFirstClick', nextPage)}
122
+ onPrevClick={(nextPage) => console.log('onPrevClick', nextPage)}
123
+ onNextClick={(nextPage) => console.log('onNextClick', nextPage)}
124
+ onLastClick={(nextPage) => console.log('onLastClick', nextPage)}
125
+ labels={{ first: 'First', prev: 'Previous', next: 'Next', last: 'Last' }}
126
+ />
127
+ );
128
+ };
@@ -0,0 +1,245 @@
1
+ import clsx from 'clsx';
2
+ import { useId, useMemo, useState } from 'react';
3
+
4
+ import styles from './Pagination.module.css';
5
+ import type { PaginationProps } from './Pagination.types.ts';
6
+ import { Button } from '../Button/Button.tsx';
7
+
8
+ type PageItem = number | 'ellipsis';
9
+
10
+ const clamp = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max);
11
+
12
+ const range = (start: number, end: number) => {
13
+ const items: number[] = [];
14
+ for (let i = start; i <= end; i += 1) {
15
+ items.push(i);
16
+ }
17
+ return items;
18
+ };
19
+
20
+ const getPageItems = (
21
+ count: number,
22
+ page: number,
23
+ siblingCount: number,
24
+ boundaryCount: number,
25
+ showEllipsis: boolean
26
+ ): PageItem[] => {
27
+ if (count <= 0) {
28
+ return [];
29
+ }
30
+
31
+ if (!showEllipsis) {
32
+ return range(1, count);
33
+ }
34
+
35
+ const totalNumbers = siblingCount * 2 + 1;
36
+ const totalBlocks = totalNumbers + boundaryCount * 2 + 2;
37
+
38
+ if (count <= totalBlocks) {
39
+ return range(1, count);
40
+ }
41
+
42
+ const startPages = range(1, Math.min(boundaryCount, count));
43
+ const endPages = range(Math.max(count - boundaryCount + 1, boundaryCount + 1), count);
44
+
45
+ const leftSiblingIndex = Math.max(page - siblingCount, boundaryCount + 2);
46
+ const rightSiblingIndex = Math.min(page + siblingCount, count - boundaryCount - 1);
47
+
48
+ const showLeftEllipsis = leftSiblingIndex > boundaryCount + 2;
49
+ const showRightEllipsis = rightSiblingIndex < count - boundaryCount - 1;
50
+
51
+ const items: PageItem[] = [...startPages];
52
+
53
+ const middleStart = showLeftEllipsis ? leftSiblingIndex : boundaryCount + 1;
54
+ const middleEnd = showRightEllipsis ? rightSiblingIndex : count - boundaryCount;
55
+
56
+ if (showLeftEllipsis) {
57
+ items.push('ellipsis');
58
+ }
59
+
60
+ if (middleStart <= middleEnd) {
61
+ items.push(...range(middleStart, middleEnd));
62
+ }
63
+
64
+ if (showRightEllipsis) {
65
+ items.push('ellipsis');
66
+ }
67
+
68
+ items.push(...endPages);
69
+
70
+ return items;
71
+ };
72
+
73
+ export const Pagination = ({
74
+ id,
75
+ count,
76
+ page,
77
+ defaultPage = 1,
78
+ onPageChange,
79
+ onFirstClick,
80
+ onLastClick,
81
+ onNextClick,
82
+ onPrevClick,
83
+ siblingCount = 1,
84
+ boundaryCount = 1,
85
+ showFirstLast = true,
86
+ showPrevNext = true,
87
+ showEllipsis = true,
88
+ disabled = false,
89
+ size = 'sm',
90
+ variant = 'outline',
91
+ intent = 'neutral',
92
+ activeVariant = 'solid',
93
+ activeIntent,
94
+ labels,
95
+ ariaLabel = 'Pagination',
96
+ getPageLabel,
97
+ className,
98
+ }: PaginationProps) => {
99
+ const baseId = useId();
100
+ const componentId = id ?? `ds-pagination-${baseId}`;
101
+ const [internalPage, setInternalPage] = useState(defaultPage);
102
+
103
+ const safeCount = Math.max(0, count);
104
+ const currentPage = clamp(page ?? internalPage, 1, Math.max(1, safeCount));
105
+
106
+ const pageItems = useMemo(
107
+ () => getPageItems(safeCount, currentPage, siblingCount, boundaryCount, showEllipsis),
108
+ [safeCount, currentPage, siblingCount, boundaryCount, showEllipsis]
109
+ );
110
+
111
+ const handlePageChange = (nextPage: number) => {
112
+ if (disabled || nextPage === currentPage) {
113
+ return;
114
+ }
115
+ if (page === undefined) {
116
+ setInternalPage(nextPage);
117
+ }
118
+ onPageChange?.(nextPage);
119
+ };
120
+
121
+ const handleFirst = () => {
122
+ const target = 1;
123
+ handlePageChange(target);
124
+ onFirstClick?.(target);
125
+ };
126
+
127
+ const handleLast = () => {
128
+ const target = safeCount;
129
+ handlePageChange(target);
130
+ onLastClick?.(target);
131
+ };
132
+
133
+ const handlePrev = () => {
134
+ const target = Math.max(1, currentPage - 1);
135
+ handlePageChange(target);
136
+ onPrevClick?.(target);
137
+ };
138
+
139
+ const handleNext = () => {
140
+ const target = Math.min(safeCount, currentPage + 1);
141
+ handlePageChange(target);
142
+ onNextClick?.(target);
143
+ };
144
+
145
+ if (safeCount <= 0) {
146
+ return null;
147
+ }
148
+
149
+ return (
150
+ <nav id={componentId} aria-label={ariaLabel} className={clsx(styles.root, className)}>
151
+ <ul className={styles.list}>
152
+ {showFirstLast && (
153
+ <li className={styles.item}>
154
+ <Button
155
+ size={size}
156
+ variant={variant}
157
+ intent={intent}
158
+ className={styles.pageButton}
159
+ onClick={handleFirst}
160
+ disabled={disabled || currentPage === 1}
161
+ aria-label="Go to first page"
162
+ >
163
+ {labels?.first ?? 'First'}
164
+ </Button>
165
+ </li>
166
+ )}
167
+ {showPrevNext && (
168
+ <li className={styles.item}>
169
+ <Button
170
+ size={size}
171
+ variant={variant}
172
+ intent={intent}
173
+ className={styles.pageButton}
174
+ onClick={handlePrev}
175
+ disabled={disabled || currentPage === 1}
176
+ aria-label="Go to previous page"
177
+ >
178
+ {labels?.prev ?? 'Prev'}
179
+ </Button>
180
+ </li>
181
+ )}
182
+ {pageItems.map((item, index) => {
183
+ if (item === 'ellipsis') {
184
+ return (
185
+ <li key={`ellipsis-${index}`} className={styles.item} aria-hidden="true">
186
+ <span className={styles.ellipsis}>…</span>
187
+ </li>
188
+ );
189
+ }
190
+
191
+ const isCurrent = item === currentPage;
192
+ const ariaLabelText =
193
+ getPageLabel?.(item, isCurrent) ?? `Page ${item}${isCurrent ? ', current page' : ''}`;
194
+
195
+ return (
196
+ <li key={item} className={styles.item}>
197
+ <Button
198
+ size={size}
199
+ variant={isCurrent ? activeVariant : variant}
200
+ intent={isCurrent ? (activeIntent ?? intent) : intent}
201
+ className={styles.pageButton}
202
+ onClick={() => handlePageChange(item)}
203
+ disabled={disabled}
204
+ aria-current={isCurrent ? 'page' : undefined}
205
+ aria-label={ariaLabelText}
206
+ >
207
+ {item}
208
+ </Button>
209
+ </li>
210
+ );
211
+ })}
212
+ {showPrevNext && (
213
+ <li className={styles.item}>
214
+ <Button
215
+ size={size}
216
+ variant={variant}
217
+ intent={intent}
218
+ className={styles.pageButton}
219
+ onClick={handleNext}
220
+ disabled={disabled || currentPage === safeCount}
221
+ aria-label="Go to next page"
222
+ >
223
+ {labels?.next ?? 'Next'}
224
+ </Button>
225
+ </li>
226
+ )}
227
+ {showFirstLast && (
228
+ <li className={styles.item}>
229
+ <Button
230
+ size={size}
231
+ variant={variant}
232
+ intent={intent}
233
+ className={styles.pageButton}
234
+ onClick={handleLast}
235
+ disabled={disabled || currentPage === safeCount}
236
+ aria-label="Go to last page"
237
+ >
238
+ {labels?.last ?? 'Last'}
239
+ </Button>
240
+ </li>
241
+ )}
242
+ </ul>
243
+ </nav>
244
+ );
245
+ };
@@ -0,0 +1,37 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ import type { ButtonIntent, ButtonSize, ButtonVariant } from '../Button/Button.types.ts';
4
+
5
+ export interface PaginationLabels {
6
+ first?: ReactNode;
7
+ last?: ReactNode;
8
+ next?: ReactNode;
9
+ prev?: ReactNode;
10
+ }
11
+
12
+ export interface PaginationProps {
13
+ id?: string;
14
+ count: number;
15
+ page?: number;
16
+ defaultPage?: number;
17
+ onPageChange?: (page: number) => void;
18
+ onFirstClick?: (page: number) => void;
19
+ onLastClick?: (page: number) => void;
20
+ onNextClick?: (page: number) => void;
21
+ onPrevClick?: (page: number) => void;
22
+ siblingCount?: number;
23
+ boundaryCount?: number;
24
+ showFirstLast?: boolean;
25
+ showPrevNext?: boolean;
26
+ showEllipsis?: boolean;
27
+ disabled?: boolean;
28
+ size?: ButtonSize;
29
+ variant?: ButtonVariant;
30
+ intent?: ButtonIntent;
31
+ activeVariant?: ButtonVariant;
32
+ activeIntent?: ButtonIntent;
33
+ labels?: PaginationLabels;
34
+ ariaLabel?: string;
35
+ getPageLabel?: (page: number, isCurrent: boolean) => string;
36
+ className?: string;
37
+ }