@storybook/react-vite 8.6.14 → 10.0.4

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/README.md CHANGED
@@ -1,3 +1,7 @@
1
1
  # Storybook for React & Vite
2
2
 
3
- See [documentation](https://storybook.js.org/docs/get-started/frameworks/react-vite?renderer=react) for installation instructions, usage examples, APIs, and more.
3
+ Develop, document, and test UI components in isolation.
4
+
5
+ See [documentation](https://storybook.js.org/docs/get-started/frameworks/react-vite?renderer=react&ref=readme) for installation instructions, usage examples, APIs, and more.
6
+
7
+ Learn more about Storybook at [storybook.js.org](https://storybook.js.org/?ref=readme).
@@ -0,0 +1,17 @@
1
+ import CJS_COMPAT_NODE_URL_y3pg975sggp from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_y3pg975sggp from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_y3pg975sggp from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_y3pg975sggp.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_y3pg975sggp.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_y3pg975sggp.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ var __defProp = Object.defineProperty;
13
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
+
15
+ export {
16
+ __name
17
+ };
@@ -0,0 +1,217 @@
1
+ import CJS_COMPAT_NODE_URL_y3pg975sggp from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_y3pg975sggp from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_y3pg975sggp from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_y3pg975sggp.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_y3pg975sggp.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_y3pg975sggp.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ __name
14
+ } from "./chunk-IV4SM72Q.js";
15
+
16
+ // src/plugins/react-docgen.ts
17
+ import { existsSync } from "node:fs";
18
+ import { relative, sep } from "node:path";
19
+ import { getProjectRoot } from "storybook/internal/common";
20
+ import { logger } from "storybook/internal/node-logger";
21
+ import { createFilter } from "@rollup/pluginutils";
22
+ import * as find from "empathic/find";
23
+ import MagicString from "magic-string";
24
+ import {
25
+ ERROR_CODES,
26
+ builtinHandlers as docgenHandlers,
27
+ builtinResolvers as docgenResolver,
28
+ makeFsImporter,
29
+ parse
30
+ } from "react-docgen";
31
+ import * as TsconfigPaths from "tsconfig-paths";
32
+
33
+ // src/plugins/docgen-handlers/actualNameHandler.ts
34
+ import { utils } from "react-docgen";
35
+ var { getNameOrValue, isReactForwardRefCall } = utils;
36
+ var actualNameHandler = /* @__PURE__ */ __name(function actualNameHandler2(documentation, componentDefinition) {
37
+ documentation.set("definedInFile", componentDefinition.hub.file.opts.filename);
38
+ if ((componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id")) {
39
+ documentation.set(
40
+ "actualName",
41
+ getNameOrValue(componentDefinition.get("id"))
42
+ );
43
+ } else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
44
+ let currentPath = componentDefinition;
45
+ while (currentPath.parentPath) {
46
+ if (currentPath.parentPath.isVariableDeclarator()) {
47
+ documentation.set("actualName", getNameOrValue(currentPath.parentPath.get("id")));
48
+ return;
49
+ }
50
+ if (currentPath.parentPath.isAssignmentExpression()) {
51
+ const leftPath = currentPath.parentPath.get("left");
52
+ if (leftPath.isIdentifier() || leftPath.isLiteral()) {
53
+ documentation.set("actualName", getNameOrValue(leftPath));
54
+ return;
55
+ }
56
+ }
57
+ currentPath = currentPath.parentPath;
58
+ }
59
+ documentation.set("actualName", "");
60
+ }
61
+ }, "actualNameHandler");
62
+ var actualNameHandler_default = actualNameHandler;
63
+
64
+ // src/plugins/docgen-resolver.ts
65
+ import { extname } from "node:path";
66
+ import resolve from "resolve";
67
+ var ReactDocgenResolveError = class extends Error {
68
+ constructor(filename) {
69
+ super(`'${filename}' was ignored by react-docgen.`);
70
+ // the magic string that react-docgen uses to check if a module is ignored
71
+ this.code = "MODULE_NOT_FOUND";
72
+ }
73
+ static {
74
+ __name(this, "ReactDocgenResolveError");
75
+ }
76
+ };
77
+ var RESOLVE_EXTENSIONS = [
78
+ ".js",
79
+ ".cts",
80
+ // These were originally not in the code, I added them
81
+ ".mts",
82
+ // These were originally not in the code, I added them
83
+ ".ctsx",
84
+ // These were originally not in the code, I added them
85
+ ".mtsx",
86
+ // These were originally not in the code, I added them
87
+ ".ts",
88
+ ".tsx",
89
+ ".mjs",
90
+ ".cjs",
91
+ ".mts",
92
+ ".cts",
93
+ ".jsx"
94
+ ];
95
+ function defaultLookupModule(filename, basedir) {
96
+ const resolveOptions = {
97
+ basedir,
98
+ extensions: RESOLVE_EXTENSIONS,
99
+ // we do not need to check core modules as we cannot import them anyway
100
+ includeCoreModules: false
101
+ };
102
+ try {
103
+ return resolve.sync(filename, resolveOptions);
104
+ } catch (error) {
105
+ const ext = extname(filename);
106
+ let newFilename;
107
+ switch (ext) {
108
+ case ".js":
109
+ case ".mjs":
110
+ case ".cjs":
111
+ newFilename = `${filename.slice(0, -2)}ts`;
112
+ break;
113
+ case ".jsx":
114
+ newFilename = `${filename.slice(0, -3)}tsx`;
115
+ break;
116
+ default:
117
+ throw error;
118
+ }
119
+ return resolve.sync(newFilename, {
120
+ ...resolveOptions,
121
+ // we already know that there is an extension at this point, so no need to check other extensions
122
+ extensions: []
123
+ });
124
+ }
125
+ }
126
+ __name(defaultLookupModule, "defaultLookupModule");
127
+
128
+ // src/plugins/react-docgen.ts
129
+ var defaultHandlers = Object.values(docgenHandlers).map((handler) => handler);
130
+ var defaultResolver = new docgenResolver.FindExportedDefinitionsResolver();
131
+ var handlers = [...defaultHandlers, actualNameHandler_default];
132
+ async function reactDocgen({
133
+ include = /\.(mjs|tsx?|jsx?)$/,
134
+ exclude = [/node_modules\/.*/]
135
+ } = {}) {
136
+ const cwd = process.cwd();
137
+ const filter = createFilter(include, exclude);
138
+ const tsconfigPath = find.up("tsconfig.json", { cwd, last: getProjectRoot() });
139
+ const tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
140
+ let matchPath;
141
+ if (tsconfig.resultType === "success") {
142
+ logger.info("Using tsconfig paths for react-docgen");
143
+ matchPath = TsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths, [
144
+ "browser",
145
+ "module",
146
+ "main"
147
+ ]);
148
+ }
149
+ return {
150
+ name: "storybook:react-docgen-plugin",
151
+ enforce: "pre",
152
+ async transform(src, id) {
153
+ if (!filter(relative(cwd, id))) {
154
+ return;
155
+ }
156
+ try {
157
+ const docgenResults = parse(src, {
158
+ resolver: defaultResolver,
159
+ handlers,
160
+ importer: getReactDocgenImporter(matchPath),
161
+ filename: id
162
+ });
163
+ const s = new MagicString(src);
164
+ docgenResults.forEach((info) => {
165
+ const { actualName, definedInFile, ...docgenInfo } = info;
166
+ if (actualName && definedInFile == id) {
167
+ const docNode = JSON.stringify(docgenInfo);
168
+ s.append(`;${actualName}.__docgenInfo=${docNode}`);
169
+ }
170
+ });
171
+ return {
172
+ code: s.toString(),
173
+ map: s.generateMap({ hires: true, source: id })
174
+ };
175
+ } catch (e) {
176
+ if (e.code === ERROR_CODES.MISSING_DEFINITION) {
177
+ return;
178
+ }
179
+ throw e;
180
+ }
181
+ }
182
+ };
183
+ }
184
+ __name(reactDocgen, "reactDocgen");
185
+ function getReactDocgenImporter(matchPath) {
186
+ return makeFsImporter((filename, basedir) => {
187
+ const mappedFilenameByPaths = (() => {
188
+ if (matchPath) {
189
+ const match = matchPath(filename);
190
+ return match || filename;
191
+ } else {
192
+ return filename;
193
+ }
194
+ })();
195
+ const result = defaultLookupModule(mappedFilenameByPaths, basedir);
196
+ if (result.includes(`${sep}react-native${sep}index.js`)) {
197
+ const replaced = result.replace(
198
+ `${sep}react-native${sep}index.js`,
199
+ `${sep}react-native-web${sep}dist${sep}index.js`
200
+ );
201
+ if (existsSync(replaced)) {
202
+ if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
203
+ return replaced;
204
+ }
205
+ }
206
+ }
207
+ if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
208
+ return result;
209
+ }
210
+ throw new ReactDocgenResolveError(filename);
211
+ });
212
+ }
213
+ __name(getReactDocgenImporter, "getReactDocgenImporter");
214
+ export {
215
+ getReactDocgenImporter,
216
+ reactDocgen
217
+ };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ export * from '@storybook/react';
1
2
  export { __definePreview as definePreview } from '@storybook/react';
2
- import { StorybookConfig as StorybookConfig$1, TypescriptOptions as TypescriptOptions$1, CompatibleString } from 'storybook/internal/types';
3
+ import { StorybookConfig as StorybookConfig$1, CompatibleString, TypescriptOptions as TypescriptOptions$1 } from 'storybook/internal/types';
3
4
  import { BuilderOptions, StorybookConfigVite } from '@storybook/builder-vite';
4
5
  import docgenTypescript from '@joshwooding/vite-plugin-react-docgen-typescript';
5
6
 
@@ -30,6 +31,14 @@ type StorybookConfigFramework = {
30
31
  options: BuilderOptions;
31
32
  };
32
33
  };
34
+ features?: StorybookConfig$1['features'] & {
35
+ /**
36
+ * Enable the experimental `.test` function in CSF Next
37
+ *
38
+ * @see https://storybook.js.org/docs/10/api/main-config/main-config-features#experimentalTestSyntax
39
+ */
40
+ experimentalTestSyntax?: boolean;
41
+ };
33
42
  };
34
43
  type TypescriptOptions = TypescriptOptions$1 & {
35
44
  /**
@@ -46,4 +55,4 @@ type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigVite | keyof
46
55
  typescript?: Partial<TypescriptOptions>;
47
56
  };
48
57
 
49
- export { FrameworkOptions, StorybookConfig };
58
+ export type { FrameworkOptions, StorybookConfig };
package/dist/index.js CHANGED
@@ -1 +1,6 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var index_exports={};__export(index_exports,{definePreview:()=>import_react.__definePreview});module.exports=__toCommonJS(index_exports);var import_react=require("@storybook/react");0&&(module.exports={definePreview});
1
+ // src/index.ts
2
+ export * from "@storybook/react";
3
+ import { __definePreview } from "@storybook/react";
4
+ export {
5
+ __definePreview as definePreview
6
+ };
@@ -1,8 +1,57 @@
1
- import { StorybookConfig } from '../index.js';
2
- import '@storybook/react';
3
- import 'storybook/internal/types';
4
- import '@storybook/builder-vite';
5
- import '@joshwooding/vite-plugin-react-docgen-typescript';
1
+ import { StorybookConfig as StorybookConfig$1, CompatibleString, TypescriptOptions as TypescriptOptions$1 } from 'storybook/internal/types';
2
+ import { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite';
3
+ import docgenTypescript from '@joshwooding/vite-plugin-react-docgen-typescript';
4
+
5
+ type FrameworkName = CompatibleString<'@storybook/react-vite'>;
6
+ type BuilderName = CompatibleString<'@storybook/builder-vite'>;
7
+ type FrameworkOptions = {
8
+ builder?: BuilderOptions;
9
+ strictMode?: boolean;
10
+ /**
11
+ * Use React's legacy root API to mount components
12
+ *
13
+ * React has introduced a new root API with React 18.x to enable a whole set of new features (e.g.
14
+ * concurrent features) If this flag is true, the legacy Root API is used to mount components to
15
+ * make it easier to migrate step by step to React 18.
16
+ *
17
+ * @default false
18
+ */
19
+ legacyRootApi?: boolean;
20
+ };
21
+ type StorybookConfigFramework = {
22
+ framework: FrameworkName | {
23
+ name: FrameworkName;
24
+ options: FrameworkOptions;
25
+ };
26
+ core?: StorybookConfig$1['core'] & {
27
+ builder?: BuilderName | {
28
+ name: BuilderName;
29
+ options: BuilderOptions;
30
+ };
31
+ };
32
+ features?: StorybookConfig$1['features'] & {
33
+ /**
34
+ * Enable the experimental `.test` function in CSF Next
35
+ *
36
+ * @see https://storybook.js.org/docs/10/api/main-config/main-config-features#experimentalTestSyntax
37
+ */
38
+ experimentalTestSyntax?: boolean;
39
+ };
40
+ };
41
+ type TypescriptOptions = TypescriptOptions$1 & {
42
+ /**
43
+ * Sets the type of Docgen when working with React and TypeScript
44
+ *
45
+ * @default `'react-docgen'`
46
+ */
47
+ reactDocgen: 'react-docgen-typescript' | 'react-docgen' | false;
48
+ /** Configures `@joshwooding/vite-plugin-react-docgen-typescript` */
49
+ reactDocgenTypescriptOptions: Parameters<typeof docgenTypescript>[0];
50
+ };
51
+ /** The interface for Storybook configuration in `main.ts` files. */
52
+ type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigVite | keyof StorybookConfigFramework | 'typescript'> & StorybookConfigVite & StorybookConfigFramework & {
53
+ typescript?: Partial<TypescriptOptions>;
54
+ };
6
55
 
7
56
  declare function defineMain(config: StorybookConfig): StorybookConfig;
8
57
 
@@ -1 +1,23 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var node_exports={};__export(node_exports,{defineMain:()=>defineMain});module.exports=__toCommonJS(node_exports);function defineMain(config){return config}0&&(module.exports={defineMain});
1
+ import CJS_COMPAT_NODE_URL_y3pg975sggp from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_y3pg975sggp from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_y3pg975sggp from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_y3pg975sggp.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_y3pg975sggp.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_y3pg975sggp.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ __name
14
+ } from "../_node-chunks/chunk-IV4SM72Q.js";
15
+
16
+ // src/node/index.ts
17
+ function defineMain(config) {
18
+ return config;
19
+ }
20
+ __name(defineMain, "defineMain");
21
+ export {
22
+ defineMain
23
+ };
package/dist/preset.d.ts CHANGED
@@ -1,8 +1,57 @@
1
- import { PresetProperty } from 'storybook/internal/types';
2
- import { StorybookConfig } from './index.js';
3
- import '@storybook/react';
4
- import '@storybook/builder-vite';
5
- import '@joshwooding/vite-plugin-react-docgen-typescript';
1
+ import { StorybookConfig as StorybookConfig$1, CompatibleString, TypescriptOptions as TypescriptOptions$1, PresetProperty } from 'storybook/internal/types';
2
+ import { StorybookConfigVite, BuilderOptions } from '@storybook/builder-vite';
3
+ import docgenTypescript from '@joshwooding/vite-plugin-react-docgen-typescript';
4
+
5
+ type FrameworkName = CompatibleString<'@storybook/react-vite'>;
6
+ type BuilderName = CompatibleString<'@storybook/builder-vite'>;
7
+ type FrameworkOptions = {
8
+ builder?: BuilderOptions;
9
+ strictMode?: boolean;
10
+ /**
11
+ * Use React's legacy root API to mount components
12
+ *
13
+ * React has introduced a new root API with React 18.x to enable a whole set of new features (e.g.
14
+ * concurrent features) If this flag is true, the legacy Root API is used to mount components to
15
+ * make it easier to migrate step by step to React 18.
16
+ *
17
+ * @default false
18
+ */
19
+ legacyRootApi?: boolean;
20
+ };
21
+ type StorybookConfigFramework = {
22
+ framework: FrameworkName | {
23
+ name: FrameworkName;
24
+ options: FrameworkOptions;
25
+ };
26
+ core?: StorybookConfig$1['core'] & {
27
+ builder?: BuilderName | {
28
+ name: BuilderName;
29
+ options: BuilderOptions;
30
+ };
31
+ };
32
+ features?: StorybookConfig$1['features'] & {
33
+ /**
34
+ * Enable the experimental `.test` function in CSF Next
35
+ *
36
+ * @see https://storybook.js.org/docs/10/api/main-config/main-config-features#experimentalTestSyntax
37
+ */
38
+ experimentalTestSyntax?: boolean;
39
+ };
40
+ };
41
+ type TypescriptOptions = TypescriptOptions$1 & {
42
+ /**
43
+ * Sets the type of Docgen when working with React and TypeScript
44
+ *
45
+ * @default `'react-docgen'`
46
+ */
47
+ reactDocgen: 'react-docgen-typescript' | 'react-docgen' | false;
48
+ /** Configures `@joshwooding/vite-plugin-react-docgen-typescript` */
49
+ reactDocgenTypescriptOptions: Parameters<typeof docgenTypescript>[0];
50
+ };
51
+ /** The interface for Storybook configuration in `main.ts` files. */
52
+ type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigVite | keyof StorybookConfigFramework | 'typescript'> & StorybookConfigVite & StorybookConfigFramework & {
53
+ typescript?: Partial<TypescriptOptions>;
54
+ };
6
55
 
7
56
  declare const core: PresetProperty<'core'>;
8
57
  declare const viteFinal: NonNullable<StorybookConfig['viteFinal']>;
package/dist/preset.js CHANGED
@@ -1 +1,57 @@
1
- "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __esm=(fn,res)=>function(){return fn&&(res=(0,fn[__getOwnPropNames(fn)[0]])(fn=0)),res};var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var import_react_docgen,getNameOrValue,isReactForwardRefCall,actualNameHandler,actualNameHandler_default,init_actualNameHandler=__esm({"src/plugins/docgen-handlers/actualNameHandler.ts"(){"use strict";import_react_docgen=require("react-docgen"),{getNameOrValue,isReactForwardRefCall}=import_react_docgen.utils,actualNameHandler=function(documentation,componentDefinition){if(documentation.set("definedInFile",componentDefinition.hub.file.opts.filename),(componentDefinition.isClassDeclaration()||componentDefinition.isFunctionDeclaration())&&componentDefinition.has("id"))documentation.set("actualName",getNameOrValue(componentDefinition.get("id")));else if(componentDefinition.isArrowFunctionExpression()||componentDefinition.isFunctionExpression()||isReactForwardRefCall(componentDefinition)){let currentPath=componentDefinition;for(;currentPath.parentPath;){if(currentPath.parentPath.isVariableDeclarator()){documentation.set("actualName",getNameOrValue(currentPath.parentPath.get("id")));return}if(currentPath.parentPath.isAssignmentExpression()){let leftPath=currentPath.parentPath.get("left");if(leftPath.isIdentifier()||leftPath.isLiteral()){documentation.set("actualName",getNameOrValue(leftPath));return}}currentPath=currentPath.parentPath}documentation.set("actualName","")}},actualNameHandler_default=actualNameHandler}});function defaultLookupModule(filename,basedir){let resolveOptions={basedir,extensions:RESOLVE_EXTENSIONS,includeCoreModules:!1};try{return import_resolve.default.sync(filename,resolveOptions)}catch(error){let ext=(0,import_node_path.extname)(filename),newFilename;switch(ext){case".js":case".mjs":case".cjs":newFilename=`${filename.slice(0,-2)}ts`;break;case".jsx":newFilename=`${filename.slice(0,-3)}tsx`;break;default:throw error}return import_resolve.default.sync(newFilename,{...resolveOptions,extensions:[]})}}var import_node_path,import_resolve,ReactDocgenResolveError,RESOLVE_EXTENSIONS,init_docgen_resolver=__esm({"src/plugins/docgen-resolver.ts"(){"use strict";import_node_path=require("path"),import_resolve=__toESM(require("resolve")),ReactDocgenResolveError=class extends Error{constructor(filename){super(`'${filename}' was ignored by react-docgen.`);this.code="MODULE_NOT_FOUND"}},RESOLVE_EXTENSIONS=[".js",".cts",".mts",".ctsx",".mtsx",".ts",".tsx",".mjs",".cjs",".mts",".cts",".jsx"]}});var react_docgen_exports={};__export(react_docgen_exports,{getReactDocgenImporter:()=>getReactDocgenImporter,reactDocgen:()=>reactDocgen});async function reactDocgen({include=/\.(mjs|tsx?|jsx?)$/,exclude=[/node_modules\/.*/]}={}){let cwd=process.cwd(),filter=(0,import_pluginutils.createFilter)(include,exclude),tsconfigPath=await(0,import_find_up.default)("tsconfig.json",{cwd}),tsconfig=TsconfigPaths.loadConfig(tsconfigPath),matchPath;return tsconfig.resultType==="success"&&(import_node_logger.logger.info("Using tsconfig paths for react-docgen"),matchPath=TsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl,tsconfig.paths,["browser","module","main"])),{name:"storybook:react-docgen-plugin",enforce:"pre",async transform(src,id){if(filter((0,import_node_path2.relative)(cwd,id)))try{let docgenResults=(0,import_react_docgen2.parse)(src,{resolver:defaultResolver,handlers,importer:getReactDocgenImporter(matchPath),filename:id}),s=new import_magic_string.default(src);return docgenResults.forEach(info=>{let{actualName,definedInFile,...docgenInfo}=info;if(actualName&&definedInFile==id){let docNode=JSON.stringify(docgenInfo);s.append(`;${actualName}.__docgenInfo=${docNode}`)}}),{code:s.toString(),map:s.generateMap({hires:!0,source:id})}}catch(e){if(e.code===import_react_docgen2.ERROR_CODES.MISSING_DEFINITION)return;throw e}}}}function getReactDocgenImporter(matchPath){return(0,import_react_docgen2.makeFsImporter)((filename,basedir)=>{let mappedFilenameByPaths=matchPath&&matchPath(filename)||filename,result=defaultLookupModule(mappedFilenameByPaths,basedir);if(result.includes(`${import_node_path2.sep}react-native${import_node_path2.sep}index.js`)){let replaced=result.replace(`${import_node_path2.sep}react-native${import_node_path2.sep}index.js`,`${import_node_path2.sep}react-native-web${import_node_path2.sep}dist${import_node_path2.sep}index.js`);if((0,import_node_fs.existsSync)(replaced)&&RESOLVE_EXTENSIONS.find(ext=>result.endsWith(ext)))return replaced}if(RESOLVE_EXTENSIONS.find(ext=>result.endsWith(ext)))return result;throw new ReactDocgenResolveError(filename)})}var import_node_fs,import_node_path2,import_node_logger,import_pluginutils,import_find_up,import_magic_string,import_react_docgen2,TsconfigPaths,defaultHandlers,defaultResolver,handlers,init_react_docgen=__esm({"src/plugins/react-docgen.ts"(){"use strict";import_node_fs=require("fs"),import_node_path2=require("path"),import_node_logger=require("storybook/internal/node-logger"),import_pluginutils=require("@rollup/pluginutils"),import_find_up=__toESM(require("find-up")),import_magic_string=__toESM(require("magic-string")),import_react_docgen2=require("react-docgen"),TsconfigPaths=__toESM(require("tsconfig-paths"));init_actualNameHandler();init_docgen_resolver();defaultHandlers=Object.values(import_react_docgen2.builtinHandlers).map(handler=>handler),defaultResolver=new import_react_docgen2.builtinResolvers.FindExportedDefinitionsResolver,handlers=[...defaultHandlers,actualNameHandler_default]}});var preset_exports={};__export(preset_exports,{core:()=>core,viteFinal:()=>viteFinal});module.exports=__toCommonJS(preset_exports);var import_node_path3=require("path"),getAbsolutePath=input=>(0,import_node_path3.dirname)(require.resolve((0,import_node_path3.join)(input,"package.json"))),core={builder:getAbsolutePath("@storybook/builder-vite"),renderer:getAbsolutePath("@storybook/react")},viteFinal=async(config,{presets})=>{let plugins=[...config?.plugins??[]],{reactDocgen:reactDocgenOption,reactDocgenTypescriptOptions}=await presets.apply("typescript",{}),typescriptPresent;try{require.resolve("typescript"),typescriptPresent=!0}catch{typescriptPresent=!1}if(reactDocgenOption==="react-docgen-typescript"&&typescriptPresent&&plugins.push(require("@joshwooding/vite-plugin-react-docgen-typescript")({...reactDocgenTypescriptOptions,savePropValueAsString:!0})),typeof reactDocgenOption=="string"){let{reactDocgen:reactDocgen2}=await Promise.resolve().then(()=>(init_react_docgen(),react_docgen_exports));plugins.unshift(await reactDocgen2({include:reactDocgenOption==="react-docgen"?/\.(mjs|tsx?|jsx?)$/:/\.(mjs|jsx?)$/}))}return{...config,plugins}};0&&(module.exports={core,viteFinal});
1
+ import CJS_COMPAT_NODE_URL_y3pg975sggp from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_y3pg975sggp from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_y3pg975sggp from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_y3pg975sggp.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_y3pg975sggp.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_y3pg975sggp.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ __name
14
+ } from "./_node-chunks/chunk-IV4SM72Q.js";
15
+
16
+ // src/preset.ts
17
+ var core = {
18
+ builder: import.meta.resolve("@storybook/builder-vite"),
19
+ renderer: import.meta.resolve("@storybook/react/preset")
20
+ };
21
+ var viteFinal = /* @__PURE__ */ __name(async (config, { presets }) => {
22
+ const plugins = [...config?.plugins ?? []];
23
+ const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply(
24
+ "typescript",
25
+ {}
26
+ );
27
+ let typescriptPresent;
28
+ try {
29
+ import.meta.resolve("typescript");
30
+ typescriptPresent = true;
31
+ } catch (e) {
32
+ typescriptPresent = false;
33
+ }
34
+ if (reactDocgenOption === "react-docgen-typescript" && typescriptPresent) {
35
+ plugins.push(
36
+ (await import("@joshwooding/vite-plugin-react-docgen-typescript")).default({
37
+ ...reactDocgenTypescriptOptions,
38
+ // We *need* this set so that RDT returns default values in the same format as react-docgen
39
+ savePropValueAsString: true
40
+ })
41
+ );
42
+ }
43
+ if (typeof reactDocgenOption === "string") {
44
+ const { reactDocgen } = await import("./_node-chunks/react-docgen-ARJA47DN.js");
45
+ plugins.unshift(
46
+ // If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files
47
+ await reactDocgen({
48
+ include: reactDocgenOption === "react-docgen" ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/
49
+ })
50
+ );
51
+ }
52
+ return { ...config, plugins };
53
+ }, "viteFinal");
54
+ export {
55
+ core,
56
+ viteFinal
57
+ };
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@storybook/react-vite",
3
- "version": "8.6.14",
4
- "description": "Storybook for React and Vite: Develop React components in isolation with Hot Reloading.",
3
+ "version": "10.0.4",
4
+ "description": "Storybook for React and Vite: Develop, document, and test UI components in isolation",
5
5
  "keywords": [
6
- "storybook"
6
+ "storybook",
7
+ "storybook-framework",
8
+ "react",
9
+ "vite",
10
+ "component",
11
+ "components"
7
12
  ],
8
13
  "homepage": "https://github.com/storybookjs/storybook/tree/next/code/frameworks/react-vite",
9
14
  "bugs": {
@@ -19,93 +24,58 @@
19
24
  "url": "https://opencollective.com/storybook"
20
25
  },
21
26
  "license": "MIT",
27
+ "type": "module",
22
28
  "exports": {
23
29
  ".": {
24
30
  "types": "./dist/index.d.ts",
25
- "node": "./dist/index.js",
26
- "import": "./dist/index.mjs",
27
- "require": "./dist/index.js"
28
- },
29
- "./preset": {
30
- "types": "./dist/preset.d.ts",
31
- "require": "./dist/preset.js"
31
+ "default": "./dist/index.js"
32
32
  },
33
33
  "./node": {
34
34
  "types": "./dist/node/index.d.ts",
35
- "node": "./dist/node/index.js",
36
- "import": "./dist/node/index.mjs",
37
- "require": "./dist/node/index.js"
35
+ "default": "./dist/node/index.js"
38
36
  },
39
- "./package.json": "./package.json"
40
- },
41
- "main": "dist/index.js",
42
- "module": "dist/index.mjs",
43
- "types": "dist/index.d.ts",
44
- "typesVersions": {
45
- "*": {
46
- "*": [
47
- "dist/index.d.ts"
48
- ],
49
- "preset": [
50
- "dist/preset.d.ts"
51
- ],
52
- "node": [
53
- "dist/node/index.d.ts"
54
- ]
37
+ "./package.json": "./package.json",
38
+ "./preset": {
39
+ "types": "./dist/preset.d.ts",
40
+ "default": "./dist/preset.js"
55
41
  }
56
42
  },
57
43
  "files": [
58
44
  "dist/**/*",
45
+ "template/**/*",
59
46
  "README.md",
60
47
  "*.js",
61
48
  "*.d.ts",
62
49
  "!src/**/*"
63
50
  ],
64
51
  "scripts": {
65
- "check": "jiti ../../../scripts/prepare/check.ts",
66
- "prep": "jiti ../../../scripts/prepare/bundle.ts"
52
+ "check": "jiti ../../../scripts/check/check-package.ts",
53
+ "prep": "jiti ../../../scripts/build/build-package.ts"
67
54
  },
68
55
  "dependencies": {
69
- "@joshwooding/vite-plugin-react-docgen-typescript": "0.5.0",
56
+ "@joshwooding/vite-plugin-react-docgen-typescript": "0.6.1",
70
57
  "@rollup/pluginutils": "^5.0.2",
71
- "@storybook/builder-vite": "8.6.14",
72
- "@storybook/react": "8.6.14",
73
- "find-up": "^5.0.0",
58
+ "@storybook/builder-vite": "10.0.4",
59
+ "@storybook/react": "10.0.4",
60
+ "empathic": "^2.0.0",
74
61
  "magic-string": "^0.30.0",
75
- "react-docgen": "^7.0.0",
62
+ "react-docgen": "^8.0.0",
76
63
  "resolve": "^1.22.8",
77
64
  "tsconfig-paths": "^4.2.0"
78
65
  },
79
66
  "devDependencies": {
80
67
  "@types/node": "^22.0.0",
81
- "typescript": "^5.7.3",
82
- "vite": "^4.0.0"
68
+ "typescript": "^5.8.3",
69
+ "vite": "^7.0.4"
83
70
  },
84
71
  "peerDependencies": {
85
- "@storybook/test": "8.6.14",
86
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
87
- "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
88
- "storybook": "^8.6.14",
89
- "vite": "^4.0.0 || ^5.0.0 || ^6.0.0"
90
- },
91
- "peerDependenciesMeta": {
92
- "@storybook/test": {
93
- "optional": true
94
- }
95
- },
96
- "engines": {
97
- "node": ">=18.0.0"
72
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
73
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
74
+ "storybook": "^10.0.4",
75
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
98
76
  },
99
77
  "publishConfig": {
100
78
  "access": "public"
101
79
  },
102
- "bundler": {
103
- "entries": [
104
- "./src/index.ts",
105
- "./src/preset.ts",
106
- "./src/node/index.ts"
107
- ],
108
- "platform": "node"
109
- },
110
- "gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae16"
80
+ "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae16"
111
81
  }
package/preset.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/preset');
1
+ export * from './dist/preset.js';
@@ -0,0 +1,5 @@
1
+ {
2
+ "rules": {
3
+ "import/extensions": "off"
4
+ }
5
+ }
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+
3
+ import PropTypes from 'prop-types';
4
+
5
+ import './button.css';
6
+
7
+ /** Primary UI component for user interaction */
8
+ export const Button = ({
9
+ primary = false,
10
+ backgroundColor = null,
11
+ size = 'medium',
12
+ label,
13
+ ...props
14
+ }) => {
15
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
16
+ return (
17
+ <button
18
+ type="button"
19
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
20
+ style={backgroundColor && { backgroundColor }}
21
+ {...props}
22
+ >
23
+ {label}
24
+ </button>
25
+ );
26
+ };
27
+
28
+ Button.propTypes = {
29
+ /** Is this the principal call to action on the page? */
30
+ primary: PropTypes.bool,
31
+ /** What background color to use */
32
+ backgroundColor: PropTypes.string,
33
+ /** How large should the button be? */
34
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
35
+ /** Button contents */
36
+ label: PropTypes.string.isRequired,
37
+ /** Optional click handler */
38
+ onClick: PropTypes.func,
39
+ };
@@ -0,0 +1,49 @@
1
+ import { fn } from 'storybook/test';
2
+
3
+ import { Button } from './Button';
4
+
5
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
6
+ export default {
7
+ title: 'Example/Button',
8
+ component: Button,
9
+ parameters: {
10
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
11
+ layout: 'centered',
12
+ },
13
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
14
+ tags: ['autodocs'],
15
+ // More on argTypes: https://storybook.js.org/docs/api/argtypes
16
+ argTypes: {
17
+ backgroundColor: { control: 'color' },
18
+ },
19
+ // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#story-args
20
+ args: { onClick: fn() },
21
+ };
22
+
23
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
24
+ export const Primary = {
25
+ args: {
26
+ primary: true,
27
+ label: 'Button',
28
+ },
29
+ };
30
+
31
+ export const Secondary = {
32
+ args: {
33
+ label: 'Button',
34
+ },
35
+ };
36
+
37
+ export const Large = {
38
+ args: {
39
+ size: 'large',
40
+ label: 'Button',
41
+ },
42
+ };
43
+
44
+ export const Small = {
45
+ args: {
46
+ size: 'small',
47
+ label: 'Button',
48
+ },
49
+ };
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+
3
+ import PropTypes from 'prop-types';
4
+
5
+ import { Button } from './Button';
6
+ import './header.css';
7
+
8
+ export const Header = ({ user = null, onLogin, onLogout, onCreateAccount }) => (
9
+ <header>
10
+ <div className="storybook-header">
11
+ <div>
12
+ <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
13
+ <g fill="none" fillRule="evenodd">
14
+ <path
15
+ d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
16
+ fill="#FFF"
17
+ />
18
+ <path
19
+ d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
20
+ fill="#555AB9"
21
+ />
22
+ <path
23
+ d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
24
+ fill="#91BAF8"
25
+ />
26
+ </g>
27
+ </svg>
28
+ <h1>Acme</h1>
29
+ </div>
30
+ <div>
31
+ {user ? (
32
+ <>
33
+ <span className="welcome">
34
+ Welcome, <b>{user.name}</b>!
35
+ </span>
36
+ <Button size="small" onClick={onLogout} label="Log out" />
37
+ </>
38
+ ) : (
39
+ <>
40
+ <Button size="small" onClick={onLogin} label="Log in" />
41
+ <Button primary size="small" onClick={onCreateAccount} label="Sign up" />
42
+ </>
43
+ )}
44
+ </div>
45
+ </div>
46
+ </header>
47
+ );
48
+
49
+ Header.propTypes = {
50
+ user: PropTypes.shape({
51
+ name: PropTypes.string.isRequired,
52
+ }),
53
+ onLogin: PropTypes.func.isRequired,
54
+ onLogout: PropTypes.func.isRequired,
55
+ onCreateAccount: PropTypes.func.isRequired,
56
+ };
@@ -0,0 +1,29 @@
1
+ import { fn } from 'storybook/test';
2
+
3
+ import { Header } from './Header';
4
+
5
+ export default {
6
+ title: 'Example/Header',
7
+ component: Header,
8
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
9
+ tags: ['autodocs'],
10
+ parameters: {
11
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
12
+ layout: 'fullscreen',
13
+ },
14
+ args: {
15
+ onLogin: fn(),
16
+ onLogout: fn(),
17
+ onCreateAccount: fn(),
18
+ },
19
+ };
20
+
21
+ export const LoggedIn = {
22
+ args: {
23
+ user: {
24
+ name: 'Jane Doe',
25
+ },
26
+ },
27
+ };
28
+
29
+ export const LoggedOut = {};
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+
3
+ import { Header } from './Header';
4
+ import './page.css';
5
+
6
+ export const Page = () => {
7
+ const [user, setUser] = React.useState();
8
+
9
+ return (
10
+ <article>
11
+ <Header
12
+ user={user}
13
+ onLogin={() => setUser({ name: 'Jane Doe' })}
14
+ onLogout={() => setUser(undefined)}
15
+ onCreateAccount={() => setUser({ name: 'Jane Doe' })}
16
+ />
17
+
18
+ <section className="storybook-page">
19
+ <h2>Pages in Storybook</h2>
20
+ <p>
21
+ We recommend building UIs with a{' '}
22
+ <a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
23
+ <strong>component-driven</strong>
24
+ </a>{' '}
25
+ process starting with atomic components and ending with pages.
26
+ </p>
27
+ <p>
28
+ Render pages with mock data. This makes it easy to build and review page states without
29
+ needing to navigate to them in your app. Here are some handy patterns for managing page
30
+ data in Storybook:
31
+ </p>
32
+ <ul>
33
+ <li>
34
+ Use a higher-level connected component. Storybook helps you compose such data from the
35
+ "args" of child component stories
36
+ </li>
37
+ <li>
38
+ Assemble data in the page component from your services. You can mock these services out
39
+ using Storybook.
40
+ </li>
41
+ </ul>
42
+ <p>
43
+ Get a guided tutorial on component-driven development at{' '}
44
+ <a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
45
+ Storybook tutorials
46
+ </a>
47
+ . Read more in the{' '}
48
+ <a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
49
+ docs
50
+ </a>
51
+ .
52
+ </p>
53
+ <div className="tip-wrapper">
54
+ <span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
55
+ <svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
56
+ <g fill="none" fillRule="evenodd">
57
+ <path
58
+ d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
59
+ id="a"
60
+ fill="#999"
61
+ />
62
+ </g>
63
+ </svg>
64
+ Viewports addon in the toolbar
65
+ </div>
66
+ </section>
67
+ </article>
68
+ );
69
+ };
@@ -0,0 +1,28 @@
1
+ import { expect, userEvent, within } from 'storybook/test';
2
+
3
+ import { Page } from './Page';
4
+
5
+ export default {
6
+ title: 'Example/Page',
7
+ component: Page,
8
+ parameters: {
9
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
12
+ };
13
+
14
+ export const LoggedOut = {};
15
+
16
+ // More on component testing: https://storybook.js.org/docs/writing-tests/interaction-testing
17
+ export const LoggedIn = {
18
+ play: async ({ canvasElement }) => {
19
+ const canvas = within(canvasElement);
20
+ const loginButton = canvas.getByRole('button', { name: /Log in/i });
21
+ await expect(loginButton).toBeInTheDocument();
22
+ await userEvent.click(loginButton);
23
+ await expect(loginButton).not.toBeInTheDocument();
24
+
25
+ const logoutButton = canvas.getByRole('button', { name: /Log out/i });
26
+ await expect(logoutButton).toBeInTheDocument();
27
+ },
28
+ };
@@ -0,0 +1,54 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+
3
+ import { fn } from 'storybook/test';
4
+
5
+ import { Button } from './Button';
6
+
7
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
8
+ const meta = {
9
+ title: 'Example/Button',
10
+ component: Button,
11
+ parameters: {
12
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
13
+ layout: 'centered',
14
+ },
15
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
16
+ tags: ['autodocs'],
17
+ // More on argTypes: https://storybook.js.org/docs/api/argtypes
18
+ argTypes: {
19
+ backgroundColor: { control: 'color' },
20
+ },
21
+ // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#story-args
22
+ args: { onClick: fn() },
23
+ } satisfies Meta<typeof Button>;
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
29
+ export const Primary: Story = {
30
+ args: {
31
+ primary: true,
32
+ label: 'Button',
33
+ },
34
+ };
35
+
36
+ export const Secondary: Story = {
37
+ args: {
38
+ label: 'Button',
39
+ },
40
+ };
41
+
42
+ export const Large: Story = {
43
+ args: {
44
+ size: 'large',
45
+ label: 'Button',
46
+ },
47
+ };
48
+
49
+ export const Small: Story = {
50
+ args: {
51
+ size: 'small',
52
+ label: 'Button',
53
+ },
54
+ };
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+
3
+ import './button.css';
4
+
5
+ export interface ButtonProps {
6
+ /** Is this the principal call to action on the page? */
7
+ primary?: boolean;
8
+ /** What background color to use */
9
+ backgroundColor?: string;
10
+ /** How large should the button be? */
11
+ size?: 'small' | 'medium' | 'large';
12
+ /** Button contents */
13
+ label: string;
14
+ /** Optional click handler */
15
+ onClick?: () => void;
16
+ }
17
+
18
+ /** Primary UI component for user interaction */
19
+ export const Button = ({
20
+ primary = false,
21
+ size = 'medium',
22
+ backgroundColor,
23
+ label,
24
+ ...props
25
+ }: ButtonProps) => {
26
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
27
+ return (
28
+ <button
29
+ type="button"
30
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
31
+ style={{ backgroundColor }}
32
+ {...props}
33
+ >
34
+ {label}
35
+ </button>
36
+ );
37
+ };
@@ -0,0 +1,34 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+
3
+ import { fn } from 'storybook/test';
4
+
5
+ import { Header } from './Header';
6
+
7
+ const meta = {
8
+ title: 'Example/Header',
9
+ component: Header,
10
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
11
+ tags: ['autodocs'],
12
+ parameters: {
13
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
14
+ layout: 'fullscreen',
15
+ },
16
+ args: {
17
+ onLogin: fn(),
18
+ onLogout: fn(),
19
+ onCreateAccount: fn(),
20
+ },
21
+ } satisfies Meta<typeof Header>;
22
+
23
+ export default meta;
24
+ type Story = StoryObj<typeof meta>;
25
+
26
+ export const LoggedIn: Story = {
27
+ args: {
28
+ user: {
29
+ name: 'Jane Doe',
30
+ },
31
+ },
32
+ };
33
+
34
+ export const LoggedOut: Story = {};
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+
3
+ import { Button } from './Button';
4
+ import './header.css';
5
+
6
+ type User = {
7
+ name: string;
8
+ };
9
+
10
+ export interface HeaderProps {
11
+ user?: User;
12
+ onLogin?: () => void;
13
+ onLogout?: () => void;
14
+ onCreateAccount?: () => void;
15
+ }
16
+
17
+ export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
18
+ <header>
19
+ <div className="storybook-header">
20
+ <div>
21
+ <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
22
+ <g fill="none" fillRule="evenodd">
23
+ <path
24
+ d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
25
+ fill="#FFF"
26
+ />
27
+ <path
28
+ d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
29
+ fill="#555AB9"
30
+ />
31
+ <path
32
+ d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
33
+ fill="#91BAF8"
34
+ />
35
+ </g>
36
+ </svg>
37
+ <h1>Acme</h1>
38
+ </div>
39
+ <div>
40
+ {user ? (
41
+ <>
42
+ <span className="welcome">
43
+ Welcome, <b>{user.name}</b>!
44
+ </span>
45
+ <Button size="small" onClick={onLogout} label="Log out" />
46
+ </>
47
+ ) : (
48
+ <>
49
+ <Button size="small" onClick={onLogin} label="Log in" />
50
+ <Button primary size="small" onClick={onCreateAccount} label="Sign up" />
51
+ </>
52
+ )}
53
+ </div>
54
+ </div>
55
+ </header>
56
+ );
@@ -0,0 +1,33 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+
3
+ import { expect, userEvent, within } from 'storybook/test';
4
+
5
+ import { Page } from './Page';
6
+
7
+ const meta = {
8
+ title: 'Example/Page',
9
+ component: Page,
10
+ parameters: {
11
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
12
+ layout: 'fullscreen',
13
+ },
14
+ } satisfies Meta<typeof Page>;
15
+
16
+ export default meta;
17
+ type Story = StoryObj<typeof meta>;
18
+
19
+ export const LoggedOut: Story = {};
20
+
21
+ // More on component testing: https://storybook.js.org/docs/writing-tests/interaction-testing
22
+ export const LoggedIn: Story = {
23
+ play: async ({ canvasElement }) => {
24
+ const canvas = within(canvasElement);
25
+ const loginButton = canvas.getByRole('button', { name: /Log in/i });
26
+ await expect(loginButton).toBeInTheDocument();
27
+ await userEvent.click(loginButton);
28
+ await expect(loginButton).not.toBeInTheDocument();
29
+
30
+ const logoutButton = canvas.getByRole('button', { name: /Log out/i });
31
+ await expect(logoutButton).toBeInTheDocument();
32
+ },
33
+ };
@@ -0,0 +1,73 @@
1
+ import React from 'react';
2
+
3
+ import { Header } from './Header';
4
+ import './page.css';
5
+
6
+ type User = {
7
+ name: string;
8
+ };
9
+
10
+ export const Page: React.FC = () => {
11
+ const [user, setUser] = React.useState<User>();
12
+
13
+ return (
14
+ <article>
15
+ <Header
16
+ user={user}
17
+ onLogin={() => setUser({ name: 'Jane Doe' })}
18
+ onLogout={() => setUser(undefined)}
19
+ onCreateAccount={() => setUser({ name: 'Jane Doe' })}
20
+ />
21
+
22
+ <section className="storybook-page">
23
+ <h2>Pages in Storybook</h2>
24
+ <p>
25
+ We recommend building UIs with a{' '}
26
+ <a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
27
+ <strong>component-driven</strong>
28
+ </a>{' '}
29
+ process starting with atomic components and ending with pages.
30
+ </p>
31
+ <p>
32
+ Render pages with mock data. This makes it easy to build and review page states without
33
+ needing to navigate to them in your app. Here are some handy patterns for managing page
34
+ data in Storybook:
35
+ </p>
36
+ <ul>
37
+ <li>
38
+ Use a higher-level connected component. Storybook helps you compose such data from the
39
+ "args" of child component stories
40
+ </li>
41
+ <li>
42
+ Assemble data in the page component from your services. You can mock these services out
43
+ using Storybook.
44
+ </li>
45
+ </ul>
46
+ <p>
47
+ Get a guided tutorial on component-driven development at{' '}
48
+ <a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
49
+ Storybook tutorials
50
+ </a>
51
+ . Read more in the{' '}
52
+ <a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
53
+ docs
54
+ </a>
55
+ .
56
+ </p>
57
+ <div className="tip-wrapper">
58
+ <span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
59
+ <svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
60
+ <g fill="none" fillRule="evenodd">
61
+ <path
62
+ d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
63
+ id="a"
64
+ fill="#999"
65
+ />
66
+ </g>
67
+ </svg>
68
+ Viewports addon in the toolbar
69
+ </div>
70
+ </section>
71
+ </article>
72
+ );
73
+ };
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- export { __definePreview as definePreview } from '@storybook/react';
@@ -1,3 +0,0 @@
1
- function defineMain(config){return config}
2
-
3
- export { defineMain };