@buildkitgg/storybook-config 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +57 -2
- package/dist/ExampleFrame.d.ts +15 -0
- package/dist/ExampleFrame.js +8 -0
- package/dist/examples.css +230 -0
- package/dist/main.d.ts +20 -0
- package/dist/main.js +32 -0
- package/dist/preview.d.ts +24 -0
- package/dist/preview.js +29 -0
- package/dist/utils/merge.d.ts +2 -0
- package/dist/utils/merge.js +36 -0
- package/package.json +66 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrew Craswell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @buildkitgg/storybook-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared Storybook configuration for React and Vite: a base `main` config with the Chromatic, accessibility and Vitest
|
|
4
|
+
addons, a base preview, and frames that give example stories a consistent layout.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
pnpm add -D @buildkitgg/storybook-config storybook @storybook/react-vite
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Main config
|
|
11
|
+
|
|
12
|
+
`defineMain` merges your config onto the base. Arrays such as `addons` are concatenated and objects are merged deeply,
|
|
13
|
+
so add only what your Storybook needs:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// .storybook/main.ts
|
|
17
|
+
import { defineMain } from "@buildkitgg/storybook-config/main"
|
|
18
|
+
|
|
19
|
+
export default defineMain({
|
|
20
|
+
stories: ["../src/**/*.stories.tsx"]
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The base uses the `@storybook/react-vite` framework, adds `@chromatic-com/storybook`, `@storybook/addon-a11y` and
|
|
25
|
+
`@storybook/addon-vitest`, and turns off telemetry. The addons are dependencies of this package.
|
|
26
|
+
|
|
27
|
+
## Preview
|
|
28
|
+
|
|
29
|
+
`definePreview` merges your annotations onto the base preview, which matches `color` and `date` controls by argument
|
|
30
|
+
name. Decorators are concatenated and parameters merged deeply:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
// .storybook/preview.tsx
|
|
34
|
+
import { definePreview } from "@buildkitgg/storybook-config/preview"
|
|
35
|
+
|
|
36
|
+
export default definePreview({
|
|
37
|
+
parameters: { layout: "fullscreen" },
|
|
38
|
+
decorators: [(Story) => <Story />]
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Example frames
|
|
43
|
+
|
|
44
|
+
`ExampleFrame` wraps a story in a heading, an optional description and an optional source disclosure. `ExampleResult`
|
|
45
|
+
labels the outcome of an action next to it:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { ExampleFrame, ExampleResult } from "@buildkitgg/storybook-config/examples"
|
|
49
|
+
|
|
50
|
+
export const Saved = () => (
|
|
51
|
+
<ExampleFrame group="Forms" title="Save" description="Shows the saved state after submitting.">
|
|
52
|
+
<button type="submit">Save</button>
|
|
53
|
+
<ExampleResult>Saved</ExampleResult>
|
|
54
|
+
</ExampleFrame>
|
|
55
|
+
)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Importing `@buildkitgg/storybook-config/examples` also loads the frames' stylesheet.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import "./examples.css";
|
|
3
|
+
export type ExampleFrameProps = {
|
|
4
|
+
group: string;
|
|
5
|
+
title: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
code?: string;
|
|
8
|
+
catalog?: boolean;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare function ExampleFrame({ group, title, description, code, catalog, children }: ExampleFrameProps): import("react").JSX.Element;
|
|
12
|
+
export declare function ExampleResult({ label, children }: {
|
|
13
|
+
label?: string;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "./examples.css";
|
|
3
|
+
export function ExampleFrame({ group, title, description, code, catalog, children }) {
|
|
4
|
+
return (_jsxs("main", { className: "bk-example", children: [_jsxs("header", { className: "bk-example-heading", children: [_jsx("p", { className: "bk-example-path", children: group.replaceAll("/", " / ") }), _jsx("h1", { children: title }), description && _jsx("p", { className: "bk-example-description", children: description })] }), _jsxs("section", { className: catalog ? "bk-example-preview bk-catalog-preview" : "bk-example-preview", "aria-label": title + " example", children: [_jsxs("div", { className: "bk-example-toolbar", children: [_jsx("span", { children: "Preview" }), _jsx("span", { children: catalog ? "Component" : "Interactive example" })] }), _jsx("div", { className: "bk-example-canvas", children: children })] }), code && (_jsxs("details", { className: "bk-example-source", children: [_jsx("summary", { children: "View implementation" }), _jsx("pre", { children: _jsx("code", { children: code }) })] }))] }));
|
|
5
|
+
}
|
|
6
|
+
export function ExampleResult({ label = "Result", children }) {
|
|
7
|
+
return (_jsxs("div", { className: "bk-example-result", children: [_jsx("span", { children: label }), _jsx("output", { "aria-live": "polite", children: children })] }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bk-ink: #182230;
|
|
3
|
+
--bk-muted: #64748b;
|
|
4
|
+
--bk-line: #e2e7ee;
|
|
5
|
+
--bk-paper: #ffffff;
|
|
6
|
+
--bk-soft: #f7f9fc;
|
|
7
|
+
--bk-accent: #315bd6;
|
|
8
|
+
}
|
|
9
|
+
.bk-example {
|
|
10
|
+
max-width: 848px;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
padding: 44px 32px 64px;
|
|
13
|
+
color: var(--bk-ink);
|
|
14
|
+
font:
|
|
15
|
+
14px/1.6 system-ui,
|
|
16
|
+
sans-serif;
|
|
17
|
+
}
|
|
18
|
+
.bk-example-heading {
|
|
19
|
+
margin-bottom: 26px;
|
|
20
|
+
}
|
|
21
|
+
.bk-example-path {
|
|
22
|
+
color: var(--bk-muted);
|
|
23
|
+
font:
|
|
24
|
+
11px/1.5 ui-monospace,
|
|
25
|
+
monospace;
|
|
26
|
+
margin: 0 0 14px;
|
|
27
|
+
overflow-wrap: anywhere;
|
|
28
|
+
}
|
|
29
|
+
.bk-example h1 {
|
|
30
|
+
font-size: 27px;
|
|
31
|
+
letter-spacing: -0.035em;
|
|
32
|
+
font-weight: 650;
|
|
33
|
+
line-height: 1.25;
|
|
34
|
+
margin: 0 0 10px;
|
|
35
|
+
}
|
|
36
|
+
.bk-example-description {
|
|
37
|
+
max-width: 620px;
|
|
38
|
+
margin: 0;
|
|
39
|
+
color: var(--bk-muted);
|
|
40
|
+
font-size: 14px;
|
|
41
|
+
line-height: 1.7;
|
|
42
|
+
}
|
|
43
|
+
.bk-example-preview {
|
|
44
|
+
border: 1px solid var(--bk-line);
|
|
45
|
+
border-radius: 12px;
|
|
46
|
+
background: var(--bk-paper);
|
|
47
|
+
box-shadow: 0 2px 5px rgb(15 23 42 / 2%);
|
|
48
|
+
min-width: 0;
|
|
49
|
+
}
|
|
50
|
+
.bk-example-toolbar {
|
|
51
|
+
display: flex;
|
|
52
|
+
justify-content: space-between;
|
|
53
|
+
align-items: center;
|
|
54
|
+
gap: 12px;
|
|
55
|
+
padding: 11px 20px;
|
|
56
|
+
border-bottom: 1px solid var(--bk-line);
|
|
57
|
+
font-size: 11px;
|
|
58
|
+
color: var(--bk-muted);
|
|
59
|
+
}
|
|
60
|
+
.bk-example-toolbar span:first-child {
|
|
61
|
+
font-weight: 600;
|
|
62
|
+
color: var(--bk-ink);
|
|
63
|
+
}
|
|
64
|
+
.bk-example-canvas {
|
|
65
|
+
padding: 28px;
|
|
66
|
+
min-width: 0;
|
|
67
|
+
color: var(--foreground, var(--bk-ink));
|
|
68
|
+
background: var(--background, var(--bk-paper));
|
|
69
|
+
border-radius: 0 0 12px 12px;
|
|
70
|
+
}
|
|
71
|
+
.bk-catalog-preview .bk-example-canvas {
|
|
72
|
+
min-height: 180px;
|
|
73
|
+
display: grid;
|
|
74
|
+
align-content: center;
|
|
75
|
+
gap: 16px;
|
|
76
|
+
}
|
|
77
|
+
.bk-catalog-preview .bk-example-canvas > * {
|
|
78
|
+
max-width: 100%;
|
|
79
|
+
}
|
|
80
|
+
.bk-example-source {
|
|
81
|
+
border: 1px solid var(--bk-line);
|
|
82
|
+
border-radius: 9px;
|
|
83
|
+
margin-top: 16px;
|
|
84
|
+
background: var(--bk-paper);
|
|
85
|
+
}
|
|
86
|
+
.bk-example-source summary {
|
|
87
|
+
padding: 12px 18px;
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
color: var(--bk-muted);
|
|
90
|
+
font-size: 12px;
|
|
91
|
+
}
|
|
92
|
+
.bk-example-source pre {
|
|
93
|
+
margin: 0;
|
|
94
|
+
padding: 20px;
|
|
95
|
+
background: var(--bk-soft);
|
|
96
|
+
border-top: 1px solid var(--bk-line);
|
|
97
|
+
white-space: pre-wrap;
|
|
98
|
+
overflow-wrap: anywhere;
|
|
99
|
+
font:
|
|
100
|
+
12px/1.8 ui-monospace,
|
|
101
|
+
monospace;
|
|
102
|
+
}
|
|
103
|
+
.bk-example-source summary:focus-visible {
|
|
104
|
+
outline: 2px solid var(--bk-accent);
|
|
105
|
+
outline-offset: 4px;
|
|
106
|
+
}
|
|
107
|
+
.bk-example-result {
|
|
108
|
+
display: flex;
|
|
109
|
+
align-items: baseline;
|
|
110
|
+
justify-content: space-between;
|
|
111
|
+
gap: 12px;
|
|
112
|
+
flex-wrap: wrap;
|
|
113
|
+
margin-top: 24px;
|
|
114
|
+
padding-top: 16px;
|
|
115
|
+
border-top: 1px solid var(--border, var(--bk-line));
|
|
116
|
+
font-size: 12px;
|
|
117
|
+
}
|
|
118
|
+
.bk-example-result > span {
|
|
119
|
+
color: var(--muted-foreground, var(--bk-muted));
|
|
120
|
+
}
|
|
121
|
+
.bk-example-result output {
|
|
122
|
+
font-family: ui-monospace, monospace;
|
|
123
|
+
overflow-wrap: anywhere;
|
|
124
|
+
color: var(--foreground, var(--bk-ink));
|
|
125
|
+
max-width: 100%;
|
|
126
|
+
}
|
|
127
|
+
.bk-example .bk-stack {
|
|
128
|
+
display: grid;
|
|
129
|
+
grid-template-columns: minmax(0, 1fr);
|
|
130
|
+
gap: 20px;
|
|
131
|
+
}
|
|
132
|
+
.bk-example .bk-row {
|
|
133
|
+
display: flex;
|
|
134
|
+
align-items: center;
|
|
135
|
+
justify-content: space-between;
|
|
136
|
+
gap: 16px;
|
|
137
|
+
flex-wrap: wrap;
|
|
138
|
+
}
|
|
139
|
+
.bk-item-title {
|
|
140
|
+
font-size: 14px;
|
|
141
|
+
font-weight: 600;
|
|
142
|
+
margin: 0;
|
|
143
|
+
}
|
|
144
|
+
.bk-item-description {
|
|
145
|
+
color: var(--muted-foreground, var(--bk-muted));
|
|
146
|
+
font-size: 13px;
|
|
147
|
+
margin: 4px 0 0;
|
|
148
|
+
}
|
|
149
|
+
.bk-person {
|
|
150
|
+
display: flex;
|
|
151
|
+
align-items: center;
|
|
152
|
+
gap: 12px;
|
|
153
|
+
}
|
|
154
|
+
.bk-avatar {
|
|
155
|
+
display: grid;
|
|
156
|
+
place-items: center;
|
|
157
|
+
width: 40px;
|
|
158
|
+
height: 40px;
|
|
159
|
+
border-radius: 50%;
|
|
160
|
+
background: var(--muted, #eef2f6);
|
|
161
|
+
color: var(--muted-foreground, #526174);
|
|
162
|
+
font-size: 12px;
|
|
163
|
+
font-weight: 600;
|
|
164
|
+
flex: none;
|
|
165
|
+
}
|
|
166
|
+
.bk-empty {
|
|
167
|
+
border: 1px dashed var(--border, var(--bk-line));
|
|
168
|
+
border-radius: 8px;
|
|
169
|
+
padding: 24px;
|
|
170
|
+
color: var(--muted-foreground, var(--bk-muted));
|
|
171
|
+
text-align: center;
|
|
172
|
+
font-size: 13px;
|
|
173
|
+
}
|
|
174
|
+
.bk-example :where(button:not([class]), input:not([class]), textarea:not([class])) {
|
|
175
|
+
font: inherit;
|
|
176
|
+
border: 1px solid var(--border, var(--bk-line));
|
|
177
|
+
border-radius: 6px;
|
|
178
|
+
background: var(--background, white);
|
|
179
|
+
color: var(--foreground, var(--bk-ink));
|
|
180
|
+
padding: 7px 12px;
|
|
181
|
+
}
|
|
182
|
+
.bk-example button:not([class]) {
|
|
183
|
+
cursor: pointer;
|
|
184
|
+
font-size: 12px;
|
|
185
|
+
font-weight: 500;
|
|
186
|
+
}
|
|
187
|
+
.bk-example button:not([class]):hover {
|
|
188
|
+
background: var(--muted, #f7f9fc);
|
|
189
|
+
}
|
|
190
|
+
.bk-example button:not([class]):disabled {
|
|
191
|
+
opacity: 0.45;
|
|
192
|
+
cursor: not-allowed;
|
|
193
|
+
}
|
|
194
|
+
.bk-example :where(button, input, textarea):focus-visible {
|
|
195
|
+
outline: 2px solid var(--ring, var(--bk-accent));
|
|
196
|
+
outline-offset: 3px;
|
|
197
|
+
}
|
|
198
|
+
.bk-example label {
|
|
199
|
+
font-size: 13px;
|
|
200
|
+
font-weight: 500;
|
|
201
|
+
}
|
|
202
|
+
.bk-example .actions {
|
|
203
|
+
display: flex;
|
|
204
|
+
flex-wrap: wrap;
|
|
205
|
+
align-items: center;
|
|
206
|
+
gap: 8px;
|
|
207
|
+
}
|
|
208
|
+
@media (max-width: 600px) {
|
|
209
|
+
.bk-example {
|
|
210
|
+
padding: 24px 16px 40px;
|
|
211
|
+
}
|
|
212
|
+
.bk-example h1 {
|
|
213
|
+
font-size: 23px;
|
|
214
|
+
}
|
|
215
|
+
.bk-example-canvas {
|
|
216
|
+
padding: 20px;
|
|
217
|
+
}
|
|
218
|
+
.bk-example-toolbar {
|
|
219
|
+
padding: 10px 16px;
|
|
220
|
+
}
|
|
221
|
+
.bk-example-description {
|
|
222
|
+
font-size: 13px;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
@media (prefers-reduced-motion: reduce) {
|
|
226
|
+
.bk-example *,
|
|
227
|
+
.bk-docs * {
|
|
228
|
+
scroll-behavior: auto !important;
|
|
229
|
+
}
|
|
230
|
+
}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type StorybookConfig } from "@storybook/react-vite/node";
|
|
2
|
+
/**
|
|
3
|
+
* Shared Storybook base configuration for the monorepo. Consumers should not
|
|
4
|
+
* redefine these — `defineMain` merges an app's config on top of the base.
|
|
5
|
+
*/
|
|
6
|
+
export declare const baseConfig: Omit<StorybookConfig, "stories">;
|
|
7
|
+
/**
|
|
8
|
+
* Builds a Storybook `main` config by combining the shared base with an app's
|
|
9
|
+
* overrides (addons concatenated, objects merged deeply), then running it
|
|
10
|
+
* through Storybook's own `defineMain` so the framework is wired correctly.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { defineMain } from "@buildkitgg/storybook-config/main";
|
|
14
|
+
*
|
|
15
|
+
* export default defineMain({
|
|
16
|
+
* stories: ["../src/**\/*.stories.@(ts|tsx)"]
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function defineMain(overrides: StorybookConfig): StorybookConfig;
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineMain as defineStorybookMain } from "@storybook/react-vite/node";
|
|
2
|
+
import { deepMerge } from "./utils/merge.js";
|
|
3
|
+
/**
|
|
4
|
+
* Shared Storybook base configuration for the monorepo. Consumers should not
|
|
5
|
+
* redefine these — `defineMain` merges an app's config on top of the base.
|
|
6
|
+
*/
|
|
7
|
+
export const baseConfig = {
|
|
8
|
+
framework: {
|
|
9
|
+
name: "@storybook/react-vite",
|
|
10
|
+
options: {}
|
|
11
|
+
},
|
|
12
|
+
addons: ["@chromatic-com/storybook", "@storybook/addon-a11y", "@storybook/addon-vitest"],
|
|
13
|
+
core: {
|
|
14
|
+
disableTelemetry: true
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Builds a Storybook `main` config by combining the shared base with an app's
|
|
19
|
+
* overrides (addons concatenated, objects merged deeply), then running it
|
|
20
|
+
* through Storybook's own `defineMain` so the framework is wired correctly.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { defineMain } from "@buildkitgg/storybook-config/main";
|
|
24
|
+
*
|
|
25
|
+
* export default defineMain({
|
|
26
|
+
* stories: ["../src/**\/*.stories.@(ts|tsx)"]
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function defineMain(overrides) {
|
|
31
|
+
return defineStorybookMain(deepMerge(baseConfig, overrides));
|
|
32
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { definePreview as defineStorybookPreview } from "@storybook/react-vite";
|
|
2
|
+
/** Preview annotations accepted by consumers (Storybook injects `addons`). */
|
|
3
|
+
type PreviewOverrides = Partial<Omit<Parameters<typeof defineStorybookPreview<[]>>[0], "addons">>;
|
|
4
|
+
/** Shared Storybook base preview annotations for the monorepo. */
|
|
5
|
+
export declare const basePreview: PreviewOverrides;
|
|
6
|
+
/**
|
|
7
|
+
* Builds a Storybook `preview` by combining the shared base with an app's
|
|
8
|
+
* overrides (e.g. `decorators` concatenated, `parameters` merged deeply), then
|
|
9
|
+
* running it through Storybook's own `definePreview` so the React renderer
|
|
10
|
+
* (`renderToCanvas`) is wired in.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { definePreview } from "@buildkitgg/storybook-config/preview";
|
|
14
|
+
*
|
|
15
|
+
* export default definePreview({ decorators: [withTheme] });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function definePreview(overrides?: PreviewOverrides): import("@storybook/react").ReactPreview<import("@storybook/react").ReactTypes & import("storybook/internal/csf").AddonTypes & {
|
|
19
|
+
csf4: true;
|
|
20
|
+
}>;
|
|
21
|
+
declare const _default: import("@storybook/react").ReactPreview<import("@storybook/react").ReactTypes & import("storybook/internal/csf").AddonTypes & {
|
|
22
|
+
csf4: true;
|
|
23
|
+
}>;
|
|
24
|
+
export default _default;
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { definePreview as defineStorybookPreview } from "@storybook/react-vite";
|
|
2
|
+
import { deepMerge } from "./utils/merge.js";
|
|
3
|
+
/** Shared Storybook base preview annotations for the monorepo. */
|
|
4
|
+
export const basePreview = {
|
|
5
|
+
parameters: {
|
|
6
|
+
controls: {
|
|
7
|
+
matchers: {
|
|
8
|
+
color: /(background|color)$/i,
|
|
9
|
+
date: /Date$/i
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Builds a Storybook `preview` by combining the shared base with an app's
|
|
16
|
+
* overrides (e.g. `decorators` concatenated, `parameters` merged deeply), then
|
|
17
|
+
* running it through Storybook's own `definePreview` so the React renderer
|
|
18
|
+
* (`renderToCanvas`) is wired in.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { definePreview } from "@buildkitgg/storybook-config/preview";
|
|
22
|
+
*
|
|
23
|
+
* export default definePreview({ decorators: [withTheme] });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function definePreview(overrides = {}) {
|
|
27
|
+
return defineStorybookPreview({ addons: [], ...deepMerge(basePreview, overrides) });
|
|
28
|
+
}
|
|
29
|
+
export default definePreview();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep-merges configuration objects so consumer config is *combined* with the
|
|
3
|
+
* base rather than replacing it:
|
|
4
|
+
* - Arrays are concatenated (base entries first, then the consumer's).
|
|
5
|
+
* - Plain objects are merged recursively, key by key.
|
|
6
|
+
* - Everything else (strings, numbers, RegExp, functions, ...) is overridden.
|
|
7
|
+
*/
|
|
8
|
+
function isPlainObject(value) {
|
|
9
|
+
if (value === null || value === undefined || Array.isArray(value)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
// Primitives have their wrapper's prototype, so only plain objects get this far.
|
|
13
|
+
const prototype = Object.getPrototypeOf(value);
|
|
14
|
+
return prototype === Object.prototype || prototype === null;
|
|
15
|
+
}
|
|
16
|
+
/** The merge has every property of both values, so it is typed as both. */
|
|
17
|
+
export function deepMerge(base, override) {
|
|
18
|
+
if (override === undefined) {
|
|
19
|
+
// SAFETY: an undefined override leaves the base as it is.
|
|
20
|
+
return base;
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(base) && Array.isArray(override)) {
|
|
23
|
+
// SAFETY: the concatenation holds the entries of both arrays.
|
|
24
|
+
return [...base, ...override];
|
|
25
|
+
}
|
|
26
|
+
if (isPlainObject(base) && isPlainObject(override)) {
|
|
27
|
+
const merged = new Map(Object.entries(base));
|
|
28
|
+
for (const [key, value] of Object.entries(override)) {
|
|
29
|
+
merged.set(key, merged.has(key) ? deepMerge(merged.get(key), value) : value);
|
|
30
|
+
}
|
|
31
|
+
// SAFETY: the merged object has every key of both objects, each merged the same way.
|
|
32
|
+
return Object.fromEntries(merged);
|
|
33
|
+
}
|
|
34
|
+
// SAFETY: an override that can't be merged replaces the base.
|
|
35
|
+
return override;
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildkitgg/storybook-config",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Shared Storybook main and preview configuration, and story example frames.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"**/*.css"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
"./main": {
|
|
12
|
+
"types": "./dist/main.d.ts",
|
|
13
|
+
"import": "./dist/main.js"
|
|
14
|
+
},
|
|
15
|
+
"./preview": {
|
|
16
|
+
"types": "./dist/preview.d.ts",
|
|
17
|
+
"import": "./dist/preview.js"
|
|
18
|
+
},
|
|
19
|
+
"./examples": {
|
|
20
|
+
"types": "./dist/ExampleFrame.d.ts",
|
|
21
|
+
"import": "./dist/ExampleFrame.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist/**/*.js",
|
|
26
|
+
"dist/**/*.d.ts",
|
|
27
|
+
"dist/**/*.css",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"CHANGELOG.md"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@chromatic-com/storybook": "^5.6.0",
|
|
34
|
+
"@storybook/addon-a11y": "10.6.5",
|
|
35
|
+
"@storybook/addon-vitest": "10.6.5",
|
|
36
|
+
"@storybook/react": "10.6.5",
|
|
37
|
+
"@storybook/react-vite": "10.6.5",
|
|
38
|
+
"storybook": "10.6.5"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^19.2.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@repo/typescript-config": "0.0.0",
|
|
45
|
+
"typescript": "7.0.2",
|
|
46
|
+
"vitest": "5.0.5",
|
|
47
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
48
|
+
"@types/react": "^19.3.0",
|
|
49
|
+
"vite-plus": "1.4.0"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/AndrewCraswell/buildkit.git",
|
|
54
|
+
"directory": "packages/tooling/storybook-config"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/AndrewCraswell/buildkit/tree/main/packages/tooling/storybook-config#readme",
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/AndrewCraswell/buildkit/issues"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public",
|
|
62
|
+
"registry": "https://registry.npmjs.org/"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsc -p tsconfig.build.json && node -e \"require('node:fs').copyFileSync('src/examples.css', 'dist/examples.css')\"",
|
|
66
|
+
"test": "vp test run",
|
|
67
|
+
"test:coverage": "vp test run --coverage"
|
|
68
|
+
}
|
|
6
69
|
}
|