@sit-onyx/storybook-utils 1.0.0-alpha.28 → 1.0.0-alpha.29
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 +2 -2
- package/src/preview.ts +5 -0
- package/src/required.ts +36 -0
- package/src/types.ts +10 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/storybook-utils",
|
|
3
3
|
"description": "Storybook utilities for Vue",
|
|
4
|
-
"version": "1.0.0-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.29",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Schwarz IT KG",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@storybook/theming": ">= 8.0.0-rc.0",
|
|
29
29
|
"@storybook/vue3": ">= 8.0.0-rc.0",
|
|
30
30
|
"storybook-dark-mode": ">= 3",
|
|
31
|
-
"sit-onyx": "^1.0.0-alpha.
|
|
31
|
+
"sit-onyx": "^1.0.0-alpha.27"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"deepmerge-ts": "^5.1.0"
|
package/src/preview.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type Preview } from "@storybook/vue3";
|
|
|
5
5
|
import { deepmerge } from "deepmerge-ts";
|
|
6
6
|
|
|
7
7
|
import { ONYX_BREAKPOINTS, createTheme } from "./theme";
|
|
8
|
+
import { requiredGlobalType, withRequired } from "./required";
|
|
8
9
|
|
|
9
10
|
const themes = {
|
|
10
11
|
light: createTheme(),
|
|
@@ -39,6 +40,10 @@ const themes = {
|
|
|
39
40
|
*/
|
|
40
41
|
export const createPreview = <T extends Preview = Preview>(overrides?: T) => {
|
|
41
42
|
const defaultPreview = {
|
|
43
|
+
globalTypes: {
|
|
44
|
+
...requiredGlobalType,
|
|
45
|
+
},
|
|
46
|
+
decorators: [withRequired],
|
|
42
47
|
parameters: {
|
|
43
48
|
controls: {
|
|
44
49
|
matchers: {
|
package/src/required.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Decorator } from "@storybook/vue3";
|
|
2
|
+
import { ref, watch } from "vue";
|
|
3
|
+
import type { StorybookGlobalType } from "./types";
|
|
4
|
+
|
|
5
|
+
type RequiredIndicator = "required" | "optional";
|
|
6
|
+
|
|
7
|
+
export const requiredGlobalType = {
|
|
8
|
+
requiredMode: {
|
|
9
|
+
name: "Required mode",
|
|
10
|
+
description: "Switch between 'required' and 'optional' indicator",
|
|
11
|
+
defaultValue: "required",
|
|
12
|
+
toolbar: {
|
|
13
|
+
icon: "flag",
|
|
14
|
+
items: [
|
|
15
|
+
{ value: "required", right: "*", title: "Required indicator" },
|
|
16
|
+
{ value: "optional", right: "(optional)", title: "Optional indicator" },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
} satisfies StorybookGlobalType<RequiredIndicator>,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const requiredMode = ref<RequiredIndicator>("required");
|
|
23
|
+
|
|
24
|
+
export const withRequired: Decorator = (Story, context) => {
|
|
25
|
+
watch(
|
|
26
|
+
() => context.globals.requiredMode as RequiredIndicator,
|
|
27
|
+
(newRequiredMode) => (requiredMode.value = newRequiredMode),
|
|
28
|
+
{ immediate: true },
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
components: { Story },
|
|
33
|
+
setup: () => ({ requiredMode }),
|
|
34
|
+
template: `<div :class="{ ['onyx-use-optional']: requiredMode === 'optional' }"> <story /> </div>`,
|
|
35
|
+
};
|
|
36
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -46,3 +46,13 @@ export type DefineStorybookActionsAndVModelsOptions<T> = Meta<T> & {
|
|
|
46
46
|
component: NonNullable<T>;
|
|
47
47
|
events: ExtractVueEventNames<T>[];
|
|
48
48
|
};
|
|
49
|
+
|
|
50
|
+
export type StorybookGlobalType<TValue> = {
|
|
51
|
+
name: string;
|
|
52
|
+
description: string;
|
|
53
|
+
defaultValue: TValue;
|
|
54
|
+
toolbar: {
|
|
55
|
+
icon: string;
|
|
56
|
+
items: { value: TValue; right: string; title: string }[];
|
|
57
|
+
};
|
|
58
|
+
};
|