Code Monkey home page Code Monkey logo

Comments (7)

webface avatar webface commented on August 10, 2024

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.

daybrush avatar daybrush commented on August 10, 2024

@webface

Your tester probably don't convert the esm syntax of node_modules. We will add a file in commonjs format.

from storybook-addon-preview.

daybrush avatar daybrush commented on August 10, 2024

@webface

storybook-addon-preview 1.1.2 is released.

Check it again.

from storybook-addon-preview.

webface avatar webface commented on August 10, 2024

@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.

daybrush avatar daybrush commented on August 10, 2024

@webface

DEFAULT_VANILLA_CODESANDBOX needs the Vanilla tab. React should use DEFAULT_REACT_CODESANDBOX.

from storybook-addon-preview.

webface avatar webface commented on August 10, 2024

@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,
			},
		],
	}
);

Screen Shot 2020-06-12 at 8 17 26 AM

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.

daybrush avatar daybrush commented on August 10, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.