Skip to content

Commit

Permalink
♻️ Use Storybook args (first round) (#35915)
Browse files Browse the repository at this point in the history
Partial for #35923

This is the first step to replace Storybook Knobs (deprecated)[1] with Controls[2].

[1] https://www.npmjs.com/package/@storybook/addon-knobs
[2] https://storybook.js.org/docs/react/essentials/controls

We have over 60 Storybook files. I'm submitting the PRs in multiple rounds to prevent overwhelming the reviewers.

In summary:

1. Installs `@storybook/addon-controls`
2. Updates template for generated Stories.
3. Updates 15 Stories across extensions.
  • Loading branch information
alanorozco committed Sep 2, 2021
1 parent a9a4663 commit 64cb73b
Show file tree
Hide file tree
Showing 21 changed files with 730 additions and 615 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import * as Preact from '#preact';
import {__component_name_pascalcase__} from '../component'
import {withKnobs} from '@storybook/addon-knobs';

export default {
title: '__component_name_pascalcase__',
component: __component_name_pascalcase__,
decorators: [withKnobs],
args: {
'exampleProperty': 'example string property argument'
}
};

export const _default = () => {
// __do_not_submit__: This is example code only.
// __do_not_submit__: This is example code only.
export const _default = (args) => {
return (
<__component_name_pascalcase__
style={{width: 300, height: 200}}
example-property="example string property value"
{...args}
>
This text is inside.
</__component_name_pascalcase__>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
import * as Preact from '#preact';
import {withAmp} from '@ampproject/storybook-addon';
import {withKnobs} from '@storybook/addon-knobs';

export default {
title: 'amp-__component_name_hyphenated__-__component_version_snakecase__',
decorators: [withKnobs, withAmp],

decorators: [withAmp],
parameters: {
extensions: [
{name: 'amp-__component_name_hyphenated__', version: '__component_version__'},
],
__storybook_experiments_do_not_add_trailing_comma__
},
args: {
'data-example-property': 'example string property argument'
}
};

// __do_not_submit__: This is example code only.
export const ExampleUseCase = () => {
export const _default = (args) => {
return (
<amp-__component_name_hyphenated__
width="300"
height="200"
example-property="example string property value"
{...args}
>
This text is inside.
</amp-__component_name_hyphenated__>
);
};

ExampleUseCase.story = {
name: 'Example use case story'
};
3 changes: 3 additions & 0 deletions build-system/tasks/storybook/amp-env/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module.exports = {
// Enable this once we find a way to inspect the iframe document's tree.
// '@storybook/addon-a11y',
'@storybook/addon-viewport/register',
'@storybook/addon-controls/register',
// TODO(#35923): Remove addon-knobs once all stories are migrated to
// addon-controls (args/argTypes).
'@storybook/addon-knobs/register',
'@ampproject/storybook-addon',
],
Expand Down
241 changes: 241 additions & 0 deletions build-system/tasks/storybook/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build-system/tasks/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@babel/preset-react": "7.14.5",
"@babel/runtime-corejs3": "7.15.3",
"@storybook/addon-a11y": "6.3.7",
"@storybook/addon-controls": "6.3.7",
"@storybook/addon-knobs": "6.2.9",
"@storybook/addon-viewport": "6.3.7",
"@storybook/preact": "6.3.7",
Expand Down
3 changes: 3 additions & 0 deletions build-system/tasks/storybook/preact-env/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module.exports = {
addons: [
'@storybook/addon-a11y',
'@storybook/addon-viewport/register',
'@storybook/addon-controls/register',
// TODO(#35923): Remove addon-knobs once all stories are migrated to
// addon-controls (args/argTypes).
'@storybook/addon-knobs/register',
],
managerWebpack: (config) => {
Expand Down
28 changes: 9 additions & 19 deletions extensions/amp-accordion/1.0/storybook/Basic.amp.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import {withAmp} from '@ampproject/storybook-addon';
import {boolean, withKnobs} from '@storybook/addon-knobs';

import * as Preact from '#preact';

export default {
title: 'amp-accordion-1_0',
decorators: [withKnobs, withAmp],

decorators: [withAmp],
parameters: {
extensions: [{name: 'amp-accordion', version: '1.0'}],
experiments: ['bento'],
},
args: {
'expand-single-section': false,
animate: false,
},
};

export const _default = () => {
const expandSingleSection = boolean('expandSingleSection', false);
const animate = boolean('animate', false);
export const _default = (args) => {
return (
<main>
<amp-accordion
id="accordion"
expand-single-section={expandSingleSection}
animate={animate}
>
<amp-accordion id="accordion" {...args}>
<section id="section1">
<h2>Section 1</h2>
<div>Puppies are cute.</div>
Expand Down Expand Up @@ -55,16 +51,10 @@ export const _default = () => {
);
};

export const events = () => {
const expandSingleSection = boolean('expandSingleSection', false);
const animate = boolean('animate', false);
export const events = (args) => {
return (
<main>
<amp-accordion
id="accordion"
expand-single-section={expandSingleSection}
animate={animate}
>
<amp-accordion id="accordion" {...args}>
<section id="section1">
<h2>Section 1</h2>
<div>Puppies are cute.</div>
Expand Down
Loading

0 comments on commit 64cb73b

Please sign in to comment.