@sit-onyx/storybook-utils 1.1.4 → 1.1.5-dev-20261123100908
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/package.json +12 -12
- package/src/actions.ts +26 -21
- package/src/events.ts +6 -4
- package/src/preview.ts +22 -20
- package/src/sbType.ts +17 -14
- package/src/theme.ts +9 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/storybook-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5-dev-20261123100908",
|
|
4
4
|
"description": "Storybook utilities for Vue",
|
|
5
5
|
"homepage": "https://onyx.schwarz/development/packages/storybook-utils.html",
|
|
6
6
|
"bugs": {
|
|
@@ -23,27 +23,27 @@
|
|
|
23
23
|
"./style.css": "./src/style.css"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"deepmerge-ts": "^
|
|
26
|
+
"deepmerge-ts": "^8.0.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
29
|
+
"@sit-onyx/icons": "^1.14.0-dev-20261123100908",
|
|
30
|
+
"@sit-onyx/shared": "^0.1.0",
|
|
31
|
+
"prettier": "^3.10.1",
|
|
32
|
+
"storybook": "^10.6.7",
|
|
33
|
+
"vue": "3.5.44",
|
|
34
|
+
"vue-component-type-helpers": "^3.3.14"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
+
"@sit-onyx/flags": "^1.3.1-dev-20261123100908",
|
|
38
|
+
"@sit-onyx/icons": "^1.14.0-dev-20261123100908",
|
|
37
39
|
"@storybook/vue3-vite": ">= 9.0.0",
|
|
38
40
|
"@vueless/storybook-dark-mode": ">= 9.0.0",
|
|
39
41
|
"prettier": ">= 3.0.0",
|
|
40
42
|
"storybook": ">= 9.0.0",
|
|
41
|
-
"vue-component-type-helpers": ">= 2"
|
|
42
|
-
"@sit-onyx/flags": "^1.3.0",
|
|
43
|
-
"@sit-onyx/icons": "^1.10.1"
|
|
43
|
+
"vue-component-type-helpers": ">= 2"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
46
|
+
"node": ">=22"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsc --noEmit",
|
package/src/actions.ts
CHANGED
|
@@ -11,8 +11,9 @@ type ComponentEmits<Props extends ComponentProps<unknown>> = keyof {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Wraps the original component and adds [Storybook action
|
|
15
|
-
* This is useful for slotted child
|
|
14
|
+
* Wraps the original component and adds [Storybook action
|
|
15
|
+
* logging](https://storybook.js.org/docs/essentials/actions). This is useful for slotted child
|
|
16
|
+
* components that emit relevant events.
|
|
16
17
|
*
|
|
17
18
|
* Returns a wrapped component, which can be used in place of the original component.
|
|
18
19
|
*
|
|
@@ -52,7 +53,8 @@ export const createActionLoggerWrapper =
|
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
|
-
* Adds actions for all argTypes of the 'event' category, so that they are logged via the actions
|
|
56
|
+
* Adds actions for all argTypes of the 'event' category, so that they are logged via the actions
|
|
57
|
+
* plugin.
|
|
56
58
|
*/
|
|
57
59
|
export const enhanceEventArgTypes: ArgTypesEnhancer = ({ argTypes }) => {
|
|
58
60
|
Object.values(argTypes)
|
|
@@ -76,18 +78,18 @@ export const enhanceEventArgTypes: ArgTypesEnhancer = ({ argTypes }) => {
|
|
|
76
78
|
* Will be documented in a extra "Relevant HTML events" section in the Storybook documentation.
|
|
77
79
|
*
|
|
78
80
|
* @example
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*};
|
|
88
|
-
*
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const meta: Meta<typeof OnyxButton> = {
|
|
83
|
+
* title: "Buttons/Button",
|
|
84
|
+
* component: OnyxButton,
|
|
85
|
+
* argTypes: {
|
|
86
|
+
* somethingElse: { ...someOtherArgType },
|
|
87
|
+
* ...withNativeEventLogging(["onClick"]),
|
|
88
|
+
* },
|
|
89
|
+
* };
|
|
90
|
+
* ```;
|
|
89
91
|
*
|
|
90
|
-
* @param relevantEvents
|
|
92
|
+
* @param relevantEvents A list of event names that should be logged
|
|
91
93
|
* @returns Storybook ArgTypes object
|
|
92
94
|
*/
|
|
93
95
|
export const withNativeEventLogging = (relevantEvents: (keyof Events)[]) =>
|
|
@@ -109,6 +111,7 @@ export const withNativeEventLogging = (relevantEvents: (keyof Events)[]) =>
|
|
|
109
111
|
export type WithVModelDecoratorOptions = {
|
|
110
112
|
/**
|
|
111
113
|
* The matcher for the v-model events.
|
|
114
|
+
*
|
|
112
115
|
* @default /^update:/
|
|
113
116
|
*/
|
|
114
117
|
filter: (argType: StrictInputType, index: number, array: StrictInputType[]) => boolean;
|
|
@@ -120,13 +123,13 @@ export type WithVModelDecoratorOptions = {
|
|
|
120
123
|
* This ensures that the story and component props stay in sync.
|
|
121
124
|
*
|
|
122
125
|
* @example
|
|
123
|
-
*
|
|
124
|
-
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* // .storybook/preview.ts
|
|
125
128
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
129
|
+
* {
|
|
130
|
+
* decorators: [withVModelDecorator()];
|
|
131
|
+
* }
|
|
132
|
+
* ```;
|
|
130
133
|
*/
|
|
131
134
|
|
|
132
135
|
export const withVModelDecorator = (options?: WithVModelDecoratorOptions): Decorator => {
|
|
@@ -182,7 +185,9 @@ export const withVModelDecorator = (options?: WithVModelDecoratorOptions): Decor
|
|
|
182
185
|
};
|
|
183
186
|
};
|
|
184
187
|
|
|
185
|
-
/**
|
|
188
|
+
/**
|
|
189
|
+
* Capitalizes the first letter of the given string
|
|
190
|
+
*/
|
|
186
191
|
const capitalizeFirstLetter = (value: string) => {
|
|
187
192
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
188
193
|
};
|
package/src/events.ts
CHANGED
|
@@ -17,10 +17,12 @@ type EventName<T extends Event> =
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Removes a prefix from a string type.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* type Trimmed = TrimStart<"onclick", "on">;
|
|
24
|
+
* const trimmed: Trimmed = "click";
|
|
25
|
+
* ```;
|
|
24
26
|
*/
|
|
25
27
|
type TrimStart<
|
|
26
28
|
TString extends string,
|
package/src/preview.ts
CHANGED
|
@@ -9,30 +9,29 @@ import { requiredGlobalType, withRequired } from "./required.js";
|
|
|
9
9
|
import { ONYX_BREAKPOINTS, createTheme, type BrandDetails } from "./theme.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Creates a default Storybook preview configuration for 'onyx' with the following features:
|
|
13
|
-
*
|
|
14
|
-
* - Improved Vue-specific code highlighting (e.g. using `@` instead of `v-on:`)
|
|
15
|
-
*
|
|
16
|
-
* - Custom Storybook theme using onyx colors (light and dark mode)
|
|
17
|
-
*
|
|
18
|
-
* - Logs Vue emits as Storybook events
|
|
19
|
-
*
|
|
20
|
-
* @param overrides Custom preview / overrides, will be deep merged with the default preview.
|
|
12
|
+
* Creates a default Storybook preview configuration for 'onyx' with the following features: -
|
|
13
|
+
* Improved controls (sorting and expanded controls so descriptions etc. are also shown in a single
|
|
14
|
+
* story) - Improved Vue-specific code highlighting (e.g. using `@` instead of `v-on:`) - Setup for
|
|
15
|
+
* dark mode (including docs page). Requires addon `@vueless/storybook-dark-mode` to be enabled in
|
|
16
|
+
* .storybook/main.ts file - Custom Storybook theme using onyx colors (light and dark mode) -
|
|
17
|
+
* Configure viewports / breakpoints as defined by onyx - Logs Vue emits as Storybook events
|
|
21
18
|
*
|
|
22
19
|
* @example
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* // .storybook/preview.ts
|
|
22
|
+
* const preview = {
|
|
26
23
|
* // you need to destructure here because as of Storybook 7.6
|
|
27
24
|
* // it can not statically analyze that the `preview` variable is an object
|
|
28
25
|
* ...createPreview({
|
|
29
|
-
*
|
|
30
|
-
*
|
|
26
|
+
* // custom preview / overrides
|
|
27
|
+
* },
|
|
31
28
|
* }),
|
|
32
|
-
*
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* export default preview;
|
|
32
|
+
* ```
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
* ```
|
|
34
|
+
* @param overrides Custom preview / overrides, will be deep merged with the default preview.
|
|
36
35
|
*/
|
|
37
36
|
export const createPreview = <T extends Preview = Preview>(
|
|
38
37
|
overrides?: T,
|
|
@@ -85,6 +84,7 @@ export const createPreview = <T extends Preview = Preview>(
|
|
|
85
84
|
* Use a custom transformer for the story source code to better fit to our
|
|
86
85
|
* Vue.js code because storybook per default does not render it exactly how
|
|
87
86
|
* we want it to look.
|
|
87
|
+
*
|
|
88
88
|
* @see https://storybook.js.org/docs/react/api/doc-block-source
|
|
89
89
|
*/
|
|
90
90
|
transform: sourceCodeTransformer,
|
|
@@ -137,7 +137,7 @@ export const sourceCodeTransformer = async (originalSourceCode: string): Promise
|
|
|
137
137
|
/**
|
|
138
138
|
* A list of additional JavaScript imports to be added at the top of the source code.
|
|
139
139
|
*
|
|
140
|
-
*
|
|
140
|
+
* Key = module/package name to import from, value: set of imports to import from the package
|
|
141
141
|
*/
|
|
142
142
|
const additionalImports = new Map<string, Set<string>>();
|
|
143
143
|
|
|
@@ -151,8 +151,9 @@ export const sourceCodeTransformer = async (originalSourceCode: string): Promise
|
|
|
151
151
|
additionalImports.set("sit-onyx", usedOnyxComponents);
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
|
-
* List of npm packages to replace the source code with.
|
|
155
|
-
*
|
|
154
|
+
* List of npm packages to replace the source code with. The source code will be checked for any
|
|
155
|
+
* import of the package and (if its used), the code will be replaced by the corresponding
|
|
156
|
+
* import.
|
|
156
157
|
*/
|
|
157
158
|
const packagesToReplace = [
|
|
158
159
|
{ name: "@sit-onyx/icons", data: await import("@sit-onyx/icons") },
|
|
@@ -254,6 +255,7 @@ export const replaceAll = (value: string, searchValue: string | RegExp, replaceV
|
|
|
254
255
|
|
|
255
256
|
/**
|
|
256
257
|
* Escapes the given string value to be used in `new RegExp()`.
|
|
258
|
+
*
|
|
257
259
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
|
|
258
260
|
*/
|
|
259
261
|
export const escapeRegExp = (string: string) => {
|
package/src/sbType.ts
CHANGED
|
@@ -7,10 +7,13 @@ import type {
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Call a function `cb` for every type node in the storybook type tree.
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* @param inputType The root type
|
|
12
|
+
* @param cb The function that is called for every type. If any non-nullish value is returned by
|
|
13
|
+
* `cb` the execution is stopped and this value is returned.
|
|
14
|
+
* @param parent Optional, the parent type. Is only used as input for the `cb` function and provided
|
|
15
|
+
* when recursing.
|
|
16
|
+
* @returns The first non-nullish value that is returned by `cb`
|
|
14
17
|
*/
|
|
15
18
|
export const walkTree = <TValue>(
|
|
16
19
|
inputType: SBType,
|
|
@@ -61,20 +64,20 @@ const getFormInjectedParent = (symbol: string, inputType?: StrictInputType) => {
|
|
|
61
64
|
* Can be used to create an `ArgTypesEnhancer` which matches a Symbol that is used as default Prop.
|
|
62
65
|
* When it matches the passed description text will be set.
|
|
63
66
|
*
|
|
64
|
-
* @param symbol description of the symbol that should be matched.
|
|
65
|
-
* @param description the description text that should be shown in Storybook for this prop.
|
|
66
|
-
* @returns An `ArgTypesEnhancer` which can be passed to storybook.
|
|
67
|
-
*
|
|
68
67
|
* @example
|
|
69
|
-
*
|
|
70
|
-
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { createSymbolArgTypeEnhancer } from "@sit-onyx/storybook-utils";
|
|
71
70
|
*
|
|
72
|
-
*
|
|
71
|
+
* export const enhanceFormInjectedSymbol = createSymbolArgTypeEnhancer(
|
|
73
72
|
* "FORM_INJECTED_SYMBOL",
|
|
74
73
|
* "If no value (or `undefined`) is provided, `FORM_INJECTED_SYMBOL` is the internal default value for this prop.\n" +
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
74
|
+
* "In that case the props value will be derived from it's parent form (if it exists).\n",
|
|
75
|
+
* );
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @param symbol Description of the symbol that should be matched.
|
|
79
|
+
* @param description The description text that should be shown in Storybook for this prop.
|
|
80
|
+
* @returns An `ArgTypesEnhancer` which can be passed to storybook.
|
|
78
81
|
*/
|
|
79
82
|
export const createSymbolArgTypeEnhancer = (
|
|
80
83
|
symbol: string,
|
package/src/theme.ts
CHANGED
|
@@ -68,7 +68,9 @@ const getDarkTheme = (): Partial<ThemeVars> => {
|
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Define a full onyx Storybook color theme based on the given 5 main colors.
|
|
73
|
+
*/
|
|
72
74
|
const defineTheme = (colors: {
|
|
73
75
|
text: string;
|
|
74
76
|
textMuted: string;
|
|
@@ -103,7 +105,9 @@ const defineTheme = (colors: {
|
|
|
103
105
|
} satisfies Partial<ThemeVars>;
|
|
104
106
|
};
|
|
105
107
|
|
|
106
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* All available Storybook breakpoints / viewports supported by onyx.
|
|
110
|
+
*/
|
|
107
111
|
export const ONYX_BREAKPOINTS = Object.entries(RAW_ONYX_BREAKPOINTS).reduce(
|
|
108
112
|
(obj, [name, width]) => {
|
|
109
113
|
const breakpoint = name as OnyxBreakpoint;
|
|
@@ -129,6 +133,8 @@ export const ONYX_BREAKPOINTS = Object.entries(RAW_ONYX_BREAKPOINTS).reduce(
|
|
|
129
133
|
|
|
130
134
|
/**
|
|
131
135
|
* Converts a rem string into a numeric value with a rem base of 16.
|
|
132
|
-
*
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* "1rem" => 16
|
|
133
139
|
*/
|
|
134
140
|
const remToNumber = (value: string) => +value.replace("rem", "") * 16;
|