Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Migrate stories 54..61 to args #37860

Merged
merged 5 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions build-system/test-configs/forbidden-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,6 @@ const forbiddenTermsGlobal = {
'The @storybook/addon-knobs package has been deprecated. Use Controls instead (`args` and `argTypes`). https://storybook.js.org/docs/react/essentials/controls',
allowlist: [
// TODO(#35923): Update existing files to use Controls instead.
'extensions/amp-video/1.0/storybook/Basic.amp.js',
'extensions/amp-video/1.0/storybook/Basic.js',
'extensions/amp-video-iframe/1.0/storybook/Basic.amp.js',
'extensions/amp-vimeo/1.0/storybook/Basic.amp.js',
'extensions/amp-vimeo/1.0/storybook/Basic.js',
'extensions/amp-youtube/0.1/storybook/Basic.amp.js',
'extensions/amp-youtube/1.0/storybook/Basic.amp.js',
'extensions/amp-youtube/1.0/storybook/Basic.js',
'src/builtins/storybook/amp-layout.amp.js',
'src/preact/storybook/Context.js',
'src/preact/storybook/Wrappers.js',
Expand Down
118 changes: 60 additions & 58 deletions extensions/amp-video-iframe/1.0/storybook/Basic.amp.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
import {withAmp} from '@ampproject/storybook-addon';
import {boolean, number, text, withKnobs} from '@storybook/addon-knobs';

import * as Preact from '#preact';

export default {
title: 'amp-video-iframe-1_0',
decorators: [withKnobs, withAmp],
decorators: [withAmp],
parameters: {
extensions: [{name: 'amp-video-iframe', version: '1.0'}],
experiments: ['bento'],
},
args: {
width: '640px',
height: '360px',

ariaLabel: 'Video Player',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use aria-label so you don't have to extract it and rename it in the fixtures

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a hyphen in an arg name gives me a linting error, i dont think i can get around extracting and renaming in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can turn off the rule with an eslint-disable-next-line comment otherwise feel free to merge

autoplay: true,
controls: true,
mediasession: true,
noaudio: false,
loop: false,
poster: 'https://amp.dev/static/inline-examples/images/kitten-playing.png',
artist: '',
album: '',
artwork: '',
title: '',
src: 'https://amp.dev/static/samples/files/amp-video-iframe-videojs.html',
},
};

const AmpVideoIframeWithKnobs = ({i, withPlaceholder, ...rest}) => {
const AmpVideoIframeWithControls = ({
ariaLabel,
i,
withPlaceholder,
...args
}) => {
const group = i ? `Player ${i + 1}` : undefined;

const width = text('width', '640px', group);
const height = text('height', '360px', group);

const ariaLabel = text('aria-label', 'Video Player');
const autoplay = boolean('autoplay', true);
const controls = boolean('controls', true);
const mediasession = boolean('mediasession', true);
const noaudio = boolean('noaudio', false);
const loop = boolean('loop', false);
const poster = text(
'poster',
'https://amp.dev/static/samples/img/amp-video-iframe-sample-placeholder.jpg'
);

const artist = text('artist', '');
const album = text('album', '');
const artwork = text('artwork', '');
const title = text('title', '');

const src = text(
'src',
'https://amp.dev/static/samples/files/amp-video-iframe-videojs.html'
);

const placeholderAndFallback = withPlaceholder ? (
<>
<div placeholder style="background:red">
Expand All @@ -52,22 +48,10 @@ const AmpVideoIframeWithKnobs = ({i, withPlaceholder, ...rest}) => {

return (
<amp-video-iframe
{...rest}
id={group}
aria-label={ariaLabel}
autoplay={autoplay}
controls={controls}
mediasession={mediasession}
noaudio={noaudio}
loop={loop}
poster={poster}
artist={artist}
album={album}
artwork={artwork}
title={title}
layout="responsive"
width={width}
height={height}
src={src}
{...args}
>
{placeholderAndFallback}
</amp-video-iframe>
Expand All @@ -86,15 +70,16 @@ const Spacer = ({height}) => {
);
};

export const Default = () => {
const amount = number('Amount', 1, {}, 'Page');
const spacerHeight = text('Space', '80vh', 'Page');
const spaceAbove = boolean('Space above', false, 'Page');
const spaceBelow = boolean('Space below', false, 'Page');

export const Default = ({
amount,
spaceAbove,
spaceBelow,
spacerHeight,
...args
}) => {
const players = [];
for (let i = 0; i < amount; i++) {
players.push(<AmpVideoIframeWithKnobs key={i} i={i} />);
players.push(<AmpVideoIframeWithControls key={i} i={i} {...args} />);
if (i < amount - 1) {
players.push(<Spacer height={spacerHeight} />);
}
Expand All @@ -109,16 +94,23 @@ export const Default = () => {
);
};

Default.args = {
amount: 1,
spacerHeight: '80vh',
spaceAbove: false,
spaceBelow: false,
};

const ActionButton = ({children, ...props}) => (
<button style={{flex: 1, margin: '0 4px'}} {...props}>
{children}
</button>
);

export const Actions = () => {
export const Actions = ({...args}) => {
return (
<div style="max-width: 800px">
<AmpVideoIframeWithKnobs id="player" />
<AmpVideoIframeWithControls id="player" {...args} />
<div
style={{
margin: '12px 0',
Expand All @@ -135,15 +127,18 @@ export const Actions = () => {
);
};

export const WithPlaceholderAndFallback = () => {
const amount = number('Amount', 1, {}, 'Page');
const spacerHeight = text('Space', '80vh', 'Page');
const spaceAbove = boolean('Space above', false, 'Page');
const spaceBelow = boolean('Space below', false, 'Page');

export const WithPlaceholderAndFallback = ({
amount,
spaceAbove,
spaceBelow,
spacerHeight,
...args
}) => {
const players = [];
for (let i = 0; i < amount; i++) {
players.push(<AmpVideoIframeWithKnobs key={i} i={i} placeholder={true} />);
players.push(
<AmpVideoIframeWithControls key={i} i={i} placeholder={true} {...args} />
);
if (i < amount - 1) {
players.push(<Spacer height={spacerHeight} />);
}
Expand All @@ -157,3 +152,10 @@ export const WithPlaceholderAndFallback = () => {
</>
);
};

WithPlaceholderAndFallback.args = {
amount: 1,
spacerHeight: '80vh',
spaceAbove: false,
spaceBelow: false,
};
Loading