vibe-design-system 2.5.13 → 2.5.14
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/bin/init.js +11 -0
- package/package.json +1 -1
- package/vds-core-template/story-generator.mjs +24 -6
package/bin/init.js
CHANGED
|
@@ -47,8 +47,18 @@ export default config;
|
|
|
47
47
|
`;
|
|
48
48
|
|
|
49
49
|
const STORYBOOK_PREVIEW_TS = `import type { Preview } from "@storybook/react";
|
|
50
|
+
import React from "react";
|
|
51
|
+
import { MemoryRouter } from "react-router-dom";
|
|
50
52
|
import "../src/index.css";
|
|
51
53
|
|
|
54
|
+
const withRouter = (Story: any) => {
|
|
55
|
+
try {
|
|
56
|
+
return React.createElement(MemoryRouter, null, React.createElement(Story));
|
|
57
|
+
} catch {
|
|
58
|
+
return React.createElement(Story);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
52
62
|
const preview: Preview = {
|
|
53
63
|
parameters: {
|
|
54
64
|
layout: "fullscreen",
|
|
@@ -66,6 +76,7 @@ const preview: Preview = {
|
|
|
66
76
|
},
|
|
67
77
|
},
|
|
68
78
|
},
|
|
79
|
+
decorators: [withRouter],
|
|
69
80
|
};
|
|
70
81
|
|
|
71
82
|
export default preview;
|
package/package.json
CHANGED
|
@@ -374,6 +374,15 @@ function hasNamedExports(source, names) {
|
|
|
374
374
|
return true;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
+
/** Whether component has children prop typed as ReactNode / React.ReactNode (use createElement fallback in render). */
|
|
378
|
+
function hasChildrenPropReactNode(props) {
|
|
379
|
+
if (!Array.isArray(props) || props.length === 0) return false;
|
|
380
|
+
const childrenProp = props.find((p) => p.name === "children");
|
|
381
|
+
if (!childrenProp) return false;
|
|
382
|
+
const type = String(childrenProp.type || "").toLowerCase();
|
|
383
|
+
return type.includes("reactnode") || type.includes("react.reactnode");
|
|
384
|
+
}
|
|
385
|
+
|
|
377
386
|
/** Void HTML elements: img, input, hr, br — must not receive children. If component wraps one and has children in props, omit children in story args. */
|
|
378
387
|
function componentWrapsVoidElement(source) {
|
|
379
388
|
if (!source || typeof source !== "string") return false;
|
|
@@ -710,6 +719,7 @@ function buildStoryFileContent(comp) {
|
|
|
710
719
|
// Props: manifest or parse from source for default args (LucideIcon, array types)
|
|
711
720
|
const effectiveProps = Array.isArray(comp.props) && comp.props.length > 0 ? comp.props : parsePropsFromSource(source);
|
|
712
721
|
const { argLines: defaultArgLines, lucideImports } = buildDefaultArgsForRequiredProps(effectiveProps);
|
|
722
|
+
const useReactNodeChildrenRender = !omitChildren && hasChildrenPropReactNode(effectiveProps);
|
|
713
723
|
|
|
714
724
|
// Skip story only if not a page and no export found
|
|
715
725
|
if (exportStyle === "unknown" && !isPage && (!source.includes("export") || !new RegExp(`\\b${componentName}\\b`).test(source))) {
|
|
@@ -722,6 +732,9 @@ function buildStoryFileContent(comp) {
|
|
|
722
732
|
|
|
723
733
|
const lines = [];
|
|
724
734
|
lines.push(`import type { Meta, StoryObj } from "@storybook/react";`);
|
|
735
|
+
if (useReactNodeChildrenRender) {
|
|
736
|
+
lines.push(`import React from "react";`);
|
|
737
|
+
}
|
|
725
738
|
if (lucideImports.length > 0) {
|
|
726
739
|
lines.push(`import { ${lucideImports.join(", ")} } from "lucide-react";`);
|
|
727
740
|
}
|
|
@@ -770,21 +783,26 @@ function buildStoryFileContent(comp) {
|
|
|
770
783
|
}
|
|
771
784
|
|
|
772
785
|
// Generic variant-based stories — render real component with args (omit children for img/void)
|
|
786
|
+
const renderLine = useReactNodeChildrenRender
|
|
787
|
+
? ` render: (args) => React.createElement(ComponentRef, { ...args, children: args.children || React.createElement('span', null, 'Example') }),`
|
|
788
|
+
: ` render: (args) => <ComponentRef {...args} />,`;
|
|
789
|
+
const childrenArgLine = (label) => (!omitChildren && !useReactNodeChildrenRender ? ` children: ${JSON.stringify(label)},` : null);
|
|
790
|
+
|
|
773
791
|
if (!variants.length) {
|
|
774
792
|
lines.push(`export const Default: Story = {`);
|
|
775
|
-
lines.push(
|
|
793
|
+
lines.push(renderLine);
|
|
776
794
|
lines.push(` args: {`);
|
|
777
|
-
if (
|
|
795
|
+
if (childrenArgLine(componentName)) lines.push(childrenArgLine(componentName));
|
|
778
796
|
for (const line of defaultArgLines) lines.push(line);
|
|
779
797
|
lines.push(` },`);
|
|
780
798
|
lines.push(`};`);
|
|
781
799
|
} else {
|
|
782
800
|
const defaultVariant = variants[0];
|
|
783
801
|
lines.push(`export const ${capitalize(defaultVariant)}: Story = {`);
|
|
784
|
-
lines.push(
|
|
802
|
+
lines.push(renderLine);
|
|
785
803
|
lines.push(` args: {`);
|
|
786
804
|
lines.push(` variant: "${defaultVariant}",`);
|
|
787
|
-
if (
|
|
805
|
+
if (childrenArgLine(componentName)) lines.push(childrenArgLine(componentName));
|
|
788
806
|
for (const line of defaultArgLines) lines.push(line);
|
|
789
807
|
lines.push(` },`);
|
|
790
808
|
lines.push(`};`);
|
|
@@ -792,10 +810,10 @@ function buildStoryFileContent(comp) {
|
|
|
792
810
|
for (const v of variants.slice(1)) {
|
|
793
811
|
const storyName = capitalize(v);
|
|
794
812
|
lines.push(`export const ${storyName}: Story = {`);
|
|
795
|
-
lines.push(
|
|
813
|
+
lines.push(renderLine);
|
|
796
814
|
lines.push(` args: {`);
|
|
797
815
|
lines.push(` variant: "${v}",`);
|
|
798
|
-
if (
|
|
816
|
+
if (childrenArgLine(storyName)) lines.push(childrenArgLine(storyName));
|
|
799
817
|
for (const line of defaultArgLines) lines.push(line);
|
|
800
818
|
lines.push(` },`);
|
|
801
819
|
lines.push(`};`);
|