@repobuddy/storybook 2.2.2 → 2.3.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/esm/index.d.ts +81 -1
- package/esm/storybook-addon-tag-badges/index.d.ts +43 -21
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/storybook-addon-tag-badges/types.ts +3 -2
- package/src/types/_extract_string_literals.ts +1 -0
- package/src/types/extends_meta.ts +37 -0
- package/src/types/extends_story_obj.ts +42 -0
- package/src/types.ts +4 -0
package/esm/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
|
5
5
|
import { ClassNameProps, StyleProps } from "@just-web/css";
|
|
6
6
|
import { Args, DecoratorFunction, Renderer } from "storybook/internal/csf";
|
|
7
7
|
import { Decorator, Meta, StoryContext, StoryObj, StrictArgs } from "@storybook/react-vite";
|
|
8
|
+
import { IsStringLiteral } from "type-plus";
|
|
8
9
|
export * from "@repobuddy/test";
|
|
9
10
|
|
|
10
11
|
//#region src/components/show_html.d.ts
|
|
@@ -645,6 +646,8 @@ declare function whenRunningInTest<TArgs = StrictArgs>(decoratorOrHandler: ((...
|
|
|
645
646
|
* @template M - The base Meta type
|
|
646
647
|
* @template E - The extension type containing tagType
|
|
647
648
|
*
|
|
649
|
+
* @deprecated use `import { ExtendsMeta } from '@repobuddy/storybook'` instead.
|
|
650
|
+
*
|
|
648
651
|
* @example
|
|
649
652
|
* ```ts
|
|
650
653
|
* // Create a generic Meta type for a project
|
|
@@ -665,6 +668,8 @@ type ExtendMeta<TCmpOrArgs, M extends Meta<TCmpOrArgs>, E extends {
|
|
|
665
668
|
* @template S - The base StoryObj type
|
|
666
669
|
* @template E - The extension type containing tagType
|
|
667
670
|
*
|
|
671
|
+
* @deprecated use `import { ExtendsStoryObj } from '@repobuddy/storybook'` instead.
|
|
672
|
+
*
|
|
668
673
|
* @example
|
|
669
674
|
* ```ts
|
|
670
675
|
* // Create a generic StoryObj type for a project
|
|
@@ -680,4 +685,79 @@ type ExtendStoryObj<TMetaOrCmpOrArgs, S extends StoryObj<TMetaOrCmpOrArgs>, E ex
|
|
|
680
685
|
tags?: Array<E['tag'] | (string & {})> | undefined;
|
|
681
686
|
};
|
|
682
687
|
//#endregion
|
|
683
|
-
|
|
688
|
+
//#region src/types/_extract_string_literals.d.ts
|
|
689
|
+
type ExtractStringLiterals<T> = T extends any ? (string extends T ? never : T) : never;
|
|
690
|
+
//#endregion
|
|
691
|
+
//#region src/types/extends_meta.d.ts
|
|
692
|
+
/**
|
|
693
|
+
* Extends the Storybook Meta type with custom tag types.
|
|
694
|
+
*
|
|
695
|
+
* This utility type allows you to extend the `tags` property of a Storybook Meta type
|
|
696
|
+
* with custom string literal types while preserving existing tag types from the base Meta.
|
|
697
|
+
*
|
|
698
|
+
* @template M - The base Meta type to extend
|
|
699
|
+
* @template E - The extension type containing a `tag` property with the custom tag types
|
|
700
|
+
*
|
|
701
|
+
* @example
|
|
702
|
+
* ```ts
|
|
703
|
+
* import type { ExtendsMeta } from '@repobuddy/storybook'
|
|
704
|
+
* import type { Args, Meta as M } from '@storybook/your-framework'
|
|
705
|
+
*
|
|
706
|
+
* // Create a generic Meta type for your project
|
|
707
|
+
* type Meta<TCmpOrArgs = Args> = ExtendsMeta<
|
|
708
|
+
* M<TCmpOrArgs>,
|
|
709
|
+
* { tag: 'new' | 'beta' | 'deprecated' }
|
|
710
|
+
* >
|
|
711
|
+
*
|
|
712
|
+
* // Use in component stories
|
|
713
|
+
* const meta: Meta<typeof Component> = {
|
|
714
|
+
* tags: ['new'], // <--- gets auto-completion for 'new' | 'beta' | 'deprecated'
|
|
715
|
+
* // ...
|
|
716
|
+
* }
|
|
717
|
+
* ```
|
|
718
|
+
*/
|
|
719
|
+
type ExtendsMeta<M extends {
|
|
720
|
+
tags?: string[] | undefined;
|
|
721
|
+
}, E extends {
|
|
722
|
+
tag: string;
|
|
723
|
+
}> = Omit<M, 'tags'> & {
|
|
724
|
+
tags?: ExtractStringLiterals<NonNullable<M['tags']>[number]> extends infer MT ? IsStringLiteral<MT> extends true ? Array<(string & {}) | MT | E['tag']> | undefined : Array<(string & {}) | E['tag']> | undefined : never;
|
|
725
|
+
};
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/types/extends_story_obj.d.ts
|
|
728
|
+
/**
|
|
729
|
+
* Extends the Storybook StoryObj type with custom tag types.
|
|
730
|
+
*
|
|
731
|
+
* This utility type allows you to extend the `tags` property of a Storybook StoryObj type
|
|
732
|
+
* with custom string literal types while preserving existing tag types from the base StoryObj.
|
|
733
|
+
*
|
|
734
|
+
* @template S - The base StoryObj type to extend (must have an optional `tags` property)
|
|
735
|
+
* @template E - The extension type containing a `tag` property with the custom tag types
|
|
736
|
+
*
|
|
737
|
+
* @example
|
|
738
|
+
* ```ts
|
|
739
|
+
* import type { ExtendsStoryObj } from '@repobuddy/storybook'
|
|
740
|
+
* import type { Args, StoryObj as S } from '@storybook/your-framework'
|
|
741
|
+
*
|
|
742
|
+
* // Create a generic StoryObj type for your project
|
|
743
|
+
* type StoryObj<TCmpOrArgs = Args> = ExtendsStoryObj<
|
|
744
|
+
* S<TCmpOrArgs>,
|
|
745
|
+
* { tag: 'new' | 'beta' | 'deprecated' }
|
|
746
|
+
* >
|
|
747
|
+
*
|
|
748
|
+
* // Use in component stories
|
|
749
|
+
* const story: StoryObj<typeof Component> = {
|
|
750
|
+
* tags: ['new'], // <--- gets auto-completion for 'new' | 'beta' | 'deprecated'
|
|
751
|
+
* // ...
|
|
752
|
+
* }
|
|
753
|
+
* ```
|
|
754
|
+
*/
|
|
755
|
+
type ExtendsStoryObj<S extends {
|
|
756
|
+
tags?: string[] | undefined;
|
|
757
|
+
}, E extends {
|
|
758
|
+
tag: string;
|
|
759
|
+
}> = Omit<S, 'tags'> & {
|
|
760
|
+
tags?: ExtractStringLiterals<NonNullable<S['tags']>[number]> extends infer MT ? IsStringLiteral<MT> extends true ? Array<(string & {}) | MT | E['tag']> | undefined : Array<(string & {}) | E['tag']> | undefined : never;
|
|
761
|
+
};
|
|
762
|
+
//#endregion
|
|
763
|
+
export { ActionsParam, BackgroundsParam, DocsParam, ExtendMeta, ExtendStoryObj, ExtendsMeta, ExtendsStoryObj, GlobalApiBackgroundsParam, GlobalApiViewportParam, LayoutParam, ShowHtml, ShowHtmlProps, SourceProps, StoryCardProps, StorySortParam, StorybookBuiltInParams, TestParam, Viewport, ViewportParam, defineActionsParam, defineBackgroundsParam, defineDocsParam, defineLayoutParam, defineParameters, defineTestParam, defineViewportParam, showDocSource, whenRunningInTest, withStoryCard };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { TagBadgeParameters } from "storybook-addon-tag-badges/manager-helpers";
|
|
3
3
|
import { Args, Meta as Meta$1, StoryObj as StoryObj$1 } from "@storybook/react-vite";
|
|
4
|
+
import { IsStringLiteral } from "type-plus";
|
|
4
5
|
|
|
5
6
|
//#region src/storybook-addon-tag-badges/tag_badges.d.ts
|
|
6
7
|
type TagBadgeParameter = TagBadgeParameters[0];
|
|
@@ -44,32 +45,14 @@ declare const internalBadge: TagBadgeParameter;
|
|
|
44
45
|
declare const tagBadges: TagBadgeParameters;
|
|
45
46
|
//#endregion
|
|
46
47
|
//#region src/types.d.ts
|
|
47
|
-
/**
|
|
48
|
-
* Extends the Storybook Meta type with custom tag types
|
|
49
|
-
* @template TCmpOrArgs - The component or args type
|
|
50
|
-
* @template M - The base Meta type
|
|
51
|
-
* @template E - The extension type containing tagType
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* // Create a generic Meta type for a project
|
|
56
|
-
* type Meta<TCmpOrArgs = Args> = ExtendMeta<TCmpOrArgs, Meta<TCmpOrArgs>, { tagType: 'tag1' | 'tag2' }>
|
|
57
|
-
*
|
|
58
|
-
* // Create a specific Meta type for a component
|
|
59
|
-
* type Meta = ExtendMeta<typeof Component, Meta<typeof Component>, { tagType: 'tag1' | 'tag2' }>
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
type ExtendMeta<TCmpOrArgs, M extends Meta$1<TCmpOrArgs>, E extends {
|
|
63
|
-
tag: string;
|
|
64
|
-
}> = Omit<M, 'tags'> & {
|
|
65
|
-
tags?: Array<E['tag'] | (string & {})> | undefined;
|
|
66
|
-
};
|
|
67
48
|
/**
|
|
68
49
|
* Extends the Storybook StoryObj type with custom tag types
|
|
69
50
|
* @template TMetaOrCmpOrArgs - The meta, component or args type
|
|
70
51
|
* @template S - The base StoryObj type
|
|
71
52
|
* @template E - The extension type containing tagType
|
|
72
53
|
*
|
|
54
|
+
* @deprecated use `import { ExtendsStoryObj } from '@repobuddy/storybook'` instead.
|
|
55
|
+
*
|
|
73
56
|
* @example
|
|
74
57
|
* ```ts
|
|
75
58
|
* // Create a generic StoryObj type for a project
|
|
@@ -85,8 +68,47 @@ type ExtendStoryObj<TMetaOrCmpOrArgs, S extends StoryObj$1<TMetaOrCmpOrArgs>, E
|
|
|
85
68
|
tags?: Array<E['tag'] | (string & {})> | undefined;
|
|
86
69
|
};
|
|
87
70
|
//#endregion
|
|
71
|
+
//#region src/types/_extract_string_literals.d.ts
|
|
72
|
+
type ExtractStringLiterals<T> = T extends any ? (string extends T ? never : T) : never;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/types/extends_meta.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* Extends the Storybook Meta type with custom tag types.
|
|
77
|
+
*
|
|
78
|
+
* This utility type allows you to extend the `tags` property of a Storybook Meta type
|
|
79
|
+
* with custom string literal types while preserving existing tag types from the base Meta.
|
|
80
|
+
*
|
|
81
|
+
* @template M - The base Meta type to extend
|
|
82
|
+
* @template E - The extension type containing a `tag` property with the custom tag types
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import type { ExtendsMeta } from '@repobuddy/storybook'
|
|
87
|
+
* import type { Args, Meta as M } from '@storybook/your-framework'
|
|
88
|
+
*
|
|
89
|
+
* // Create a generic Meta type for your project
|
|
90
|
+
* type Meta<TCmpOrArgs = Args> = ExtendsMeta<
|
|
91
|
+
* M<TCmpOrArgs>,
|
|
92
|
+
* { tag: 'new' | 'beta' | 'deprecated' }
|
|
93
|
+
* >
|
|
94
|
+
*
|
|
95
|
+
* // Use in component stories
|
|
96
|
+
* const meta: Meta<typeof Component> = {
|
|
97
|
+
* tags: ['new'], // <--- gets auto-completion for 'new' | 'beta' | 'deprecated'
|
|
98
|
+
* // ...
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
type ExtendsMeta<M extends {
|
|
103
|
+
tags?: string[] | undefined;
|
|
104
|
+
}, E extends {
|
|
105
|
+
tag: string;
|
|
106
|
+
}> = Omit<M, 'tags'> & {
|
|
107
|
+
tags?: ExtractStringLiterals<NonNullable<M['tags']>[number]> extends infer MT ? IsStringLiteral<MT> extends true ? Array<(string & {}) | MT | E['tag']> | undefined : Array<(string & {}) | E['tag']> | undefined : never;
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
88
110
|
//#region src/storybook-addon-tag-badges/types.d.ts
|
|
89
|
-
type Meta<TCmpOrArgs = Args> =
|
|
111
|
+
type Meta<TCmpOrArgs = Args> = ExtendsMeta<Meta$1<TCmpOrArgs>, {
|
|
90
112
|
tag: TagNames;
|
|
91
113
|
}>;
|
|
92
114
|
type StoryObj<TMetaOrCmpOrArgs = Args> = ExtendStoryObj<TMetaOrCmpOrArgs, StoryObj$1<TMetaOrCmpOrArgs>, {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -12,3 +12,5 @@ export * from './parameters/define_viewport_param.ts'
|
|
|
12
12
|
export * from './parameters/story_sort.ts'
|
|
13
13
|
export * from './testing/decorators/when_running_in_test.tsx'
|
|
14
14
|
export type * from './types.ts'
|
|
15
|
+
export * from './types/extends_meta.ts'
|
|
16
|
+
export * from './types/extends_story_obj.ts'
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Args, Meta as M, StoryObj as SBO } from '@storybook/react-vite'
|
|
2
|
-
import type {
|
|
2
|
+
import type { ExtendStoryObj } from '../types.js'
|
|
3
|
+
import type { ExtendsMeta } from '../types/extends_meta.js'
|
|
3
4
|
import type { TagNames } from './tag_badges.js'
|
|
4
5
|
|
|
5
|
-
export type Meta<TCmpOrArgs = Args> =
|
|
6
|
+
export type Meta<TCmpOrArgs = Args> = ExtendsMeta<M<TCmpOrArgs>, { tag: TagNames }>
|
|
6
7
|
|
|
7
8
|
export type StoryObj<TMetaOrCmpOrArgs = Args> = ExtendStoryObj<
|
|
8
9
|
TMetaOrCmpOrArgs,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ExtractStringLiterals<T> = T extends any ? (string extends T ? never : T) : never
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IsStringLiteral } from 'type-plus'
|
|
2
|
+
import type { ExtractStringLiterals } from './_extract_string_literals.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extends the Storybook Meta type with custom tag types.
|
|
6
|
+
*
|
|
7
|
+
* This utility type allows you to extend the `tags` property of a Storybook Meta type
|
|
8
|
+
* with custom string literal types while preserving existing tag types from the base Meta.
|
|
9
|
+
*
|
|
10
|
+
* @template M - The base Meta type to extend
|
|
11
|
+
* @template E - The extension type containing a `tag` property with the custom tag types
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { ExtendsMeta } from '@repobuddy/storybook'
|
|
16
|
+
* import type { Args, Meta as M } from '@storybook/your-framework'
|
|
17
|
+
*
|
|
18
|
+
* // Create a generic Meta type for your project
|
|
19
|
+
* type Meta<TCmpOrArgs = Args> = ExtendsMeta<
|
|
20
|
+
* M<TCmpOrArgs>,
|
|
21
|
+
* { tag: 'new' | 'beta' | 'deprecated' }
|
|
22
|
+
* >
|
|
23
|
+
*
|
|
24
|
+
* // Use in component stories
|
|
25
|
+
* const meta: Meta<typeof Component> = {
|
|
26
|
+
* tags: ['new'], // <--- gets auto-completion for 'new' | 'beta' | 'deprecated'
|
|
27
|
+
* // ...
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export type ExtendsMeta<M extends { tags?: string[] | undefined }, E extends { tag: string }> = Omit<M, 'tags'> & {
|
|
32
|
+
tags?: ExtractStringLiterals<NonNullable<M['tags']>[number]> extends infer MT
|
|
33
|
+
? IsStringLiteral<MT> extends true
|
|
34
|
+
? Array<(string & {}) | MT | E['tag']> | undefined
|
|
35
|
+
: Array<(string & {}) | E['tag']> | undefined
|
|
36
|
+
: never
|
|
37
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { IsStringLiteral } from 'type-plus'
|
|
2
|
+
import type { ExtractStringLiterals } from './_extract_string_literals.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extends the Storybook StoryObj type with custom tag types.
|
|
6
|
+
*
|
|
7
|
+
* This utility type allows you to extend the `tags` property of a Storybook StoryObj type
|
|
8
|
+
* with custom string literal types while preserving existing tag types from the base StoryObj.
|
|
9
|
+
*
|
|
10
|
+
* @template S - The base StoryObj type to extend (must have an optional `tags` property)
|
|
11
|
+
* @template E - The extension type containing a `tag` property with the custom tag types
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import type { ExtendsStoryObj } from '@repobuddy/storybook'
|
|
16
|
+
* import type { Args, StoryObj as S } from '@storybook/your-framework'
|
|
17
|
+
*
|
|
18
|
+
* // Create a generic StoryObj type for your project
|
|
19
|
+
* type StoryObj<TCmpOrArgs = Args> = ExtendsStoryObj<
|
|
20
|
+
* S<TCmpOrArgs>,
|
|
21
|
+
* { tag: 'new' | 'beta' | 'deprecated' }
|
|
22
|
+
* >
|
|
23
|
+
*
|
|
24
|
+
* // Use in component stories
|
|
25
|
+
* const story: StoryObj<typeof Component> = {
|
|
26
|
+
* tags: ['new'], // <--- gets auto-completion for 'new' | 'beta' | 'deprecated'
|
|
27
|
+
* // ...
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export type ExtendsStoryObj<
|
|
32
|
+
S extends { tags?: string[] | undefined },
|
|
33
|
+
E extends {
|
|
34
|
+
tag: string
|
|
35
|
+
}
|
|
36
|
+
> = Omit<S, 'tags'> & {
|
|
37
|
+
tags?: ExtractStringLiterals<NonNullable<S['tags']>[number]> extends infer MT
|
|
38
|
+
? IsStringLiteral<MT> extends true
|
|
39
|
+
? Array<(string & {}) | MT | E['tag']> | undefined
|
|
40
|
+
: Array<(string & {}) | E['tag']> | undefined
|
|
41
|
+
: never
|
|
42
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
|
6
6
|
* @template M - The base Meta type
|
|
7
7
|
* @template E - The extension type containing tagType
|
|
8
8
|
*
|
|
9
|
+
* @deprecated use `import { ExtendsMeta } from '@repobuddy/storybook'` instead.
|
|
10
|
+
*
|
|
9
11
|
* @example
|
|
10
12
|
* ```ts
|
|
11
13
|
* // Create a generic Meta type for a project
|
|
@@ -31,6 +33,8 @@ export type ExtendMeta<
|
|
|
31
33
|
* @template S - The base StoryObj type
|
|
32
34
|
* @template E - The extension type containing tagType
|
|
33
35
|
*
|
|
36
|
+
* @deprecated use `import { ExtendsStoryObj } from '@repobuddy/storybook'` instead.
|
|
37
|
+
*
|
|
34
38
|
* @example
|
|
35
39
|
* ```ts
|
|
36
40
|
* // Create a generic StoryObj type for a project
|