@roadlittledawn/docs-design-system-react 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Collapser.d.ts +20 -3
- package/dist/components/Collapser.js +10 -6
- package/dist/components/Collapser.stories.d.ts +33 -0
- package/dist/components/Collapser.stories.js +122 -2
- package/dist/components/CollapserGroup.d.ts +6 -0
- package/dist/components/CollapserGroup.js +4 -4
- package/dist/components/CollapserGroup.stories.d.ts +7 -0
- package/dist/components/CollapserGroup.stories.js +29 -0
- package/dist/styles.css +25 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
-
interface CollapserProps {
|
|
2
|
+
export interface CollapserProps {
|
|
3
3
|
/** Title text or element displayed in the collapsible header */
|
|
4
4
|
title: string | ReactNode;
|
|
5
5
|
/** Optional ID for the title element */
|
|
@@ -21,6 +21,23 @@ interface CollapserProps {
|
|
|
21
21
|
children: ReactNode;
|
|
22
22
|
/** Additional CSS classes */
|
|
23
23
|
className?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Alignment of the title within the header.
|
|
26
|
+
* Use 'right' for right-aligned titles, typically paired with an icon on the left.
|
|
27
|
+
* @default 'left'
|
|
28
|
+
*/
|
|
29
|
+
align?: 'left' | 'right';
|
|
30
|
+
/**
|
|
31
|
+
* Optional icon or React element rendered on the left side of the header,
|
|
32
|
+
* before the title text. Useful for visual identification of each section.
|
|
33
|
+
*/
|
|
34
|
+
icon?: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* Numeric step label shown on the far left of the header.
|
|
37
|
+
* Automatically injected by `CollapserGroup` when `numbered` is true;
|
|
38
|
+
* can also be set manually on individual collapsers.
|
|
39
|
+
* Use `--dds-collapser-step-number-color` to customise its colour.
|
|
40
|
+
*/
|
|
41
|
+
stepNumber?: number;
|
|
24
42
|
}
|
|
25
|
-
export declare function Collapser({ title, id, defaultOpen, open: controlledOpen, onToggle, children, className, }: CollapserProps): import("react/jsx-runtime").JSX.Element;
|
|
26
|
-
export {};
|
|
43
|
+
export declare function Collapser({ title, id, defaultOpen, open: controlledOpen, onToggle, children, className, align, icon, stepNumber, }: CollapserProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useRef, useEffect } from "react";
|
|
4
4
|
import { useKeyPress } from "../hooks/useKeyPress";
|
|
5
5
|
export function Collapser(_a) {
|
|
6
|
-
var title = _a.title, id = _a.id, _b = _a.defaultOpen, defaultOpen = _b === void 0 ? false : _b, controlledOpen = _a.open, onToggle = _a.onToggle, children = _a.children, _c = _a.className, className = _c === void 0 ? "" : _c;
|
|
7
|
-
var
|
|
6
|
+
var title = _a.title, id = _a.id, _b = _a.defaultOpen, defaultOpen = _b === void 0 ? false : _b, controlledOpen = _a.open, onToggle = _a.onToggle, children = _a.children, _c = _a.className, className = _c === void 0 ? "" : _c, _d = _a.align, align = _d === void 0 ? 'left' : _d, icon = _a.icon, stepNumber = _a.stepNumber;
|
|
7
|
+
var _e = useState(defaultOpen), uncontrolledOpen = _e[0], setUncontrolledOpen = _e[1];
|
|
8
8
|
var isControlled = controlledOpen !== undefined;
|
|
9
9
|
var isOpen = isControlled ? controlledOpen : uncontrolledOpen;
|
|
10
|
-
var
|
|
10
|
+
var _f = useState(undefined), height = _f[0], setHeight = _f[1];
|
|
11
11
|
var contentRef = useRef(null);
|
|
12
12
|
// Keyboard shortcuts: 's' or 'f' to show, 'h' to hide
|
|
13
13
|
useKeyPress(['s', 'f', 'h'], function (e) {
|
|
@@ -28,10 +28,14 @@ export function Collapser(_a) {
|
|
|
28
28
|
setUncontrolledOpen(!uncontrolledOpen);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
var collapserClasses = [
|
|
31
|
+
var collapserClasses = [
|
|
32
|
+
"dds-collapser",
|
|
33
|
+
align === 'right' ? "dds-collapser--align-right" : "",
|
|
34
|
+
className,
|
|
35
|
+
]
|
|
32
36
|
.filter(Boolean)
|
|
33
37
|
.join(" ");
|
|
34
|
-
return (_jsxs("div", { className: collapserClasses, children: [_jsxs("button", { onClick: toggleOpen, type: "button", className: "dds-collapser-button", "aria-expanded": isOpen, children: [_jsx("h5", { id: id, className: "dds-collapser-title", children: title }), _jsx("svg", { className: "dds-collapser-icon ".concat(isOpen ? "dds-collapser-icon-open" : ""), width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("polyline", { points: "6 9 12 15 18 9" }) })] }), _jsx("div", { className: "dds-collapser-content-wrapper", style: {
|
|
38
|
+
return (_jsxs("div", { className: collapserClasses, children: [_jsxs("button", { onClick: toggleOpen, type: "button", className: "dds-collapser-button", "aria-expanded": isOpen, children: [stepNumber !== undefined && (_jsxs("span", { className: "dds-collapser-step-number", children: [stepNumber, "."] })), icon && (_jsx("span", { className: "dds-collapser-header-icon", "aria-hidden": "true", children: icon })), _jsx("h5", { id: id, className: "dds-collapser-title", children: title }), _jsx("svg", { className: "dds-collapser-icon ".concat(isOpen ? "dds-collapser-icon-open" : ""), width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("polyline", { points: "6 9 12 15 18 9" }) })] }), _jsx("div", { className: "dds-collapser-content-wrapper", style: {
|
|
35
39
|
height: isOpen ? height : 0,
|
|
36
40
|
}, children: _jsx("div", { ref: contentRef, className: "dds-collapser-content", children: children }) })] }));
|
|
37
41
|
}
|
|
@@ -18,11 +18,44 @@ export declare const DefaultOpen: Story;
|
|
|
18
18
|
* Collapser with an ID for the title.
|
|
19
19
|
*/
|
|
20
20
|
export declare const WithID: Story;
|
|
21
|
+
/**
|
|
22
|
+
* Collapser with an icon rendered on the left side of the header.
|
|
23
|
+
* The icon prop accepts any React element — use your own icon component or SVG.
|
|
24
|
+
*/
|
|
25
|
+
export declare const WithIcon: Story;
|
|
26
|
+
/**
|
|
27
|
+
* Collapser with the title right-aligned within the header.
|
|
28
|
+
* Use this for design layouts where the title should appear on the right
|
|
29
|
+
* and content (such as a step number or icon) anchors the left.
|
|
30
|
+
*/
|
|
31
|
+
export declare const RightAligned: Story;
|
|
32
|
+
/**
|
|
33
|
+
* Collapser with both an icon and right-aligned title — matching the
|
|
34
|
+
* reference screenshot layout where an icon anchors the left and the
|
|
35
|
+
* title text flows to the right before the chevron.
|
|
36
|
+
*/
|
|
37
|
+
export declare const WithIconRightAligned: Story;
|
|
21
38
|
/**
|
|
22
39
|
* Collapser containing complex content.
|
|
23
40
|
*/
|
|
24
41
|
export declare const ComplexContent: Story;
|
|
42
|
+
/**
|
|
43
|
+
* Shows all four header layout variants side-by-side for visual comparison:
|
|
44
|
+
* default left-aligned, left-aligned with icon, right-aligned, and right-aligned with icon.
|
|
45
|
+
*/
|
|
46
|
+
export declare const AllVariants: Story;
|
|
25
47
|
/**
|
|
26
48
|
* Multiple collapsers in a FAQ-style layout using CollapserGroup.
|
|
27
49
|
*/
|
|
28
50
|
export declare const FAQExample: Story;
|
|
51
|
+
/**
|
|
52
|
+
* Example matching the reference screenshot: collapsers in a group where each
|
|
53
|
+
* has a distinct icon on the left and right-aligned title text.
|
|
54
|
+
*/
|
|
55
|
+
export declare const IconGroupExample: Story;
|
|
56
|
+
/**
|
|
57
|
+
* CollapserGroup with `numbered` auto-numbers each entry.
|
|
58
|
+
* Matches the reference screenshot pattern: step number + icon on the left,
|
|
59
|
+
* title right-aligned, chevron on the far right.
|
|
60
|
+
*/
|
|
61
|
+
export declare const NumberedGroup: Story;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Collapser } from './Collapser';
|
|
3
3
|
import { CollapserGroup } from './CollapserGroup';
|
|
4
|
+
// Spoofed icon components for demonstration purposes
|
|
5
|
+
// (replace with your own Icon component when available)
|
|
6
|
+
var IconBook = function () { return (_jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M4 19.5A2.5 2.5 0 0 1 6.5 17H20" }), _jsx("path", { d: "M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z" })] })); };
|
|
7
|
+
var IconBolt = function () { return (_jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("polyline", { points: "13 2 3 14 12 14 11 22 21 10 12 10 13 2" }) })); };
|
|
8
|
+
var IconStar = function () { return (_jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("polygon", { points: "12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" }) })); };
|
|
9
|
+
var IconSettings = function () { return (_jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "3" }), _jsx("path", { d: "M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" })] })); };
|
|
4
10
|
/**
|
|
5
11
|
* The Collapser component creates expandable/collapsible content sections with smooth animations.
|
|
6
12
|
*/
|
|
@@ -22,6 +28,20 @@ var meta = {
|
|
|
22
28
|
description: 'Whether the collapser should be open by default (uncontrolled mode).',
|
|
23
29
|
table: { defaultValue: { summary: 'false' } },
|
|
24
30
|
},
|
|
31
|
+
align: {
|
|
32
|
+
control: 'radio',
|
|
33
|
+
options: ['left', 'right'],
|
|
34
|
+
description: "Alignment of the title within the header. Use 'right' for right-aligned titles, typically paired with an icon on the left.",
|
|
35
|
+
table: { defaultValue: { summary: 'left' } },
|
|
36
|
+
},
|
|
37
|
+
icon: {
|
|
38
|
+
control: false,
|
|
39
|
+
description: 'Optional icon or React element rendered on the left side of the header, before the title text.',
|
|
40
|
+
},
|
|
41
|
+
stepNumber: {
|
|
42
|
+
control: 'number',
|
|
43
|
+
description: 'Numeric step label shown on the far left. Auto-injected by `CollapserGroup` when `numbered` is true. Colour controlled via `--dds-collapser-step-number-color`.',
|
|
44
|
+
},
|
|
25
45
|
children: {
|
|
26
46
|
control: false,
|
|
27
47
|
description: 'Content to show/hide when toggling.',
|
|
@@ -35,7 +55,7 @@ var meta = {
|
|
|
35
55
|
parameters: {
|
|
36
56
|
docs: {
|
|
37
57
|
description: {
|
|
38
|
-
component: "\nThe Collapser component allows users to show and hide content sections to reduce visual clutter.\n\n## When to Use\n\n- For FAQ sections where answers can be toggled\n- To hide advanced options or detailed information\n- For progressive disclosure of content\n- When you have lengthy content that doesn't need to be visible all the time\n\n## When Not to Use\n\n- For primary navigation (use proper navigation components)\n- For critical information that should always be visible\n- When most users will need to expand all sections (just show the content)\n\n## Accessibility\n\n- Uses proper ARIA attributes (aria-expanded)\n- Keyboard accessible with Enter and Space keys\n- Supports additional keyboard shortcuts: 's' or 'f' to show, 'h' to hide\n- Screen reader friendly\n\n## Keyboard Shortcuts\n\n- **s** or **f**: Show/expand the content\n- **h**: Hide/collapse the content\n- **Enter** or **Space**: Toggle expand/collapse\n ",
|
|
58
|
+
component: "\nThe Collapser component allows users to show and hide content sections to reduce visual clutter.\n\n## When to Use\n\n- For FAQ sections where answers can be toggled\n- To hide advanced options or detailed information\n- For progressive disclosure of content\n- When you have lengthy content that doesn't need to be visible all the time\n\n## When Not to Use\n\n- For primary navigation (use proper navigation components)\n- For critical information that should always be visible\n- When most users will need to expand all sections (just show the content)\n\n## Accessibility\n\n- Uses proper ARIA attributes (aria-expanded)\n- Keyboard accessible with Enter and Space keys\n- Supports additional keyboard shortcuts: 's' or 'f' to show, 'h' to hide\n- Screen reader friendly\n- Icons passed via the `icon` prop should be wrapped in a container with `aria-hidden=\"true\"` since the title provides the accessible label\n\n## Keyboard Shortcuts\n\n- **s** or **f**: Show/expand the content\n- **h**: Hide/collapse the content\n- **Enter** or **Space**: Toggle expand/collapse\n\n## Customising Step Numbers\n\nOverride the CSS custom property to change the step number colour:\n\n```css\n.my-steps {\n --dds-collapser-step-number-color: #7c3aed;\n}\n```\n ",
|
|
39
59
|
},
|
|
40
60
|
},
|
|
41
61
|
},
|
|
@@ -91,6 +111,63 @@ export var WithID = {
|
|
|
91
111
|
},
|
|
92
112
|
},
|
|
93
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Collapser with an icon rendered on the left side of the header.
|
|
116
|
+
* The icon prop accepts any React element — use your own icon component or SVG.
|
|
117
|
+
*/
|
|
118
|
+
export var WithIcon = {
|
|
119
|
+
args: {
|
|
120
|
+
title: 'Documentation guides',
|
|
121
|
+
icon: _jsx(IconBook, {}),
|
|
122
|
+
children: (_jsxs("p", { style: { color: 'var(--dds-collapser-text)' }, children: ["Icons help users quickly identify sections at a glance. Pass any React element to the ", _jsx("code", { children: "icon" }), " prop to display it on the left side of the header."] })),
|
|
123
|
+
},
|
|
124
|
+
parameters: {
|
|
125
|
+
docs: {
|
|
126
|
+
source: {
|
|
127
|
+
code: "<Collapser title=\"Documentation guides\" icon={<IconBook />}>\n <p>\n Icons help users quickly identify sections at a glance. Pass any React\n element to the icon prop to display it on the left side of the header.\n </p>\n</Collapser>",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Collapser with the title right-aligned within the header.
|
|
134
|
+
* Use this for design layouts where the title should appear on the right
|
|
135
|
+
* and content (such as a step number or icon) anchors the left.
|
|
136
|
+
*/
|
|
137
|
+
export var RightAligned = {
|
|
138
|
+
args: {
|
|
139
|
+
title: 'Right-aligned title',
|
|
140
|
+
align: 'right',
|
|
141
|
+
children: (_jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "The title is right-aligned in the header, with the chevron remaining on the far right. Long titles will wrap to a new line on small screens rather than colliding with other elements." })),
|
|
142
|
+
},
|
|
143
|
+
parameters: {
|
|
144
|
+
docs: {
|
|
145
|
+
source: {
|
|
146
|
+
code: "<Collapser title=\"Right-aligned title\" align=\"right\">\n <p>\n The title is right-aligned in the header, with the chevron remaining on\n the far right.\n </p>\n</Collapser>",
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Collapser with both an icon and right-aligned title — matching the
|
|
153
|
+
* reference screenshot layout where an icon anchors the left and the
|
|
154
|
+
* title text flows to the right before the chevron.
|
|
155
|
+
*/
|
|
156
|
+
export var WithIconRightAligned = {
|
|
157
|
+
args: {
|
|
158
|
+
title: 'Quick start guide',
|
|
159
|
+
align: 'right',
|
|
160
|
+
icon: _jsx(IconBolt, {}),
|
|
161
|
+
children: (_jsxs("p", { style: { color: 'var(--dds-collapser-text)' }, children: ["Combining ", _jsx("code", { children: "icon" }), " and ", _jsx("code", { children: "align=\"right\"" }), " produces a layout where the icon anchors the left edge, the title flows to the right, and the chevron stays at the far right."] })),
|
|
162
|
+
},
|
|
163
|
+
parameters: {
|
|
164
|
+
docs: {
|
|
165
|
+
source: {
|
|
166
|
+
code: "<Collapser title=\"Quick start guide\" align=\"right\" icon={<IconBolt />}>\n <p>\n Combining icon and align=\"right\" produces a layout where the icon anchors\n the left edge, the title flows to the right, and the chevron stays at the far right.\n </p>\n</Collapser>",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
};
|
|
94
171
|
/**
|
|
95
172
|
* Collapser containing complex content.
|
|
96
173
|
*/
|
|
@@ -107,6 +184,20 @@ export var ComplexContent = {
|
|
|
107
184
|
},
|
|
108
185
|
},
|
|
109
186
|
};
|
|
187
|
+
/**
|
|
188
|
+
* Shows all four header layout variants side-by-side for visual comparison:
|
|
189
|
+
* default left-aligned, left-aligned with icon, right-aligned, and right-aligned with icon.
|
|
190
|
+
*/
|
|
191
|
+
export var AllVariants = {
|
|
192
|
+
parameters: {
|
|
193
|
+
docs: {
|
|
194
|
+
source: {
|
|
195
|
+
code: "{/* Left-aligned (default) */}\n<Collapser title=\"Left-aligned (default)\">\n <p>The standard layout \u2014 title on the left, chevron on the right.</p>\n</Collapser>\n\n{/* Left-aligned with icon */}\n<Collapser title=\"Left-aligned with icon\" icon={<IconBook />}>\n <p>An icon appears to the left of the title.</p>\n</Collapser>\n\n{/* Right-aligned */}\n<Collapser title=\"Right-aligned title\" align=\"right\">\n <p>Title text flows to the right. Chevron stays at the far right.</p>\n</Collapser>\n\n{/* Right-aligned with icon */}\n<Collapser title=\"Right-aligned with icon\" align=\"right\" icon={<IconBolt />}>\n <p>Icon anchors the left, title flows right, chevron at the far right.</p>\n</Collapser>",
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
render: function () { return (_jsxs("div", { children: [_jsx(Collapser, { title: "Left-aligned (default)", children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "The standard layout \u2014 title on the left, chevron on the right." }) }), _jsx(Collapser, { title: "Left-aligned with icon", icon: _jsx(IconBook, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "An icon appears to the left of the title." }) }), _jsx(Collapser, { title: "Right-aligned title", align: "right", children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Title text flows to the right. Chevron stays at the far right." }) }), _jsx(Collapser, { title: "Right-aligned with icon", align: "right", icon: _jsx(IconBolt, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Icon anchors the left, title flows right, chevron at the far right." }) })] })); },
|
|
200
|
+
};
|
|
110
201
|
/**
|
|
111
202
|
* Multiple collapsers in a FAQ-style layout using CollapserGroup.
|
|
112
203
|
*/
|
|
@@ -118,5 +209,34 @@ export var FAQExample = {
|
|
|
118
209
|
},
|
|
119
210
|
},
|
|
120
211
|
},
|
|
121
|
-
render: function () { return (_jsxs(CollapserGroup, { children: [_jsx(Collapser, { title: "What is this documentation system?", children: _jsx("p", { children: "This is a comprehensive documentation design system that provides reusable components and guidelines for creating effective technical documentation." }) }), _jsx(Collapser, { title: "How do I get started?", children: _jsx("p", { children: "Start by installing the component package, then explore the components in Storybook to understand their usage and configuration options." }) }), _jsx(Collapser, { title: "Can I customize the components?", children: _jsx("p", { children: "Yes! All components accept a className prop for custom styling, and you can override the default styles using CSS." }) }), _jsx(Collapser, { title: "Is this accessible?", children: _jsx("p", { children: "Accessibility is a core principle. All components follow WAI-ARIA best practices and are keyboard navigable." }) })] })); },
|
|
212
|
+
render: function () { return (_jsxs(CollapserGroup, { children: [_jsx(Collapser, { title: "What is this documentation system?", children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "This is a comprehensive documentation design system that provides reusable components and guidelines for creating effective technical documentation." }) }), _jsx(Collapser, { title: "How do I get started?", children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Start by installing the component package, then explore the components in Storybook to understand their usage and configuration options." }) }), _jsx(Collapser, { title: "Can I customize the components?", children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Yes! All components accept a className prop for custom styling, and you can override the default styles using CSS." }) }), _jsx(Collapser, { title: "Is this accessible?", children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Accessibility is a core principle. All components follow WAI-ARIA best practices and are keyboard navigable." }) })] })); },
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Example matching the reference screenshot: collapsers in a group where each
|
|
216
|
+
* has a distinct icon on the left and right-aligned title text.
|
|
217
|
+
*/
|
|
218
|
+
export var IconGroupExample = {
|
|
219
|
+
parameters: {
|
|
220
|
+
docs: {
|
|
221
|
+
source: {
|
|
222
|
+
code: "<CollapserGroup>\n <Collapser title=\"Getting started\" align=\"right\" icon={<IconBook />}>\n <p>Learn the basics and set up your environment.</p>\n </Collapser>\n <Collapser title=\"Quick actions\" align=\"right\" icon={<IconBolt />}>\n <p>Discover shortcuts and power-user features.</p>\n </Collapser>\n <Collapser title=\"Highlights\" align=\"right\" icon={<IconStar />}>\n <p>See what makes this system stand out.</p>\n </Collapser>\n <Collapser title=\"Configuration\" align=\"right\" icon={<IconSettings />}>\n <p>Customise the system to fit your workflow.</p>\n </Collapser>\n</CollapserGroup>",
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
render: function () { return (_jsxs(CollapserGroup, { children: [_jsx(Collapser, { title: "Getting started", align: "right", icon: _jsx(IconBook, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Learn the basics and set up your environment." }) }), _jsx(Collapser, { title: "Quick actions", align: "right", icon: _jsx(IconBolt, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Discover shortcuts and power-user features." }) }), _jsx(Collapser, { title: "Highlights", align: "right", icon: _jsx(IconStar, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "See what makes this system stand out." }) }), _jsx(Collapser, { title: "Configuration", align: "right", icon: _jsx(IconSettings, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Customise the system to fit your workflow." }) })] })); },
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* CollapserGroup with `numbered` auto-numbers each entry.
|
|
230
|
+
* Matches the reference screenshot pattern: step number + icon on the left,
|
|
231
|
+
* title right-aligned, chevron on the far right.
|
|
232
|
+
*/
|
|
233
|
+
export var NumberedGroup = {
|
|
234
|
+
parameters: {
|
|
235
|
+
docs: {
|
|
236
|
+
source: {
|
|
237
|
+
code: "{/* numbered=true on CollapserGroup auto-injects stepNumber into each child */}\n<CollapserGroup numbered>\n <Collapser title=\"Decrease pain\" align=\"right\" icon={<IconBolt />}>\n <p>Step numbers are injected automatically by CollapserGroup.</p>\n </Collapser>\n <Collapser title=\"Align your workflow\" align=\"right\" icon={<IconBook />}>\n <p>Combine numbered with icons and right-aligned titles.</p>\n </Collapser>\n <Collapser title=\"Learn to move\" align=\"right\" icon={<IconStar />}>\n <p>Each entry gets a sequential step number on the far left.</p>\n </Collapser>\n <Collapser title=\"Configuration\" align=\"right\" icon={<IconSettings />}>\n <p>Customise the system to fit your workflow.</p>\n </Collapser>\n</CollapserGroup>",
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
render: function () { return (_jsxs(CollapserGroup, { numbered: true, children: [_jsx(Collapser, { title: "Decrease pain", align: "right", icon: _jsx(IconBolt, {}), children: _jsxs("p", { style: { color: 'var(--dds-collapser-text)' }, children: ["Step numbers are injected automatically by CollapserGroup when", ' ', _jsx("code", { children: "numbered" }), " is true."] }) }), _jsx(Collapser, { title: "Align your workflow", align: "right", icon: _jsx(IconBook, {}), children: _jsxs("p", { style: { color: 'var(--dds-collapser-text)' }, children: ["Combine ", _jsx("code", { children: "numbered" }), " with icons and right-aligned titles for a clean annotated-list layout."] }) }), _jsx(Collapser, { title: "Learn to move", align: "right", icon: _jsx(IconStar, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Each entry gets a sequential step number on the far left." }) }), _jsx(Collapser, { title: "Configuration", align: "right", icon: _jsx(IconSettings, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Customise the system to fit your workflow." }) })] })); },
|
|
122
242
|
};
|
|
@@ -11,5 +11,11 @@ export interface CollapserGroupProps {
|
|
|
11
11
|
onChange?: (openIndexes: number[]) => void;
|
|
12
12
|
/** Additional CSS classes */
|
|
13
13
|
className?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Automatically prefix each collapser header with a sequential step number (1, 2, 3…).
|
|
16
|
+
* The number is injected via the `stepNumber` prop on each `Collapser` child.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
numbered?: boolean;
|
|
14
20
|
}
|
|
15
21
|
export declare const CollapserGroup: React.FC<CollapserGroupProps>;
|
|
@@ -23,12 +23,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
23
23
|
import { useState, Children, cloneElement, isValidElement } from 'react';
|
|
24
24
|
import { Collapser } from './Collapser';
|
|
25
25
|
export var CollapserGroup = function (_a) {
|
|
26
|
-
var children = _a.children, _b = _a.spacing, spacing = _b === void 0 ? '0.5rem' : _b, _c = _a.allowMultiple, allowMultiple = _c === void 0 ? true : _c, defaultOpen = _a.defaultOpen, onChange = _a.onChange, _d = _a.className, className = _d === void 0 ? '' : _d;
|
|
27
|
-
var
|
|
26
|
+
var children = _a.children, _b = _a.spacing, spacing = _b === void 0 ? '0.5rem' : _b, _c = _a.allowMultiple, allowMultiple = _c === void 0 ? true : _c, defaultOpen = _a.defaultOpen, onChange = _a.onChange, _d = _a.className, className = _d === void 0 ? '' : _d, _e = _a.numbered, numbered = _e === void 0 ? false : _e;
|
|
27
|
+
var _f = useState(function () {
|
|
28
28
|
if (defaultOpen === undefined)
|
|
29
29
|
return [];
|
|
30
30
|
return Array.isArray(defaultOpen) ? defaultOpen : [defaultOpen];
|
|
31
|
-
}), openIndexes =
|
|
31
|
+
}), openIndexes = _f[0], setOpenIndexes = _f[1];
|
|
32
32
|
var handleToggle = function (index) {
|
|
33
33
|
setOpenIndexes(function (prev) {
|
|
34
34
|
var next;
|
|
@@ -49,7 +49,7 @@ export var CollapserGroup = function (_a) {
|
|
|
49
49
|
return child;
|
|
50
50
|
// Only inject props if child is a Collapser component
|
|
51
51
|
if (child.type === Collapser) {
|
|
52
|
-
return cloneElement(child, __assign(__assign({}, child.props), { open: openIndexes.includes(index), onToggle: function () { return handleToggle(index); } }));
|
|
52
|
+
return cloneElement(child, __assign(__assign(__assign({}, child.props), { open: openIndexes.includes(index), onToggle: function () { return handleToggle(index); } }), (numbered ? { stepNumber: index + 1 } : {})));
|
|
53
53
|
}
|
|
54
54
|
return child;
|
|
55
55
|
}) }));
|
|
@@ -27,3 +27,10 @@ export declare const DefaultOpen: Story;
|
|
|
27
27
|
* Multiple collapsers open by default.
|
|
28
28
|
*/
|
|
29
29
|
export declare const MultipleDefaultOpen: Story;
|
|
30
|
+
/**
|
|
31
|
+
* Setting `numbered` on CollapserGroup automatically prefixes each collapser header
|
|
32
|
+
* with a sequential step number (1., 2., …), closely matching the reference screenshot
|
|
33
|
+
* with number + icon on the left and right-aligned title text.
|
|
34
|
+
* Customise the number colour with `--dds-collapser-step-number-color`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const NumberedGroup: Story;
|
|
@@ -12,6 +12,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { CollapserGroup } from './CollapserGroup';
|
|
14
14
|
import { Collapser } from './Collapser';
|
|
15
|
+
// Spoofed icons for the NumberedGroup story (replace with your Icon component when available)
|
|
16
|
+
var IconBolt = function () { return (_jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("polyline", { points: "13 2 3 14 12 14 11 22 21 10 12 10 13 2" }) })); };
|
|
17
|
+
var IconBook = function () { return (_jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M4 19.5A2.5 2.5 0 0 1 6.5 17H20" }), _jsx("path", { d: "M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z" })] })); };
|
|
18
|
+
var IconStar = function () { return (_jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("polygon", { points: "12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" }) })); };
|
|
19
|
+
var IconSettings = function () { return (_jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "3" }), _jsx("path", { d: "M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" })] })); };
|
|
15
20
|
/**
|
|
16
21
|
* CollapserGroup manages multiple Collapser components with consistent spacing
|
|
17
22
|
* and optional accordion behavior.
|
|
@@ -48,6 +53,11 @@ var meta = {
|
|
|
48
53
|
description: 'Additional CSS classes.',
|
|
49
54
|
table: { defaultValue: { summary: '""' } },
|
|
50
55
|
},
|
|
56
|
+
numbered: {
|
|
57
|
+
control: 'boolean',
|
|
58
|
+
description: 'Automatically prefix each collapser header with a sequential step number (1, 2, 3…). Pairs well with `icon` and `align="right"` on child collapsers.',
|
|
59
|
+
table: { defaultValue: { summary: 'false' } },
|
|
60
|
+
},
|
|
51
61
|
},
|
|
52
62
|
parameters: {
|
|
53
63
|
docs: {
|
|
@@ -139,3 +149,22 @@ export var MultipleDefaultOpen = {
|
|
|
139
149
|
},
|
|
140
150
|
render: function (args) { return (_jsxs(CollapserGroup, __assign({}, args, { children: [_jsx(Collapser, { title: "Introduction", children: _jsx("p", { children: "This section is open by default." }) }), _jsx(Collapser, { title: "Installation", children: _jsx("p", { children: "This section starts closed." }) }), _jsx(Collapser, { title: "Quick Start", children: _jsx("p", { children: "This section is also open by default." }) })] }))); },
|
|
141
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* Setting `numbered` on CollapserGroup automatically prefixes each collapser header
|
|
154
|
+
* with a sequential step number (1., 2., …), closely matching the reference screenshot
|
|
155
|
+
* with number + icon on the left and right-aligned title text.
|
|
156
|
+
* Customise the number colour with `--dds-collapser-step-number-color`.
|
|
157
|
+
*/
|
|
158
|
+
export var NumberedGroup = {
|
|
159
|
+
args: {
|
|
160
|
+
numbered: true,
|
|
161
|
+
},
|
|
162
|
+
parameters: {
|
|
163
|
+
docs: {
|
|
164
|
+
source: {
|
|
165
|
+
code: "<CollapserGroup numbered>\n <Collapser title=\"Decrease pain\" align=\"right\" icon={<IconBolt />}>\n <p>Step numbers are injected automatically \u2014 no extra props needed on each item.</p>\n </Collapser>\n <Collapser title=\"Align your workflow\" align=\"right\" icon={<IconBook />}>\n <p>Combine numbered with icons and right-aligned titles.</p>\n </Collapser>\n <Collapser title=\"Learn to move\" align=\"right\" icon={<IconStar />}>\n <p>Each entry gets a sequential step number on the far left.</p>\n </Collapser>\n <Collapser title=\"Build strength\" align=\"right\" icon={<IconSettings />}>\n <p>Customise the number colour with --dds-collapser-step-number-color.</p>\n </Collapser>\n</CollapserGroup>",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
render: function (args) { return (_jsxs(CollapserGroup, __assign({}, args, { children: [_jsx(Collapser, { title: "Decrease pain", align: "right", icon: _jsx(IconBolt, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Step numbers are injected automatically \u2014 no extra props needed on each item." }) }), _jsx(Collapser, { title: "Align your workflow", align: "right", icon: _jsx(IconBook, {}), children: _jsxs("p", { style: { color: 'var(--dds-collapser-text)' }, children: ["Combine ", _jsx("code", { children: "numbered" }), " with icons and right-aligned titles for a clean annotated-list layout."] }) }), _jsx(Collapser, { title: "Learn to move", align: "right", icon: _jsx(IconStar, {}), children: _jsx("p", { style: { color: 'var(--dds-collapser-text)' }, children: "Each entry gets a sequential step number on the far left." }) }), _jsx(Collapser, { title: "Build strength", align: "right", icon: _jsx(IconSettings, {}), children: _jsxs("p", { style: { color: 'var(--dds-collapser-text)' }, children: ["Customise the number colour with ", _jsx("code", { children: "--dds-collapser-step-number-color" }), "."] }) })] }))); },
|
|
170
|
+
};
|
package/dist/styles.css
CHANGED
|
@@ -207,8 +207,10 @@
|
|
|
207
207
|
--dds-collapser-button-padding: 0.75rem; /* p-3 */
|
|
208
208
|
--dds-collapser-button-hover-bg: #f9fafb; /* gray-50 */
|
|
209
209
|
--dds-collapser-icon-color: #6b7280; /* gray-500 */
|
|
210
|
+
--dds-collapser-step-number-color: #6b7280; /* gray-500 — override to customise step numbers */
|
|
210
211
|
--dds-collapser-text: #374151; /* gray-700 */
|
|
211
212
|
--dds-collapser-content-padding: 1rem; /* p-4 */
|
|
213
|
+
--dds-collapser-header-gap: 0.5rem;
|
|
212
214
|
|
|
213
215
|
/* Tabs */
|
|
214
216
|
--dds-tabs-margin: 1rem 0;
|
|
@@ -342,6 +344,7 @@
|
|
|
342
344
|
--dds-collapser-border: #4b5563; /* gray-600 */
|
|
343
345
|
--dds-collapser-button-hover-bg: rgba(255, 255, 255, 0.05);
|
|
344
346
|
--dds-collapser-icon-color: #9ca3af; /* gray-400 */
|
|
347
|
+
--dds-collapser-step-number-color: #9ca3af;
|
|
345
348
|
--dds-collapser-text: #e5e7eb; /* gray-200 */
|
|
346
349
|
|
|
347
350
|
/* Tabs */
|
|
@@ -497,6 +500,7 @@
|
|
|
497
500
|
--dds-collapser-border: #4b5563;
|
|
498
501
|
--dds-collapser-button-hover-bg: rgba(255, 255, 255, 0.05);
|
|
499
502
|
--dds-collapser-icon-color: #9ca3af;
|
|
503
|
+
--dds-collapser-step-number-color: #9ca3af;
|
|
500
504
|
--dds-collapser-text: #e5e7eb;
|
|
501
505
|
|
|
502
506
|
/* Tabs */
|
|
@@ -652,6 +656,7 @@
|
|
|
652
656
|
--dds-collapser-border: #4b5563;
|
|
653
657
|
--dds-collapser-button-hover-bg: rgba(255, 255, 255, 0.05);
|
|
654
658
|
--dds-collapser-icon-color: #9ca3af;
|
|
659
|
+
--dds-collapser-step-number-color: #9ca3af;
|
|
655
660
|
--dds-collapser-text: #e5e7eb;
|
|
656
661
|
|
|
657
662
|
/* CodeBlock */
|
|
@@ -1101,6 +1106,7 @@ a.no-text-decoration {
|
|
|
1101
1106
|
padding: var(--dds-collapser-button-padding);
|
|
1102
1107
|
display: flex;
|
|
1103
1108
|
align-items: center;
|
|
1109
|
+
gap: var(--dds-collapser-header-gap);
|
|
1104
1110
|
transition: var(--dds-transition-colors);
|
|
1105
1111
|
border: none;
|
|
1106
1112
|
background: transparent;
|
|
@@ -1112,6 +1118,18 @@ a.no-text-decoration {
|
|
|
1112
1118
|
background-color: var(--dds-collapser-button-hover-bg);
|
|
1113
1119
|
outline: none;
|
|
1114
1120
|
}
|
|
1121
|
+
.dds-collapser-step-number {
|
|
1122
|
+
flex-shrink: 0;
|
|
1123
|
+
min-width: 1.5em;
|
|
1124
|
+
font-variant-numeric: tabular-nums;
|
|
1125
|
+
color: var(--dds-collapser-step-number-color);
|
|
1126
|
+
}
|
|
1127
|
+
.dds-collapser-header-icon {
|
|
1128
|
+
display: flex;
|
|
1129
|
+
align-items: center;
|
|
1130
|
+
flex-shrink: 0;
|
|
1131
|
+
color: var(--dds-collapser-icon-color);
|
|
1132
|
+
}
|
|
1115
1133
|
.dds-collapser-title {
|
|
1116
1134
|
display: flex;
|
|
1117
1135
|
align-items: center;
|
|
@@ -1120,12 +1138,18 @@ a.no-text-decoration {
|
|
|
1120
1138
|
margin: 0;
|
|
1121
1139
|
font-weight: bold;
|
|
1122
1140
|
color: var(--dds-heading-color);
|
|
1141
|
+
word-break: break-word;
|
|
1142
|
+
min-width: 0;
|
|
1143
|
+
}
|
|
1144
|
+
.dds-collapser--align-right .dds-collapser-title {
|
|
1145
|
+
justify-content: flex-end;
|
|
1146
|
+
text-align: right;
|
|
1123
1147
|
}
|
|
1124
1148
|
.dds-collapser-icon {
|
|
1125
1149
|
margin-left: auto;
|
|
1150
|
+
flex-shrink: 0;
|
|
1126
1151
|
transition: transform 0.3s ease;
|
|
1127
1152
|
color: var(--dds-collapser-icon-color);
|
|
1128
|
-
flex-shrink: 0;
|
|
1129
1153
|
}
|
|
1130
1154
|
.dds-collapser-icon-open {
|
|
1131
1155
|
transform: rotate(180deg);
|