From 271c230cf1e202657f84953836f24a1f8a236131 Mon Sep 17 00:00:00 2001 From: tooppaaa Date: Sat, 9 May 2020 11:25:54 +0200 Subject: [PATCH 1/2] cli: web-components stories homogenization --- .../src/generators/WEB-COMPONENTS/index.js | 10 ++-- .../template/.storybook/main.js | 1 + .../template/stories/0-Welcome.stories.js | 49 +++++++++++++++++++ .../template/stories/1-Button.stories.js | 42 ++++++++++++++++ .../template/stories/index.stories.js | 24 --------- 5 files changed, 97 insertions(+), 29 deletions(-) create mode 100644 lib/cli/src/generators/WEB-COMPONENTS/template/stories/0-Welcome.stories.js create mode 100644 lib/cli/src/generators/WEB-COMPONENTS/template/stories/1-Button.stories.js delete mode 100644 lib/cli/src/generators/WEB-COMPONENTS/template/stories/index.stories.js diff --git a/lib/cli/src/generators/WEB-COMPONENTS/index.js b/lib/cli/src/generators/WEB-COMPONENTS/index.js index ad448dc92d52..6a7d4697e744 100755 --- a/lib/cli/src/generators/WEB-COMPONENTS/index.js +++ b/lib/cli/src/generators/WEB-COMPONENTS/index.js @@ -1,7 +1,6 @@ import fse from 'fs-extra'; import path from 'path'; import { - getVersion, getVersionedPackages, retrievePackageJson, writePackageJson, @@ -15,17 +14,18 @@ export default async (npmOptions, { storyFormat }) => { '@storybook/web-components', '@storybook/addon-actions', '@storybook/addon-links', + '@storybook/addons', 'lit-html', ]; - if (storyFormat === STORY_FORMAT.MDX) { - // TODO: handle adding of docs mode - } - const versionedPackages = await getVersionedPackages(npmOptions, ...packages); fse.copySync(path.resolve(__dirname, 'template/'), '.', { overwrite: true }); + if (storyFormat === STORY_FORMAT.MDX) { + // TODO: handle adding of docs mode + } + const packageJson = await retrievePackageJson(); packageJson.dependencies = packageJson.dependencies || {}; diff --git a/lib/cli/src/generators/WEB-COMPONENTS/template/.storybook/main.js b/lib/cli/src/generators/WEB-COMPONENTS/template/.storybook/main.js index 77857c48de3f..3036098563cc 100644 --- a/lib/cli/src/generators/WEB-COMPONENTS/template/.storybook/main.js +++ b/lib/cli/src/generators/WEB-COMPONENTS/template/.storybook/main.js @@ -1,3 +1,4 @@ module.exports = { stories: ['../stories/**/*.stories.js'], + addons: ['@storybook/addon-actions', '@storybook/addon-links'], }; diff --git a/lib/cli/src/generators/WEB-COMPONENTS/template/stories/0-Welcome.stories.js b/lib/cli/src/generators/WEB-COMPONENTS/template/stories/0-Welcome.stories.js new file mode 100644 index 000000000000..de56afdc9f1c --- /dev/null +++ b/lib/cli/src/generators/WEB-COMPONENTS/template/stories/0-Welcome.stories.js @@ -0,0 +1,49 @@ +import { html } from 'lit-html'; + +export default { + title: 'Welcome', +}; + +export const ToStorybook = () => html`
+

Welcome to storybook

+

This is a UI component dev environment for your app.

+

+ We've added some basic stories inside the + src/stories directory.
+ A story is a single state of one or more UI components. You can have as many stories as you + want.
+ (Basically a story is like a visual test case.) +

+

+ See these sample + stories for a component called + Button . +

+

+ Just like that, you can add your own components as stories.
+ You can also edit those components and see changes right away.
+ (Try editing the Button stories located at + src/stories/index.js.) +

+

+ Usually we create stories with smaller UI components in the app.
+ Have a look at the + + Writing Stories + + section in our documentation. +

+

+ NOTE:
+ Have a look at the .storybook/webpack.config.js to add webpack + loaders and plugins you are using in this project. +

+
`; + +ToStorybook.story = { + name: 'to Storybook', +}; diff --git a/lib/cli/src/generators/WEB-COMPONENTS/template/stories/1-Button.stories.js b/lib/cli/src/generators/WEB-COMPONENTS/template/stories/1-Button.stories.js new file mode 100644 index 000000000000..b87d698a5e13 --- /dev/null +++ b/lib/cli/src/generators/WEB-COMPONENTS/template/stories/1-Button.stories.js @@ -0,0 +1,42 @@ +import { html } from 'lit-html'; +import { action } from '@storybook/addon-actions'; +import { linkTo } from '@storybook/addon-links'; + +export default { + title: 'Button', +}; + +export const Text = () => html` + +`; + +export const Emoji = () => html` + +`; + +Emoji.story = { + parameters: { notes: 'My notes on a button with emojis' }, +}; + +export const WithSomeEmojiAndAction = () => html` + +`; + +WithSomeEmojiAndAction.story = { + name: 'with some emoji and action', + parameters: { notes: 'My notes on a button with emojis' }, +}; + +export const ButtonWithLinkToAnotherStory = () => html``; + +ButtonWithLinkToAnotherStory.story = { + name: 'button with link to another story', +}; diff --git a/lib/cli/src/generators/WEB-COMPONENTS/template/stories/index.stories.js b/lib/cli/src/generators/WEB-COMPONENTS/template/stories/index.stories.js deleted file mode 100644 index 0697fe20c7b4..000000000000 --- a/lib/cli/src/generators/WEB-COMPONENTS/template/stories/index.stories.js +++ /dev/null @@ -1,24 +0,0 @@ -import { html } from 'lit-html'; - -// import '../my-component.js'; - -export default { - title: 'Demo', -}; - -export const Heading = () => html`

Hello World

`; - -export const SettingProperties = () => html` - Hello World -`; - -export const Events = () => html` - -`; - -export const WithFunction = () => { - const header = 'My Header'; - return html`

${header}

`; -}; From 1c4e3d5e7310fc6919ec765eee98be7eeedce1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Wed, 13 May 2020 22:22:23 +0200 Subject: [PATCH 2/2] feat(cli): remove `@storybook/addons` from deps installed when running `sb init` in a web-component project `@storybook/addons` is already a dependency of all `@storybook/addon-XXX` packages so there is no need to add it to the root project directly. --- lib/cli/src/generators/WEB-COMPONENTS/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cli/src/generators/WEB-COMPONENTS/index.js b/lib/cli/src/generators/WEB-COMPONENTS/index.js index 6a7d4697e744..2b6159651136 100755 --- a/lib/cli/src/generators/WEB-COMPONENTS/index.js +++ b/lib/cli/src/generators/WEB-COMPONENTS/index.js @@ -14,7 +14,6 @@ export default async (npmOptions, { storyFormat }) => { '@storybook/web-components', '@storybook/addon-actions', '@storybook/addon-links', - '@storybook/addons', 'lit-html', ];