@repobuddy/storybook 1.0.1 → 2.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/cjs/components/show_html.d.ts +16 -0
- package/cjs/components/show_html.js +29 -0
- package/cjs/decorators/show_doc_source.d.ts +6 -0
- package/cjs/decorators/show_doc_source.js +38 -0
- package/cjs/index.d.ts +13 -0
- package/cjs/index.js +137 -0
- package/cjs/manager/brand_title.d.ts +35 -0
- package/cjs/manager/brand_title.js +12 -0
- package/cjs/manager/index.d.ts +1 -0
- package/cjs/manager/index.js +16 -0
- package/cjs/parameters/define_actions_param.d.ts +24 -0
- package/cjs/parameters/define_actions_param.js +11 -0
- package/cjs/parameters/define_backgrounds_param.d.ts +45 -0
- package/cjs/parameters/define_backgrounds_param.js +10 -0
- package/cjs/parameters/define_docs_param.d.ts +217 -0
- package/cjs/parameters/define_docs_param.js +11 -0
- package/cjs/parameters/define_layout_param.d.ts +20 -0
- package/cjs/parameters/define_layout_param.js +10 -0
- package/cjs/parameters/define_parameters.d.ts +39 -0
- package/cjs/parameters/define_parameters.js +9 -0
- package/cjs/parameters/define_test_param.d.ts +34 -0
- package/cjs/parameters/define_test_param.js +11 -0
- package/cjs/parameters/define_viewport_param.d.ts +78 -0
- package/cjs/parameters/define_viewport_param.js +11 -0
- package/cjs/parameters/story_sort.d.ts +27 -0
- package/cjs/parameters/story_sort.js +1 -0
- package/cjs/storybook-addon-tag-badges/index.d.ts +2 -0
- package/cjs/storybook-addon-tag-badges/index.js +16 -0
- package/cjs/storybook-addon-tag-badges/tag_badges.d.ts +41 -0
- package/cjs/storybook-addon-tag-badges/tag_badges.js +179 -0
- package/cjs/storybook-addon-tag-badges/types.d.ts +9 -0
- package/cjs/storybook-addon-tag-badges/types.js +1 -0
- package/cjs/storybook-dark-mode/dark_mode_docs_container.d.ts +26 -0
- package/cjs/storybook-dark-mode/dark_mode_docs_container.js +23 -0
- package/cjs/storybook-dark-mode/define_dark_mode.d.ts +54 -0
- package/cjs/storybook-dark-mode/define_dark_mode.js +11 -0
- package/cjs/storybook-dark-mode/index.d.ts +3 -0
- package/cjs/storybook-dark-mode/index.js +38 -0
- package/cjs/storybook-dark-mode/with_dark_mode.d.ts +22 -0
- package/cjs/storybook-dark-mode/with_dark_mode.js +54 -0
- package/cjs/testing/decorators/when_running_in_test.d.ts +5 -0
- package/cjs/testing/decorators/when_running_in_test.js +12 -0
- package/cjs/testing/decorators/when_running_in_text.ctx.d.ts +3 -0
- package/cjs/testing/decorators/when_running_in_text.ctx.js +10 -0
- package/cjs/types.d.ts +41 -0
- package/cjs/types.js +1 -0
- package/cjs/variants/index.d.ts +1 -0
- package/cjs/variants/index.js +8 -0
- package/cjs/variants/package.json +3 -0
- package/cjs/variants/preset.d.ts +11 -0
- package/cjs/variants/preset.js +3 -0
- package/esm/components/show_html.d.ts +1 -1
- package/esm/components/show_html.js +17 -26
- package/esm/decorators/show_doc_source.js +26 -12
- package/esm/index.d.ts +1 -0
- package/esm/index.js +12 -12
- package/esm/manager/brand_title.js +2 -24
- package/esm/manager/index.js +1 -1
- package/esm/parameters/define_actions_param.js +1 -9
- package/esm/parameters/define_backgrounds_param.js +1 -7
- package/esm/parameters/define_docs_param.d.ts +2 -2
- package/esm/parameters/define_docs_param.js +1 -28
- package/esm/parameters/define_layout_param.js +1 -15
- package/esm/parameters/define_parameters.d.ts +1 -1
- package/esm/parameters/define_parameters.js +1 -30
- package/esm/parameters/define_test_param.js +1 -17
- package/esm/parameters/define_viewport_param.js +1 -28
- package/esm/parameters/story_sort.js +0 -1
- package/esm/storybook-addon-tag-badges/index.js +1 -1
- package/esm/storybook-addon-tag-badges/tag_badges.d.ts +1 -1
- package/esm/storybook-addon-tag-badges/tag_badges.js +153 -172
- package/esm/storybook-addon-tag-badges/types.d.ts +7 -6
- package/esm/storybook-addon-tag-badges/types.js +0 -1
- package/esm/storybook-dark-mode/dark_mode_docs_container.d.ts +2 -2
- package/esm/storybook-dark-mode/dark_mode_docs_container.js +19 -30
- package/esm/storybook-dark-mode/define_dark_mode.d.ts +3 -3
- package/esm/storybook-dark-mode/define_dark_mode.js +1 -17
- package/esm/storybook-dark-mode/index.js +3 -3
- package/esm/storybook-dark-mode/with_dark_mode.js +36 -47
- package/esm/testing/decorators/when_running_in_test.js +4 -8
- package/esm/testing/decorators/when_running_in_text.ctx.d.ts +1 -2
- package/esm/testing/decorators/when_running_in_text.ctx.js +2 -2
- package/esm/types.d.ts +41 -0
- package/esm/types.js +0 -0
- package/esm/variants/index.d.ts +1 -0
- package/esm/variants/index.js +2 -0
- package/esm/variants/package.json +3 -0
- package/esm/variants/preset.d.ts +11 -0
- package/esm/variants/preset.js +1 -0
- package/package.json +51 -34
- package/readme.md +3 -3
- package/src/decorators/show_doc_source.tsx +30 -11
- package/src/index.ts +1 -0
- package/src/parameters/define_docs_param.ts +2 -2
- package/src/storybook-addon-tag-badges/tag_badges.ts +1 -1
- package/src/storybook-addon-tag-badges/types.ts +7 -6
- package/src/storybook-dark-mode/dark_mode_docs_container.tsx +2 -2
- package/src/storybook-dark-mode/define_dark_mode.ts +3 -3
- package/src/storybook-dark-mode/with_dark_mode.tsx +2 -1
- package/src/types.ts +51 -0
- package/src/variants/index.ts +3 -0
- package/src/variants/package.json +3 -0
- package/src/variants/preset.ts +22 -0
- package/src/overview.mdx +0 -7
- package/src/storybook-dark-mode/dark_mode_docs_container.mdx +0 -33
package/esm/types.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
/**
|
|
3
|
+
* Extends the Storybook Meta type with custom tag types
|
|
4
|
+
* @template TCmpOrArgs - The component or args type
|
|
5
|
+
* @template M - The base Meta type
|
|
6
|
+
* @template E - The extension type containing tagType
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // Create a generic Meta type for a project
|
|
11
|
+
* type Meta<TCmpOrArgs = Args> = ExtendMeta<TCmpOrArgs, Meta<TCmpOrArgs>, { tagType: 'tag1' | 'tag2' }>
|
|
12
|
+
*
|
|
13
|
+
* // Create a specific Meta type for a component
|
|
14
|
+
* type Meta = ExtendMeta<typeof Component, Meta<typeof Component>, { tagType: 'tag1' | 'tag2' }>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type ExtendMeta<TCmpOrArgs, M extends Meta<TCmpOrArgs>, E extends {
|
|
18
|
+
tag: string;
|
|
19
|
+
}> = Omit<M, 'tags'> & {
|
|
20
|
+
tags?: Array<E['tag'] | (string & {})> | undefined;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Extends the Storybook StoryObj type with custom tag types
|
|
24
|
+
* @template TMetaOrCmpOrArgs - The meta, component or args type
|
|
25
|
+
* @template S - The base StoryObj type
|
|
26
|
+
* @template E - The extension type containing tagType
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Create a generic StoryObj type for a project
|
|
31
|
+
* type StoryObj<TMetaOrCmpOrArgs = Args> = ExtendStoryObj<TMetaOrCmpOrArgs, StoryObj<TMetaOrCmpOrArgs>, { tagType: 'tag1' | 'tag2' }>
|
|
32
|
+
*
|
|
33
|
+
* // Create a specific StoryObj type for a component
|
|
34
|
+
* type StoryObj = ExtendStoryObj<typeof Component, StoryObj<typeof Component>, { tagType: 'tag1' | 'tag2' }>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export type ExtendStoryObj<TMetaOrCmpOrArgs, S extends StoryObj<TMetaOrCmpOrArgs>, E extends {
|
|
38
|
+
tag: string;
|
|
39
|
+
}> = Omit<S, 'tags'> & {
|
|
40
|
+
tags?: Array<E['tag'] | (string & {})> | undefined;
|
|
41
|
+
};
|
package/esm/types.js
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const empty: {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User specifies `@repobuddy/storybook/variants/addon` in the `.storybook/main.ts`.
|
|
3
|
+
*
|
|
4
|
+
* Storybook loads it on the server side.
|
|
5
|
+
*
|
|
6
|
+
* It provides a default export (or in CJS, `module.exports =`) that contains:
|
|
7
|
+
*
|
|
8
|
+
* - `managerEntries` a function that returns an array of strings on where to load the manager (on the client side)
|
|
9
|
+
* - `previewAnnotations` a function that returns an array of strings on where to load the preview (on the client side)
|
|
10
|
+
* - `experimental_serverChannel` a function that handles the server-side channel
|
|
11
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.info("variants.preset.js.load");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repobuddy/storybook",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Storybook repo buddy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -14,6 +14,14 @@
|
|
|
14
14
|
"url": "https://github.com/unional"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
|
+
"imports": {
|
|
18
|
+
"#repobuddy/storybook": "./src/index.ts",
|
|
19
|
+
"#repobuddy/storybook/manager": "./src/manager/index.ts",
|
|
20
|
+
"#repobuddy/storybook/storybook-addon-tag-badges": "./src/storybook-addon-tag-badges/index.ts",
|
|
21
|
+
"#repobuddy/storybook/storybook-dark-mode": "./src/storybook-dark-mode/index.ts",
|
|
22
|
+
"#repobuddy/storybook/variants": "./src/variants/index.ts",
|
|
23
|
+
"#repobuddy/storybook/variants/package.json": "./src/variants/package.json"
|
|
24
|
+
},
|
|
17
25
|
"exports": {
|
|
18
26
|
".": {
|
|
19
27
|
"types": "./esm/index.d.ts",
|
|
@@ -31,58 +39,67 @@
|
|
|
31
39
|
"types": "./esm/storybook-dark-mode/index.d.ts",
|
|
32
40
|
"default": "./esm/storybook-dark-mode/index.js"
|
|
33
41
|
},
|
|
34
|
-
"./
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
"./variants": {
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./esm/variants/index.d.ts",
|
|
45
|
+
"default": "./esm/variants/index.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./variants/package.json": "./esm/variants/package.json",
|
|
49
|
+
"./variants/preset": "./esm/variants/preset.js"
|
|
38
50
|
},
|
|
39
51
|
"files": [
|
|
52
|
+
"cjs",
|
|
40
53
|
"esm",
|
|
41
54
|
"src",
|
|
42
|
-
"!**/*.{spec,test,unit,accept,integrate,system,perf,stress,study,stories}.*"
|
|
55
|
+
"!**/*.{spec,test,unit,accept,integrate,system,perf,stress,study,stories}.*",
|
|
56
|
+
"!**/*.mdx"
|
|
43
57
|
],
|
|
44
58
|
"dependencies": {
|
|
45
|
-
"@just-web/css": "^0.
|
|
59
|
+
"@just-web/css": "^0.7.0",
|
|
46
60
|
"@repobuddy/test": "^1.0.0",
|
|
47
|
-
"
|
|
61
|
+
"@storybook/icons": "^2.0.1",
|
|
62
|
+
"htmlfy": "^1.0.0"
|
|
48
63
|
},
|
|
49
64
|
"devDependencies": {
|
|
50
|
-
"@repobuddy/vitest": "^
|
|
51
|
-
"@storybook/
|
|
52
|
-
"@storybook/addon-
|
|
53
|
-
"@storybook/addon-
|
|
54
|
-
"@storybook/
|
|
55
|
-
"@
|
|
56
|
-
"@tailwindcss/
|
|
57
|
-
"@
|
|
58
|
-
"@vitest/
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"storybook
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
65
|
+
"@repobuddy/vitest": "^2.0.0",
|
|
66
|
+
"@storybook-community/storybook-dark-mode": "^7.0.2",
|
|
67
|
+
"@storybook/addon-docs": "^10.0.7",
|
|
68
|
+
"@storybook/addon-themes": "^10.0.7",
|
|
69
|
+
"@storybook/addon-vitest": "^10.0.7",
|
|
70
|
+
"@storybook/react-vite": "^10.0.7",
|
|
71
|
+
"@tailwindcss/cli": "^4.1.17",
|
|
72
|
+
"@tailwindcss/vite": "^4.1.17",
|
|
73
|
+
"@vitest/browser": "^4.0.9",
|
|
74
|
+
"@vitest/browser-playwright": "^4.0.9",
|
|
75
|
+
"@vitest/coverage-v8": "^4.0.9",
|
|
76
|
+
"dedent": "^1.7.0",
|
|
77
|
+
"ncp": "^2.0.0",
|
|
78
|
+
"react": "^19.2.0",
|
|
79
|
+
"react-dom": "^19.2.0",
|
|
80
|
+
"rimraf": "^6.1.0",
|
|
81
|
+
"storybook": "^10.0.7",
|
|
82
|
+
"storybook-addon-tag-badges": "^3.0.2",
|
|
83
|
+
"tailwindcss": "^4.1.17",
|
|
84
|
+
"unbuild": "^3.6.1",
|
|
85
|
+
"vite": "^7.2.2",
|
|
86
|
+
"vitest": "^4.0.9"
|
|
70
87
|
},
|
|
71
88
|
"peerDependencies": {
|
|
72
|
-
"storybook-
|
|
73
|
-
"storybook-
|
|
89
|
+
"@storybook-community/storybook-dark-mode": "^7.0.0",
|
|
90
|
+
"storybook-addon-tag-badges": "^3.0.2"
|
|
74
91
|
},
|
|
75
92
|
"peerDependenciesMeta": {
|
|
76
|
-
"storybook-
|
|
93
|
+
"@storybook-community/storybook-dark-mode": {
|
|
77
94
|
"optional": true
|
|
78
95
|
},
|
|
79
|
-
"storybook-
|
|
96
|
+
"storybook-addon-tag-badges": {
|
|
80
97
|
"optional": true
|
|
81
98
|
}
|
|
82
99
|
},
|
|
83
100
|
"scripts": {
|
|
84
|
-
"build": "
|
|
85
|
-
"clean": "rimraf .turbo coverage esm storybook-static *.tsbuildinfo",
|
|
101
|
+
"build": "unbuild",
|
|
102
|
+
"clean": "rimraf .turbo coverage cjs esm storybook-static *.tsbuildinfo",
|
|
86
103
|
"coverage": "vitest run --coverage",
|
|
87
104
|
"sb": "storybook dev -p 6006",
|
|
88
105
|
"sb:build": "storybook build",
|
package/readme.md
CHANGED
|
@@ -102,9 +102,9 @@ import { defaultConfig } from 'storybook-addon-tag-badges'
|
|
|
102
102
|
addons.setConfig({ tagBadges: [newBadge, ...defaultConfig] })
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
###
|
|
105
|
+
### `@storybook-community/storybook-dark-mode`
|
|
106
106
|
|
|
107
|
-
[`@repobuddy/storybook`][`@repobuddy/storybook`] provides a few utilities to work with [
|
|
107
|
+
[`@repobuddy/storybook`][`@repobuddy/storybook`] provides a few utilities to work with [`@storybook-community/storybook-dark-mode`][`@storybook-community/storybook-dark-mode`].
|
|
108
108
|
|
|
109
109
|
```ts
|
|
110
110
|
// .storybook/preview.tsx
|
|
@@ -133,5 +133,5 @@ export const preview: Preview = {
|
|
|
133
133
|
|
|
134
134
|
[`@repobuddy/storybook`]: https://github.com/repobuddy/storybook
|
|
135
135
|
[`storybook-addon-tag-badges`]: https://github.com/Sidnioulz/storybook-addon-tag-badges
|
|
136
|
-
[
|
|
136
|
+
[`@storybook-community/storybook-dark-mode`]: https://github.com/repobuddy/@storybook-community/storybook-dark-mode
|
|
137
137
|
[`storybook-addon-code-editor`]: https://github.com/storybookjs/storybook/tree/main/addons/code/code-editor
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { SyntaxHighlighter } from 'storybook/internal/components'
|
|
1
3
|
import type { Args, DecoratorFunction, Renderer } from 'storybook/internal/csf'
|
|
4
|
+
import { addons } from 'storybook/preview-api'
|
|
5
|
+
import { convert, ThemeProvider, themes } from 'storybook/theming'
|
|
6
|
+
|
|
7
|
+
const channel = addons.getChannel()
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* A decorator that shows the source code of a story above the rendered story.
|
|
@@ -8,18 +14,31 @@ export function showDocSource<TRenderer extends Renderer = Renderer, TArgs = Arg
|
|
|
8
14
|
TRenderer,
|
|
9
15
|
TArgs
|
|
10
16
|
> {
|
|
11
|
-
return (Story, { parameters }) => {
|
|
17
|
+
return (Story, { parameters: { docs, darkMode } }) => {
|
|
18
|
+
// This is a workaround to get the current dark mode from `@storybook-community/storybook-dark-mode` without referencing it.
|
|
19
|
+
const storedItem = window.localStorage.getItem('sb-addon-themes-3')
|
|
20
|
+
const current = typeof storedItem === 'string' ? JSON.parse(storedItem).current : darkMode?.current
|
|
21
|
+
const [isDark, setIsDark] = useState((darkMode?.stylePreview && current === 'dark') ?? false)
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
channel.on('DARK_MODE', setIsDark)
|
|
25
|
+
|
|
26
|
+
return () => channel.off('DARK_MODE', setIsDark)
|
|
27
|
+
}, [])
|
|
28
|
+
|
|
12
29
|
return (
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
30
|
+
<ThemeProvider theme={convert(docs?.theme ?? (isDark ? themes.dark : themes.light))}>
|
|
31
|
+
<section
|
|
32
|
+
style={{
|
|
33
|
+
display: 'flex',
|
|
34
|
+
flexDirection: 'column',
|
|
35
|
+
gap: '1rem'
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
<SyntaxHighlighter language={docs?.source?.language}>{docs?.source?.code}</SyntaxHighlighter>
|
|
39
|
+
<Story />
|
|
40
|
+
</section>
|
|
41
|
+
</ThemeProvider>
|
|
23
42
|
)
|
|
24
43
|
}
|
|
25
44
|
}
|
package/src/index.ts
CHANGED
|
@@ -95,12 +95,12 @@ export interface DocsParam {
|
|
|
95
95
|
/**
|
|
96
96
|
* `docs.description.story` can be used to describe the story in doc.
|
|
97
97
|
*/
|
|
98
|
-
story?: string |
|
|
98
|
+
story?: string | undefined
|
|
99
99
|
/**
|
|
100
100
|
* `docs.description.component` can be used to describe the component in meta.
|
|
101
101
|
* It has no effect on the stories.
|
|
102
102
|
*/
|
|
103
|
-
component?: string |
|
|
103
|
+
component?: string | undefined
|
|
104
104
|
}
|
|
105
105
|
| undefined
|
|
106
106
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Args, Meta as M, StoryObj as SBO } from '@storybook/react-vite'
|
|
2
|
+
import type { ExtendMeta, ExtendStoryObj } from '../types.ts'
|
|
2
3
|
import type { TagNames } from './tag_badges.ts'
|
|
3
4
|
|
|
4
|
-
export type Meta<TCmpOrArgs = Args> =
|
|
5
|
-
tags?: Array<TagNames | (string & {})> | undefined
|
|
6
|
-
}
|
|
5
|
+
export type Meta<TCmpOrArgs = Args> = ExtendMeta<TCmpOrArgs, M<TCmpOrArgs>, { tag: TagNames }>
|
|
7
6
|
|
|
8
|
-
export type StoryObj<TMetaOrCmpOrArgs = Args> =
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export type StoryObj<TMetaOrCmpOrArgs = Args> = ExtendStoryObj<
|
|
8
|
+
TMetaOrCmpOrArgs,
|
|
9
|
+
SBO<TMetaOrCmpOrArgs>,
|
|
10
|
+
{ tag: TagNames }
|
|
11
|
+
>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { DARK_MODE_EVENT_NAME } from '@storybook-community/storybook-dark-mode'
|
|
1
2
|
import { DocsContainer, type DocsContextProps } from '@storybook/addon-docs/blocks'
|
|
2
3
|
import { type PropsWithChildren, useEffect, useState } from 'react'
|
|
3
|
-
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode2'
|
|
4
4
|
import { type ThemeVars, themes } from 'storybook/theming'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Creates a `DocsContainer` for `storybook` that works with
|
|
7
|
+
* Creates a `DocsContainer` for `storybook` that works with `@storybook-community/storybook-dark-mode`.
|
|
8
8
|
*
|
|
9
9
|
* @see https://github.com/hipstersmoothie/storybook-dark-mode/issues/282
|
|
10
10
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CSSProperties } from '@just-web/css'
|
|
2
|
-
import type { ThemeVars } from 'storybook/
|
|
2
|
+
import type { ThemeVars } from 'storybook/theming'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Configuration parameters for
|
|
5
|
+
* Configuration parameters for `@storybook-community/storybook-dark-mode`.
|
|
6
6
|
*/
|
|
7
7
|
export interface DarkModeParam {
|
|
8
8
|
/** The current theme ('dark' or 'light') */
|
|
@@ -36,7 +36,7 @@ export interface DarkModeParam {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Defines
|
|
39
|
+
* Defines `@storybook-community/storybook-dark-mode` parameters for Storybook stories.
|
|
40
40
|
*
|
|
41
41
|
* @see https://storybook.js.org/addons/@storybook/addon-themes#dark-mode
|
|
42
42
|
* @returns An object containing the dark mode parameter configuration
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CSSProperties } from '@just-web/css'
|
|
2
2
|
import { toDOMStyle } from '@just-web/css'
|
|
3
|
-
import { useDarkMode } from 'storybook-dark-
|
|
3
|
+
import { useDarkMode } from '@storybook-community/storybook-dark-mode'
|
|
4
4
|
import type { DecoratorFunction } from 'storybook/internal/types'
|
|
5
5
|
import type { DarkModeParam } from './define_dark_mode.ts'
|
|
6
6
|
|
|
@@ -32,6 +32,7 @@ export function withDarkMode(
|
|
|
32
32
|
const darkMode = parameters.darkMode as DarkModeParam | undefined
|
|
33
33
|
if (!darkMode) return <Story />
|
|
34
34
|
|
|
35
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: on purpose
|
|
35
36
|
const dark = useDarkMode()
|
|
36
37
|
const target = darkMode.classTarget === 'html' ? document.documentElement : document.body
|
|
37
38
|
if (dark) {
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extends the Storybook Meta type with custom tag types
|
|
5
|
+
* @template TCmpOrArgs - The component or args type
|
|
6
|
+
* @template M - The base Meta type
|
|
7
|
+
* @template E - The extension type containing tagType
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Create a generic Meta type for a project
|
|
12
|
+
* type Meta<TCmpOrArgs = Args> = ExtendMeta<TCmpOrArgs, Meta<TCmpOrArgs>, { tagType: 'tag1' | 'tag2' }>
|
|
13
|
+
*
|
|
14
|
+
* // Create a specific Meta type for a component
|
|
15
|
+
* type Meta = ExtendMeta<typeof Component, Meta<typeof Component>, { tagType: 'tag1' | 'tag2' }>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export type ExtendMeta<
|
|
19
|
+
TCmpOrArgs,
|
|
20
|
+
M extends Meta<TCmpOrArgs>,
|
|
21
|
+
E extends {
|
|
22
|
+
tag: string
|
|
23
|
+
}
|
|
24
|
+
> = Omit<M, 'tags'> & {
|
|
25
|
+
tags?: Array<E['tag'] | (string & {})> | undefined
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Extends the Storybook StoryObj type with custom tag types
|
|
30
|
+
* @template TMetaOrCmpOrArgs - The meta, component or args type
|
|
31
|
+
* @template S - The base StoryObj type
|
|
32
|
+
* @template E - The extension type containing tagType
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* // Create a generic StoryObj type for a project
|
|
37
|
+
* type StoryObj<TMetaOrCmpOrArgs = Args> = ExtendStoryObj<TMetaOrCmpOrArgs, StoryObj<TMetaOrCmpOrArgs>, { tagType: 'tag1' | 'tag2' }>
|
|
38
|
+
*
|
|
39
|
+
* // Create a specific StoryObj type for a component
|
|
40
|
+
* type StoryObj = ExtendStoryObj<typeof Component, StoryObj<typeof Component>, { tagType: 'tag1' | 'tag2' }>
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export type ExtendStoryObj<
|
|
44
|
+
TMetaOrCmpOrArgs,
|
|
45
|
+
S extends StoryObj<TMetaOrCmpOrArgs>,
|
|
46
|
+
E extends {
|
|
47
|
+
tag: string
|
|
48
|
+
}
|
|
49
|
+
> = Omit<S, 'tags'> & {
|
|
50
|
+
tags?: Array<E['tag'] | (string & {})> | undefined
|
|
51
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User specifies `@repobuddy/storybook/variants/addon` in the `.storybook/main.ts`.
|
|
3
|
+
*
|
|
4
|
+
* Storybook loads it on the server side.
|
|
5
|
+
*
|
|
6
|
+
* It provides a default export (or in CJS, `module.exports =`) that contains:
|
|
7
|
+
*
|
|
8
|
+
* - `managerEntries` a function that returns an array of strings on where to load the manager (on the client side)
|
|
9
|
+
* - `previewAnnotations` a function that returns an array of strings on where to load the preview (on the client side)
|
|
10
|
+
* - `experimental_serverChannel` a function that handles the server-side channel
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
console.info('variants.preset.js.load')
|
|
14
|
+
|
|
15
|
+
// export const managerEntries = ['@storybook-community/storybook-dark-mode/manager']
|
|
16
|
+
// const previewAnnotations = (entry = []) => [...entry, require.resolve('@storybook-community/storybook-dark-mode')]
|
|
17
|
+
// const previewAnnotations = [ require.resolve('@storybook-community/storybook-dark-mode')]
|
|
18
|
+
|
|
19
|
+
// module.exports = {
|
|
20
|
+
// managerEntries,
|
|
21
|
+
// // previewAnnotations
|
|
22
|
+
// }
|
package/src/overview.mdx
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/addon-docs/blocks'
|
|
2
|
-
|
|
3
|
-
# `createDarkModeDocsContainer`
|
|
4
|
-
|
|
5
|
-
<Meta title="storybook-dark-mode/createDarkModeDocsContainer" />
|
|
6
|
-
|
|
7
|
-
Creates a `DocsContainer` for `storybook` that works with `storybook-dark-mode2`.
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
|
|
11
|
-
It can be called with no arguments to use the default themes from `storybook/theming`.
|
|
12
|
-
|
|
13
|
-
```tsx
|
|
14
|
-
// .storybook/preview.tsx
|
|
15
|
-
import { createDarkModeDocsContainer } from '@repobuddy/storybook/react'
|
|
16
|
-
|
|
17
|
-
export const preview: Preview = {
|
|
18
|
-
parameters: {
|
|
19
|
-
docs: {
|
|
20
|
-
container: createDarkModeDocsContainer()
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
It can also be called with a custom themes.
|
|
27
|
-
|
|
28
|
-
```tsx
|
|
29
|
-
container: createDarkModeDocsContainer({
|
|
30
|
-
light: customThemes.light,
|
|
31
|
-
dark: customThemes.dark
|
|
32
|
-
})
|
|
33
|
-
```
|