Comments (7)
I revised my code
import * as React from "react";
import { storiesOf } from "@storybook/react";
import { withKnobs, boolean, number } from "@storybook/addon-knobs";
import {
withPreview,
previewTemplate,
DEFAULT_VANILLA_CODESANDBOX,
} from "storybook-addon-preview";
import Task from "./Task";
const storyName = "Test";
const title = "Test Title";
const stories = storiesOf(storyName, module);
const VirtualComponent = Task;
stories.addDecorator(withKnobs).addDecorator(withPreview);
stories.add(
title,
(e) => {
const opt1 = boolean("opt1", false);
const opt2 = number("num1", 0);
return (
<VirtualComponent
title={title}
storyName={storyName}
key={Math.random()}
/>
);
},
{
preview: [
{
tab: "React",
template: previewTemplate`
const inst = new Instance({
opt1: ${"opt1"},
num1: ${"num1"},
});
`,
language: "js",
codesandbox: DEFAULT_VANILLA_CODESANDBOX(["@egjs/infinitegrid"]),
copy: true,
},
],
}
);
Same issue with the import
import addons, { makeDecorator } from '@storybook/addons';
^^^^^^
SyntaxError: Cannot use import statement outside a module
2 | import { storiesOf } from "@storybook/react";
3 | import { withKnobs, boolean, number } from "@storybook/addon-knobs";
> 4 | import {
| ^
5 | withPreview,
6 | previewTemplate,
7 | DEFAULT_VANILLA_CODESANDBOX,
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
at Object.<anonymous> (src/components/Test.stories.js:4:1)
Test Suites: 1 failed, 1 passed, 2 total
from storybook-addon-preview.
Your tester probably don't convert the esm syntax of node_modules. We will add a file in commonjs format.
from storybook-addon-preview.
storybook-addon-preview 1.1.2 is released.
Check it again.
from storybook-addon-preview.
@daybrush I'm using "storybook-addon-preview": "^1.1.2"
and I get a "Test" component in storybook but when i click it my screen goes blank. This is the code in my story
import {
withPreview,
previewTemplate,
DEFAULT_VANILLA_CODESANDBOX,
} from "storybook-addon-preview";
import { storiesOf } from "@storybook/react";
import AppHeader from "./AppHeader.js";
import { withKnobs, text, boolean, number } from "@storybook/addon-knobs";
const storyName = "Test";
const title = "Test Title";
const stories = storiesOf(storyName, module);
const VirtualComponent = AppHeader;
stories.addDecorator(withKnobs).addDecorator(withPreview);
stories.add(
title,
(e) => {
const opt1 = boolean("opt1", false);
const opt2 = number("num1", 0);
return (
<VirtualComponent
title={title}
storyName={storyName}
key={Math.random()}
/>
);
},
{
preview: [
{
tab: "React",
template: previewTemplate`
const inst = new Instance({
opt1: ${"opt1"},
num1: ${"num1"},
});
`,
language: "js",
codesandbox: DEFAULT_VANILLA_CODESANDBOX(["@egjs/infinitegrid"]),
copy: true,
},
],
}
);
Url
http://localhost:9009/?path=/story/test--test-title
from storybook-addon-preview.
DEFAULT_VANILLA_CODESANDBOX needs the Vanilla tab. React should use DEFAULT_REACT_CODESANDBOX.
from storybook-addon-preview.
@daybrush my component now renders but when I include the template
object, thee screen stills goes blank. I am using create react app and common js files. Here is updated code, you will notice I commented out parts that don't work and produce white screen
import React from "react";
import {
withPreview,
previewTemplate,
DEFAULT_REACT_CODESANDBOX,
} from "storybook-addon-preview";
import { storiesOf } from "@storybook/react";
import AppHeader from "./AppHeader.js";
import { withKnobs, text, boolean, number } from "@storybook/addon-knobs";
const storyName = "Test";
const title = "Test Title";
const stories = storiesOf(storyName, module);
const VirtualComponent = AppHeader;
stories.addDecorator(withKnobs).addDecorator(withPreview);
stories.add(
title,
(e) => {
const opt1 = boolean("opt1", false);
const opt2 = number("num1", 0);
return (
<VirtualComponent
title={title}
storyName={storyName}
key={Math.random()}
/>
);
},
{
preview: [
{
tab: "React",
// template: previewTemplate`
// const inst = new Instance({
// opt1: ${"opt1"},
// num1: ${"num1"},
// });
// `,
language: "js",
codesandbox: DEFAULT_REACT_CODESANDBOX(["@egjs/infinitegrid"]),
copy: true,
},
],
}
);
If I uncomment template
I get a white screen
My code does not use knobs in this component so I modified code as below
template: `
const inst = new Instance({
opt1: 1,
num1: 1,
});
`,
Still get white screen
from storybook-addon-preview.
@webface
Oh sorry CSS was also required to use codesandbox.
https://github.com/naver/storybook-addon-preview#you-can-use-the-default-codesandbox-presets
I'm going to turn CSS into an option.
from storybook-addon-preview.
Related Issues (16)
- How to use the addon with CSF? HOT 3
- Support for Storybook 6's "Controls" HOT 4
- Support for Storybook dark theme
- control variables not shown in preview HOT 1
- Add `create-react-app` CSB preset for React HOT 4
- `knobs` is always an empy object HOT 2
- Provide a way to enable custom Codesandbox PRESETS HOT 5
- Prettier HOT 4
- Support globals HOT 4
- Silent faillure in built storybook HOT 1
- highlight comment appear in html.
- Dark theme
- please update react to 18
- Request a new major version for storybook 7
- When there is no preview, no preview is displayed.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from storybook-addon-preview.