@sit-onyx/storybook-utils 0.0.0 → 0.1.0-alpha.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/package.json +6 -1
- package/src/actions.ts +3 -5
- package/src/preview.ts +6 -0
- package/src/theme.ts +45 -0
- package/src/types.ts +1 -1
- package/tsconfig.json +0 -10
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/storybook-utils",
|
|
3
3
|
"description": "Storybook utilities for Vue",
|
|
4
|
-
"version": "0.0.0",
|
|
4
|
+
"version": "0.1.0-alpha.0",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"author": "Schwarz IT KG",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"files": [
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
6
11
|
"exports": {
|
|
7
12
|
".": {
|
|
8
13
|
"default": "./src/index.ts"
|
package/src/actions.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { DefineStorybookActionsAndVModelsOptions, ExtractVueEventNames } fr
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Utility to define Storybook meta for a given Vue component which will take care of defining argTypes for
|
|
8
|
-
* the given events as well as implementing v-model handlers.
|
|
9
|
-
* Should be preferred over manually defining argTypes for
|
|
8
|
+
* the given events as well as implementing v-model handlers so that the Storybook controls are updated when you interact with the component.
|
|
9
|
+
* Should be preferred over manually defining argTypes for *.stories.ts files.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
@@ -35,7 +35,6 @@ export const defineStorybookActionsAndVModels = <T>(
|
|
|
35
35
|
decorators: [
|
|
36
36
|
(story, context) => {
|
|
37
37
|
// provide the `updateArgs` function so we can use it in the render() function below
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
38
|
const [_, updateArgs] = useArgs();
|
|
40
39
|
return story({ ...context, updateArgs });
|
|
41
40
|
},
|
|
@@ -107,8 +106,7 @@ const defineRenderFunctionForVModels = <T>(
|
|
|
107
106
|
}, {});
|
|
108
107
|
|
|
109
108
|
return {
|
|
110
|
-
|
|
111
|
-
components: { [componentName]: options.component } as Record<string, any>,
|
|
109
|
+
components: { [componentName]: options.component },
|
|
112
110
|
setup: () => ({ args, ...eventHandlers }),
|
|
113
111
|
/**
|
|
114
112
|
* Add v-model event handlers to source code
|
package/src/preview.ts
CHANGED
|
@@ -4,12 +4,15 @@ import { themes, type ThemeVars } from "@storybook/theming";
|
|
|
4
4
|
import { type Preview } from "@storybook/vue3";
|
|
5
5
|
import { deepmerge } from "deepmerge-ts";
|
|
6
6
|
import { DARK_MODE_EVENT_NAME } from "storybook-dark-mode";
|
|
7
|
+
import { ONYX_BREAKPOINTS } from "./theme";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Creates a default Storybook preview configuration for 'Onyx' with the following features:
|
|
10
11
|
* - Improved controls (sorting and expanded controls so descriptions etc. are also shown in a single story)
|
|
11
12
|
* - Improved Vue-specific code highlighting (e.g. using `@` instead of `v-on:`)
|
|
12
13
|
* - Setup for dark mode (including docs page). Requires addon `storybook-dark-mode` to be enabled in .storybook/main.ts file
|
|
14
|
+
* - Support for setting the light/dark mode when Storybook is embedded as an iframe (via query parameter, e.g. `?theme=dark`)
|
|
15
|
+
* - Configure viewports / breakpoints as defined by Onyx
|
|
13
16
|
*
|
|
14
17
|
* @param overrides Custom preview / overrides, will be deep merged with the default preview.
|
|
15
18
|
*
|
|
@@ -84,6 +87,9 @@ export const createPreview = <T extends Preview = Preview>(overrides?: T) => {
|
|
|
84
87
|
// backgrounds are not needed because we have configured the darkMode addon/toggle switch
|
|
85
88
|
disable: true,
|
|
86
89
|
},
|
|
90
|
+
viewport: {
|
|
91
|
+
viewports: ONYX_BREAKPOINTS,
|
|
92
|
+
},
|
|
87
93
|
},
|
|
88
94
|
} satisfies Preview;
|
|
89
95
|
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** All available Storybook breakpoints / viewports supported by Onyx. */
|
|
2
|
+
export const ONYX_BREAKPOINTS = {
|
|
3
|
+
xsmall2 : {
|
|
4
|
+
name: "2xsmall",
|
|
5
|
+
styles: {
|
|
6
|
+
width: "320px",
|
|
7
|
+
height: "100%",
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
xsmall: {
|
|
11
|
+
name: "xsmall",
|
|
12
|
+
styles: {
|
|
13
|
+
width: "576px",
|
|
14
|
+
height: "100%",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
small: {
|
|
18
|
+
name: "small",
|
|
19
|
+
styles: {
|
|
20
|
+
width: "768px",
|
|
21
|
+
height: "100%",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
medium: {
|
|
25
|
+
name: "medium",
|
|
26
|
+
styles: {
|
|
27
|
+
width: "992px",
|
|
28
|
+
height: "100%",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
large: {
|
|
32
|
+
name: "large",
|
|
33
|
+
styles: {
|
|
34
|
+
width: "1440px",
|
|
35
|
+
height: "100%",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
xlarge: {
|
|
39
|
+
name: "xlarge",
|
|
40
|
+
styles: {
|
|
41
|
+
width: "1920px",
|
|
42
|
+
height: "100%",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
} as const;
|
package/src/types.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type ExtractVueEventNames<VueComponent> = Extract<
|
|
|
15
15
|
// this generic type will extract ALL props and events from the given Vue component
|
|
16
16
|
ComponentPropsAndSlots<VueComponent>,
|
|
17
17
|
// emits are declared as functions, so we only take props/events that are functions and ignore the rest
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- We must use any here to match the type defined by Vue
|
|
19
19
|
((...args: any) => any) | undefined
|
|
20
20
|
>,
|
|
21
21
|
// filter out potential function properties by just picking events that start with "on"
|