@shohojdhara/atomix 0.3.14 → 0.3.15
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.
- package/CHANGELOG.md +20 -0
- package/build-tools/EXAMPLES.md +372 -0
- package/build-tools/README.md +242 -0
- package/build-tools/__tests__/error-handler.test.js +230 -0
- package/build-tools/__tests__/index.test.js +141 -0
- package/build-tools/__tests__/rollup-plugin.test.js +194 -0
- package/build-tools/__tests__/utils.test.js +161 -0
- package/build-tools/__tests__/vite-plugin.test.js +129 -0
- package/build-tools/__tests__/webpack-loader.test.js +190 -0
- package/build-tools/error-handler.js +308 -0
- package/build-tools/index.d.ts +43 -0
- package/build-tools/index.js +88 -0
- package/build-tools/package.json +67 -0
- package/build-tools/rollup-plugin.js +236 -0
- package/build-tools/types.d.ts +163 -0
- package/build-tools/utils.js +203 -0
- package/build-tools/vite-plugin.js +161 -0
- package/build-tools/webpack-loader.js +123 -0
- package/dist/atomix.css +203 -90
- package/dist/atomix.css.map +1 -1
- package/dist/atomix.min.css +3 -3
- package/dist/atomix.min.css.map +1 -1
- package/dist/build-tools/EXAMPLES.md +372 -0
- package/dist/build-tools/README.md +242 -0
- package/dist/build-tools/__tests__/error-handler.test.js +230 -0
- package/dist/build-tools/__tests__/index.test.js +141 -0
- package/dist/build-tools/__tests__/rollup-plugin.test.js +194 -0
- package/dist/build-tools/__tests__/utils.test.js +161 -0
- package/dist/build-tools/__tests__/vite-plugin.test.js +129 -0
- package/dist/build-tools/__tests__/webpack-loader.test.js +190 -0
- package/dist/build-tools/error-handler.js +308 -0
- package/dist/build-tools/index.d.ts +43 -0
- package/dist/build-tools/index.js +88 -0
- package/dist/build-tools/package.json +67 -0
- package/dist/build-tools/rollup-plugin.js +236 -0
- package/dist/build-tools/types.d.ts +163 -0
- package/dist/build-tools/utils.js +203 -0
- package/dist/build-tools/vite-plugin.js +161 -0
- package/dist/build-tools/webpack-loader.js +123 -0
- package/dist/charts.d.ts +1 -1
- package/dist/charts.js +86 -57
- package/dist/charts.js.map +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +136 -112
- package/dist/core.js.map +1 -1
- package/dist/forms.d.ts +2 -5
- package/dist/forms.js +140 -128
- package/dist/forms.js.map +1 -1
- package/dist/heavy.d.ts +1 -1
- package/dist/heavy.js +136 -112
- package/dist/heavy.js.map +1 -1
- package/dist/index.d.ts +9 -61
- package/dist/index.esm.js +237 -286
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +250 -299
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +23 -8
- package/scripts/atomix-cli.js +170 -73
- package/scripts/cli/__tests__/README.md +81 -0
- package/scripts/cli/__tests__/basic.test.js +115 -0
- package/scripts/cli/__tests__/component-generator.test.js +332 -0
- package/scripts/cli/__tests__/integration.test.js +327 -0
- package/scripts/cli/__tests__/test-setup.js +133 -0
- package/scripts/cli/__tests__/token-manager.test.js +251 -0
- package/scripts/cli/__tests__/utils.test.js +161 -0
- package/scripts/cli/component-generator.js +253 -299
- package/scripts/cli/dependency-checker.js +355 -0
- package/scripts/cli/interactive-init.js +46 -5
- package/scripts/cli/template-manager.js +0 -2
- package/scripts/cli/templates/common-templates.js +636 -0
- package/scripts/cli/templates/composable-templates.js +148 -126
- package/scripts/cli/templates/index.js +23 -16
- package/scripts/cli/templates/project-templates.js +151 -23
- package/scripts/cli/templates/react-templates.js +280 -210
- package/scripts/cli/templates/scss-templates.js +90 -91
- package/scripts/cli/templates/testing-templates.js +206 -27
- package/scripts/cli/templates/testing-utils.js +278 -0
- package/scripts/cli/templates/types-templates.js +70 -56
- package/scripts/cli/theme-bridge.js +8 -2
- package/scripts/cli/token-manager.js +318 -206
- package/scripts/cli/utils.js +0 -1
- package/src/components/Accordion/Accordion.stories.tsx +369 -870
- package/src/components/AtomixGlass/AtomixGlass.tsx +80 -39
- package/src/components/AtomixGlass/AtomixGlassContainer.tsx +103 -81
- package/src/components/AtomixGlass/__snapshots__/AtomixGlass.test.tsx.snap +8 -7
- package/src/components/AtomixGlass/glass-utils.ts +2 -2
- package/src/components/AtomixGlass/shader-utils.ts +5 -0
- package/src/components/AtomixGlass/stories/Customization.stories.tsx +131 -0
- package/src/components/AtomixGlass/stories/Examples.stories.tsx +2957 -2853
- package/src/components/AtomixGlass/stories/Modes.stories.tsx +1 -1
- package/src/components/AtomixGlass/stories/Overview.stories.tsx +348 -0
- package/src/components/AtomixGlass/stories/Performance.stories.tsx +103 -0
- package/src/components/AtomixGlass/stories/Playground.stories.tsx +50 -35
- package/src/components/AtomixGlass/stories/{ShaderVariants.stories.tsx → Shaders.stories.tsx} +1 -1
- package/src/components/AtomixGlass/stories/shared-components.tsx +90 -190
- package/src/components/Avatar/Avatar.stories.tsx +213 -1
- package/src/components/Badge/Badge.stories.tsx +121 -362
- package/src/components/Block/Block.stories.tsx +21 -12
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +141 -23
- package/src/components/Button/Button.stories.tsx +463 -1126
- package/src/components/Button/Button.test.tsx +107 -0
- package/src/components/Button/Button.tsx +46 -50
- package/src/components/Button/ButtonGroup.stories.tsx +373 -217
- package/src/components/Callout/Callout.stories.tsx +289 -634
- package/src/components/Card/Card.stories.tsx +248 -68
- package/src/components/Chart/Chart.stories.tsx +150 -8
- package/src/components/ColorModeToggle/ColorModeToggle.stories.tsx +151 -69
- package/src/components/Countdown/Countdown.stories.tsx +115 -8
- package/src/components/DataTable/DataTable.stories.tsx +346 -146
- package/src/components/DatePicker/DatePicker.stories.tsx +325 -1066
- package/src/components/Dropdown/Dropdown.stories.tsx +153 -33
- package/src/components/EdgePanel/EdgePanel.stories.tsx +230 -21
- package/src/components/Footer/Footer.stories.tsx +392 -328
- package/src/components/Form/Checkbox.stories.tsx +140 -6
- package/src/components/Form/Checkbox.test.tsx +63 -0
- package/src/components/Form/Checkbox.tsx +87 -51
- package/src/components/Form/Form.stories.tsx +119 -20
- package/src/components/Form/FormGroup.stories.tsx +127 -4
- package/src/components/Form/Radio.stories.tsx +140 -5
- package/src/components/Form/Select.stories.tsx +140 -8
- package/src/components/Form/Textarea.stories.tsx +149 -6
- package/src/components/Hero/Hero.stories.tsx +333 -32
- package/src/components/List/List.stories.tsx +141 -3
- package/src/components/Modal/Modal.stories.tsx +181 -42
- package/src/components/Popover/Popover.stories.tsx +448 -98
- package/src/components/Progress/Progress.stories.tsx +167 -5
- package/src/components/River/River.stories.tsx +1 -1
- package/src/components/SectionIntro/SectionIntro.stories.tsx +240 -48
- package/src/components/Spinner/Spinner.stories.tsx +102 -8
- package/src/components/Steps/Steps.stories.tsx +172 -43
- package/src/components/Tabs/Tabs.stories.tsx +136 -10
- package/src/components/Testimonial/Testimonial.stories.tsx +120 -3
- package/src/components/Todo/Todo.stories.tsx +198 -9
- package/src/components/Toggle/Toggle.stories.tsx +126 -39
- package/src/components/Tooltip/Tooltip.stories.tsx +194 -104
- package/src/components/Upload/Upload.stories.tsx +113 -24
- package/src/lib/README.md +2 -2
- package/src/lib/__tests__/theme-tools.test.ts +193 -0
- package/src/lib/composables/index.ts +2 -2
- package/src/lib/composables/useAtomixGlass.ts +28 -56
- package/src/lib/composables/useChartExport.ts +2 -7
- package/src/lib/composables/useDataTable.ts +46 -29
- package/src/lib/constants/components.ts +9 -32
- package/src/lib/theme/devtools/CLI.ts +1 -1
- package/src/lib/types/components.ts +1 -1
- package/src/lib/utils/__tests__/csv.test.ts +45 -0
- package/src/lib/utils/csv.ts +17 -0
- package/src/lib/utils/dataTableExport.ts +1 -10
- package/src/styles/01-settings/_index.scss +2 -1
- package/src/styles/01-settings/_settings.accordion.scss +28 -7
- package/src/styles/01-settings/_settings.colors.scss +11 -11
- package/src/styles/01-settings/_settings.typography.scss +5 -5
- package/src/styles/02-tools/_tools.utility-api.scss +14 -0
- package/src/styles/06-components/_components.accordion.scss +56 -14
- package/src/styles/06-components/_components.checkbox.scss +23 -17
- package/src/styles/99-utilities/_index.scss +2 -0
- package/src/styles/99-utilities/_utilities.scss +3 -1
- package/src/styles/99-utilities/_utilities.text-gradient.scss +45 -0
- package/themes/dark-complementary/README.md +98 -0
- package/themes/dark-complementary/index.scss +158 -0
- package/themes/default-light/README.md +81 -0
- package/themes/default-light/index.scss +154 -0
- package/themes/high-contrast/README.md +105 -0
- package/themes/high-contrast/index.scss +172 -0
- package/themes/test-theme/README.md +38 -0
- package/themes/test-theme/index.scss +47 -0
- package/scripts/cli/templates-original-backup.js +0 -1655
- package/scripts/cli/templates_backup.js +0 -684
- package/src/components/AtomixGlass/stories/AtomixGlass.stories.tsx +0 -1438
- package/src/lib/composables/useButton.ts +0 -93
- package/src/lib/composables/useCheckbox.ts +0 -70
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { fn } from '@storybook/test';
|
|
2
3
|
import { useState } from 'react';
|
|
3
4
|
import { ColorModeToggle, type ColorMode } from './ColorModeToggle';
|
|
4
5
|
import { Moon, Sun } from '@phosphor-icons/react';
|
|
@@ -10,33 +11,132 @@ const meta = {
|
|
|
10
11
|
layout: 'centered',
|
|
11
12
|
docs: {
|
|
12
13
|
description: {
|
|
13
|
-
component:
|
|
14
|
-
|
|
14
|
+
component: `
|
|
15
|
+
# ColorModeToggle
|
|
16
|
+
|
|
17
|
+
## Overview
|
|
18
|
+
|
|
19
|
+
The ColorModeToggle component provides a user-friendly switch for toggling between light and dark color modes. It automatically detects system preferences, persists user choices, and provides visual feedback. Essential for applications supporting theme customization and accessibility preferences.
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
- Automatic detection of system preference
|
|
24
|
+
- Local storage persistence
|
|
25
|
+
- Multiple size options
|
|
26
|
+
- Customizable icons
|
|
27
|
+
- Accessible design
|
|
28
|
+
- Controlled/uncontrolled modes
|
|
29
|
+
|
|
30
|
+
## Accessibility
|
|
31
|
+
|
|
32
|
+
- Keyboard support: Toggle can be activated using Space or Enter keys
|
|
33
|
+
- Screen reader: Announces current mode and change events
|
|
34
|
+
- ARIA support: Proper roles and properties for assistive technologies
|
|
35
|
+
- Focus management: Maintains visible focus indicator
|
|
36
|
+
|
|
37
|
+
## Usage Examples
|
|
38
|
+
|
|
39
|
+
### Basic Usage
|
|
40
|
+
|
|
41
|
+
\`\`\`tsx
|
|
42
|
+
<ColorModeToggle />
|
|
43
|
+
\`\`\`
|
|
44
|
+
|
|
45
|
+
### Controlled Mode
|
|
46
|
+
|
|
47
|
+
\`\`\`tsx
|
|
48
|
+
<ColorModeToggle value={mode} onChange={setMode} />
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
## API Reference
|
|
52
|
+
|
|
53
|
+
### Props
|
|
54
|
+
|
|
55
|
+
| Prop | Type | Default | Description |
|
|
56
|
+
| ---- | ---- | ------- | ----------- |
|
|
57
|
+
| size | 'sm' \\| 'md' \\| 'lg' | 'md' | Size variant of the toggle |
|
|
58
|
+
| disabled | boolean | false | Whether the toggle is disabled |
|
|
59
|
+
| showTooltip | boolean | false | Whether to show tooltip on hover |
|
|
60
|
+
| disableStorage | boolean | false | Whether to disable localStorage persistence |
|
|
61
|
+
| disableSystemPreference | boolean | false | Whether to disable system preference detection |
|
|
62
|
+
| value | 'light' \\| 'dark' \\| 'system' | - | Controlled value of the toggle |
|
|
63
|
+
| onChange | (mode: ColorMode) => void | - | Callback when mode changes |
|
|
64
|
+
| lightIcon | ReactNode | Default sun icon | Custom icon for light mode |
|
|
65
|
+
| darkIcon | ReactNode | Default moon icon | Custom icon for dark mode |
|
|
66
|
+
`,
|
|
15
67
|
},
|
|
16
68
|
},
|
|
17
69
|
},
|
|
18
70
|
tags: ['autodocs'],
|
|
19
71
|
argTypes: {
|
|
20
72
|
size: {
|
|
21
|
-
control: 'select',
|
|
73
|
+
control: { type: 'select' },
|
|
22
74
|
options: ['sm', 'md', 'lg'],
|
|
23
75
|
description: 'Size variant',
|
|
76
|
+
table: {
|
|
77
|
+
type: { summary: '"sm" | "md" | "lg"' },
|
|
78
|
+
defaultValue: { summary: 'md' },
|
|
79
|
+
},
|
|
24
80
|
},
|
|
25
81
|
disabled: {
|
|
26
82
|
control: 'boolean',
|
|
27
83
|
description: 'Disable the toggle',
|
|
84
|
+
table: {
|
|
85
|
+
type: { summary: 'boolean' },
|
|
86
|
+
defaultValue: { summary: false },
|
|
87
|
+
},
|
|
28
88
|
},
|
|
29
89
|
showTooltip: {
|
|
30
90
|
control: 'boolean',
|
|
31
91
|
description: 'Show tooltip on hover',
|
|
92
|
+
table: {
|
|
93
|
+
type: { summary: 'boolean' },
|
|
94
|
+
defaultValue: { summary: false },
|
|
95
|
+
},
|
|
32
96
|
},
|
|
33
97
|
disableStorage: {
|
|
34
98
|
control: 'boolean',
|
|
35
99
|
description: 'Disable localStorage persistence',
|
|
100
|
+
table: {
|
|
101
|
+
type: { summary: 'boolean' },
|
|
102
|
+
defaultValue: { summary: false },
|
|
103
|
+
},
|
|
36
104
|
},
|
|
37
105
|
disableSystemPreference: {
|
|
38
106
|
control: 'boolean',
|
|
39
107
|
description: 'Disable system preference detection',
|
|
108
|
+
table: {
|
|
109
|
+
type: { summary: 'boolean' },
|
|
110
|
+
defaultValue: { summary: false },
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
value: {
|
|
114
|
+
control: { type: 'radio', options: ['light', 'dark', 'system'] },
|
|
115
|
+
description: 'Controlled value of the toggle',
|
|
116
|
+
table: {
|
|
117
|
+
type: { summary: '"light" | "dark" | "system"' },
|
|
118
|
+
defaultValue: { summary: '-' },
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
onChange: {
|
|
122
|
+
action: 'mode changed',
|
|
123
|
+
description: 'Callback when mode changes',
|
|
124
|
+
},
|
|
125
|
+
lightIcon: {
|
|
126
|
+
control: 'object',
|
|
127
|
+
description: 'Custom icon for light mode',
|
|
128
|
+
table: {
|
|
129
|
+
type: { summary: 'ReactNode' },
|
|
130
|
+
defaultValue: { summary: 'Default sun icon' },
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
darkIcon: {
|
|
134
|
+
control: 'object',
|
|
135
|
+
description: 'Custom icon for dark mode',
|
|
136
|
+
table: {
|
|
137
|
+
type: { summary: 'ReactNode' },
|
|
138
|
+
defaultValue: { summary: 'Default moon icon' },
|
|
139
|
+
},
|
|
40
140
|
},
|
|
41
141
|
},
|
|
42
142
|
} satisfies Meta<typeof ColorModeToggle>;
|
|
@@ -44,13 +144,18 @@ const meta = {
|
|
|
44
144
|
export default meta;
|
|
45
145
|
type Story = StoryObj<typeof meta>;
|
|
46
146
|
|
|
47
|
-
|
|
48
|
-
export const Default: Story = {
|
|
147
|
+
export const BasicUsage: Story = {
|
|
49
148
|
args: {},
|
|
149
|
+
parameters: {
|
|
150
|
+
docs: {
|
|
151
|
+
description: {
|
|
152
|
+
story: 'Default Color Mode Toggle with automatic system preference detection.',
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
50
156
|
};
|
|
51
157
|
|
|
52
|
-
|
|
53
|
-
export const Sizes: Story = {
|
|
158
|
+
export const AllSizes: Story = {
|
|
54
159
|
render: () => (
|
|
55
160
|
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
|
|
56
161
|
<ColorModeToggle size="sm" />
|
|
@@ -58,17 +163,29 @@ export const Sizes: Story = {
|
|
|
58
163
|
<ColorModeToggle size="lg" />
|
|
59
164
|
</div>
|
|
60
165
|
),
|
|
166
|
+
parameters: {
|
|
167
|
+
docs: {
|
|
168
|
+
description: {
|
|
169
|
+
story: 'Color Mode Toggle in all available sizes.',
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
61
173
|
};
|
|
62
174
|
|
|
63
|
-
|
|
64
|
-
export const Disabled: Story = {
|
|
175
|
+
export const DisabledState: Story = {
|
|
65
176
|
args: {
|
|
66
177
|
disabled: true,
|
|
67
178
|
},
|
|
179
|
+
parameters: {
|
|
180
|
+
docs: {
|
|
181
|
+
description: {
|
|
182
|
+
story: 'Disabled state of the Color Mode Toggle.',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
68
186
|
};
|
|
69
187
|
|
|
70
|
-
|
|
71
|
-
export const Controlled: Story = {
|
|
188
|
+
export const ControlledMode: Story = {
|
|
72
189
|
render: () => {
|
|
73
190
|
const [mode, setMode] = useState<ColorMode>('light');
|
|
74
191
|
return (
|
|
@@ -81,9 +198,15 @@ export const Controlled: Story = {
|
|
|
81
198
|
</div>
|
|
82
199
|
);
|
|
83
200
|
},
|
|
201
|
+
parameters: {
|
|
202
|
+
docs: {
|
|
203
|
+
description: {
|
|
204
|
+
story: 'Controlled mode example with external state management.',
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
},
|
|
84
208
|
};
|
|
85
209
|
|
|
86
|
-
// Custom Icons
|
|
87
210
|
export const CustomIcons: Story = {
|
|
88
211
|
render: () => (
|
|
89
212
|
<ColorModeToggle
|
|
@@ -91,71 +214,30 @@ export const CustomIcons: Story = {
|
|
|
91
214
|
darkIcon={<Sun size={24} weight="fill" />}
|
|
92
215
|
/>
|
|
93
216
|
),
|
|
217
|
+
parameters: {
|
|
218
|
+
docs: {
|
|
219
|
+
description: {
|
|
220
|
+
story: 'Color Mode Toggle with custom icons.',
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
},
|
|
94
224
|
};
|
|
95
225
|
|
|
96
|
-
// With Callback
|
|
97
226
|
export const WithCallback: Story = {
|
|
98
227
|
render: () => {
|
|
99
228
|
const [lastChanged, setLastChanged] = useState<string>('');
|
|
100
229
|
return (
|
|
101
230
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem', alignItems: 'center' }}>
|
|
102
|
-
<ColorModeToggle
|
|
103
|
-
|
|
104
|
-
/>
|
|
105
|
-
{lastChanged && <p style={{ fontSize: '0.875rem' }}>{lastChanged}</p>}
|
|
231
|
+
<ColorModeToggle onChange={(mode) => setLastChanged(`Mode changed to ${mode} at ${new Date().toLocaleTimeString()}`)} />
|
|
232
|
+
{lastChanged && <p>Last changed: {lastChanged}</p>}
|
|
106
233
|
</div>
|
|
107
234
|
);
|
|
108
235
|
},
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
dataAttribute: 'data-theme',
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// Without Storage
|
|
120
|
-
export const WithoutStorage: Story = {
|
|
121
|
-
args: {
|
|
122
|
-
disableStorage: true,
|
|
236
|
+
parameters: {
|
|
237
|
+
docs: {
|
|
238
|
+
description: {
|
|
239
|
+
story: 'Color Mode Toggle with change callback.',
|
|
240
|
+
},
|
|
241
|
+
},
|
|
123
242
|
},
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// Example Usage in Header
|
|
127
|
-
export const InHeader: Story = {
|
|
128
|
-
render: () => (
|
|
129
|
-
<div
|
|
130
|
-
className="u-p-5 u-shadow u-flex u-justify-between u-items-center"
|
|
131
|
-
style={{ width: '400px', borderRadius: '8px' }}
|
|
132
|
-
>
|
|
133
|
-
<span style={{ fontWeight: 600 }}>Toggle Theme</span>
|
|
134
|
-
<ColorModeToggle />
|
|
135
|
-
</div>
|
|
136
|
-
),
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// Multiple Toggles
|
|
140
|
-
export const MultipleToggles: Story = {
|
|
141
|
-
render: () => (
|
|
142
|
-
<div style={{ display: 'flex', gap: '2rem' }}>
|
|
143
|
-
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem', alignItems: 'center' }}>
|
|
144
|
-
<ColorModeToggle size="sm" />
|
|
145
|
-
<span style={{ fontSize: '0.75rem' }}>Small</span>
|
|
146
|
-
</div>
|
|
147
|
-
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem', alignItems: 'center' }}>
|
|
148
|
-
<ColorModeToggle size="md" />
|
|
149
|
-
<span style={{ fontSize: '0.75rem' }}>Medium</span>
|
|
150
|
-
</div>
|
|
151
|
-
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem', alignItems: 'center' }}>
|
|
152
|
-
<ColorModeToggle size="lg" />
|
|
153
|
-
<span style={{ fontSize: '0.75rem' }}>Large</span>
|
|
154
|
-
</div>
|
|
155
|
-
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem', alignItems: 'center' }}>
|
|
156
|
-
<ColorModeToggle disabled />
|
|
157
|
-
<span style={{ fontSize: '0.75rem' }}>Disabled</span>
|
|
158
|
-
</div>
|
|
159
|
-
</div>
|
|
160
|
-
),
|
|
161
|
-
};
|
|
243
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { fn } from '@storybook/test';
|
|
2
3
|
import { Countdown } from './Countdown';
|
|
3
4
|
|
|
4
5
|
const meta = {
|
|
@@ -6,16 +7,101 @@ const meta = {
|
|
|
6
7
|
component: Countdown,
|
|
7
8
|
parameters: {
|
|
8
9
|
layout: 'centered',
|
|
10
|
+
docs: {
|
|
11
|
+
description: {
|
|
12
|
+
component: `
|
|
13
|
+
# Countdown
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
The Countdown component displays a countdown timer to a specified target date. It shows days, hours, minutes, and seconds in a clean, customizable format. The component supports focusing on specific units, custom separators, and different visual styles.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- Configurable time units to display
|
|
22
|
+
- Customizable separator strings
|
|
23
|
+
- Focused visual style
|
|
24
|
+
- Automatic time calculation
|
|
25
|
+
- Accessible design
|
|
26
|
+
|
|
27
|
+
## Accessibility
|
|
28
|
+
|
|
29
|
+
- Screen reader: Time values are announced appropriately
|
|
30
|
+
- ARIA support: Proper roles and properties for time elements
|
|
31
|
+
- Focus management: Interactive elements maintain focus indicators
|
|
32
|
+
- Keyboard support: Accessible via keyboard navigation
|
|
33
|
+
|
|
34
|
+
## Usage Examples
|
|
35
|
+
|
|
36
|
+
### Basic Usage
|
|
37
|
+
|
|
38
|
+
\`\`\`tsx
|
|
39
|
+
<Countdown target={targetDate} />
|
|
40
|
+
\`\`\`
|
|
41
|
+
|
|
42
|
+
### With Specific Units
|
|
43
|
+
|
|
44
|
+
\`\`\`tsx
|
|
45
|
+
<Countdown
|
|
46
|
+
target={targetDate}
|
|
47
|
+
show={['hours', 'minutes', 'seconds']}
|
|
48
|
+
/>
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
## API Reference
|
|
52
|
+
|
|
53
|
+
### Props
|
|
54
|
+
|
|
55
|
+
| Prop | Type | Default | Description |
|
|
56
|
+
| ---- | ---- | ------- | ----------- |
|
|
57
|
+
| target | Date \\| number \\| string | - | Target date/time for the countdown |
|
|
58
|
+
| show | Array<'days' \\| 'hours' \\| 'minutes' \\| 'seconds'> | ['days', 'hours', 'minutes', 'seconds'] | Which time units to display |
|
|
59
|
+
| separator | string | ':' | String to separate time units |
|
|
60
|
+
| focused | boolean | false | Whether to apply focused visual style |
|
|
61
|
+
| onComplete | () => void | - | Callback when countdown completes |
|
|
62
|
+
| formatUnit | (unit: string, value: number) => string | - | Custom formatter for time units |
|
|
63
|
+
`,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
9
66
|
},
|
|
67
|
+
tags: ['autodocs'],
|
|
10
68
|
argTypes: {
|
|
11
|
-
target: {
|
|
69
|
+
target: {
|
|
70
|
+
control: 'date',
|
|
71
|
+
description: 'Target date/time for the countdown',
|
|
72
|
+
table: {
|
|
73
|
+
type: { summary: 'Date | number | string' },
|
|
74
|
+
defaultValue: { summary: '-' },
|
|
75
|
+
},
|
|
76
|
+
},
|
|
12
77
|
show: {
|
|
13
|
-
control: 'check',
|
|
14
|
-
options: ['days', 'hours', 'minutes', 'seconds'],
|
|
78
|
+
control: { type: 'check', options: ['days', 'hours', 'minutes', 'seconds'] },
|
|
15
79
|
description: 'Fields to show',
|
|
80
|
+
table: {
|
|
81
|
+
type: { summary: "Array<'days' | 'hours' | 'minutes' | 'seconds'>" },
|
|
82
|
+
defaultValue: { summary: "['days', 'hours', 'minutes', 'seconds']" },
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
separator: {
|
|
86
|
+
control: 'text',
|
|
87
|
+
description: 'Separator string',
|
|
88
|
+
table: {
|
|
89
|
+
type: { summary: 'string' },
|
|
90
|
+
defaultValue: { summary: ':' },
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
focused: {
|
|
94
|
+
control: 'boolean',
|
|
95
|
+
description: 'Focused style',
|
|
96
|
+
table: {
|
|
97
|
+
type: { summary: 'boolean' },
|
|
98
|
+
defaultValue: { summary: false },
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
onComplete: {
|
|
102
|
+
action: 'completed',
|
|
103
|
+
description: 'Callback when countdown completes',
|
|
16
104
|
},
|
|
17
|
-
separator: { control: 'text', description: 'Separator string' },
|
|
18
|
-
focused: { control: 'boolean', description: 'Focused style' },
|
|
19
105
|
},
|
|
20
106
|
} satisfies Meta<typeof Countdown>;
|
|
21
107
|
|
|
@@ -24,17 +110,31 @@ type Story = StoryObj<typeof meta>;
|
|
|
24
110
|
|
|
25
111
|
const futureDate = new Date(Date.now() + 1000 * 60 * 60 * 24 + 1000 * 60 * 45 + 1000 * 30); // 1d 45m 30s
|
|
26
112
|
|
|
27
|
-
export const
|
|
113
|
+
export const BasicUsage: Story = {
|
|
28
114
|
args: {
|
|
29
115
|
target: futureDate,
|
|
30
116
|
},
|
|
117
|
+
parameters: {
|
|
118
|
+
docs: {
|
|
119
|
+
description: {
|
|
120
|
+
story: 'Basic Countdown component with default settings.',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
31
124
|
};
|
|
32
125
|
|
|
33
|
-
export const
|
|
126
|
+
export const FocusedStyle: Story = {
|
|
34
127
|
args: {
|
|
35
128
|
target: futureDate,
|
|
36
129
|
focused: true,
|
|
37
130
|
},
|
|
131
|
+
parameters: {
|
|
132
|
+
docs: {
|
|
133
|
+
description: {
|
|
134
|
+
story: 'Countdown with focused visual style.',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
38
138
|
};
|
|
39
139
|
|
|
40
140
|
export const CustomSeparator: Story = {
|
|
@@ -43,4 +143,11 @@ export const CustomSeparator: Story = {
|
|
|
43
143
|
separator: ' | ',
|
|
44
144
|
show: ['hours', 'minutes', 'seconds'],
|
|
45
145
|
},
|
|
46
|
-
|
|
146
|
+
parameters: {
|
|
147
|
+
docs: {
|
|
148
|
+
description: {
|
|
149
|
+
story: 'Countdown with custom separator and specific units.',
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|