Skip to content

Commit

Permalink
feat(stories): add new stories for btn and thumb
Browse files Browse the repository at this point in the history
  • Loading branch information
webistomin committed Mar 17, 2021
1 parent c943c1d commit 7221f17
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/components/VueTube/VueTube.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
height: inherit;
object-fit: cover;
object-position: center;
vertical-align: top;
}

.vuetube__button {
Expand Down
24 changes: 24 additions & 0 deletions src/components/VueTube/docs/VueTube.stories.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,27 @@
width: 100%;
height: 100%;
}

.story-vuetube-thumbnail {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.story-vuetube-aspect-ratio {
position: relative;
}

.story-vuetube-aspect-ratio::before {
display: block;
padding-bottom: 56.25%;
content: '';
}

.story-vuetube-aspect-ratio .story-vuetube-iframe {
position: absolute;
top: 0;
left: 0;
}
266 changes: 248 additions & 18 deletions src/components/VueTube/docs/VueTube.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import VueTube from '../VueTube';
import SVueTubeMDX from './VueTube.mdx';
import './VueTube.stories.css';
import '../VueTube.css';
import placeholder from './assets/placeholder.png';

export default {
title: 'Components/VueTube',
Expand All @@ -15,6 +16,11 @@ export default {
},
};

const thumbnail = {
src: placeholder,
alt: 'Video coming soon',
};

const Template: Story = (_args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { VueTube },
Expand All @@ -30,28 +36,184 @@ const Template: Story = (_args, { argTypes }) => ({
},
template: `
<div class="story-vuetube-container">
<vue-tube
v-bind="$props"
@player:ready="onReady"
@player:statechange="onStateChange"
@player:playbackqualitychange="onPlaybackRateChange"
@player:error="onError"
@player:apichange="onApiChange"
@player:load="onLoad"
@player:play="onPlay"
>
</vue-tube>
<vue-tube
v-bind="$props"
@player:ready="onReady"
@player:statechange="onStateChange"
@player:playbackqualitychange="onPlaybackRateChange"
@player:error="onError"
@player:apichange="onApiChange"
@player:load="onLoad"
@player:play="onPlay"
>
</vue-tube>
</div>
`,
`,
});

const NativeIframeTemplate: Story = () => ({
const TemplateWithAPI: Story = (_args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { VueTube },
methods: {
onReady: action('emit player:ready'),
onStateChange: action('emit player:statechange'),
onPlaybackQualityChange: action('emit player:playbackqualitychange'),
onPlaybackRateChange: action('emit player:playbackratechange'),
onError: action('emit player:error'),
onApiChange: action('emit player:apichange'),
onLoad: action('emit player:load'),
onPlay: action('emit player:play'),
},
template: `
<div class="story-vuetube-container">
<vue-tube
v-bind="$props"
@player:ready="onReady"
@player:statechange="onStateChange"
@player:playbackqualitychange="onPlaybackRateChange"
@player:error="onError"
@player:apichange="onApiChange"
@player:load="onLoad"
@player:play="onPlay"
>
</vue-tube>
</div>
`,
});

const TemplateWithCustomButton: Story = (_args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { VueTube },
methods: {
onReady: action('emit player:ready'),
onStateChange: action('emit player:statechange'),
onPlaybackQualityChange: action('emit player:playbackqualitychange'),
onPlaybackRateChange: action('emit player:playbackratechange'),
onError: action('emit player:error'),
onApiChange: action('emit player:apichange'),
onLoad: action('emit player:load'),
onPlay: action('emit player:play'),
},
template: `
<div class="story-vuetube-container">
<vue-tube
v-bind="$props"
@player:ready="onReady"
@player:statechange="onStateChange"
@player:playbackqualitychange="onPlaybackRateChange"
@player:error="onError"
@player:apichange="onApiChange"
@player:load="onLoad"
@player:play="onPlay"
>
<template #icon>
<svg
xmlns="http://www.w3.org/2000/svg"
width="48"
height="48"
viewBox="0 0 24 24">
<path
fill="#fff"
d="M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10-10-4.486-10-10 4.486-10 10-10zm0-2c-6.627 0-12 5.373-12 12s5.373 12 12 12 12-5.373 12-12-5.373-12-12-12zm-3 17v-10l9 5.146-9 4.854z"
/>
</svg>
</template>
</vue-tube>
</div>
`,
});

const TemplateWithCustomThumbnail: Story = (_args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { VueTube },
computed: {
src() {
return thumbnail.src;
},
alt() {
return thumbnail.alt;
},
},
methods: {
onReady: action('emit player:ready'),
onStateChange: action('emit player:statechange'),
onPlaybackQualityChange: action('emit player:playbackqualitychange'),
onPlaybackRateChange: action('emit player:playbackratechange'),
onError: action('emit player:error'),
onApiChange: action('emit player:apichange'),
onLoad: action('emit player:load'),
onPlay: action('emit player:play'),
},
template: `
<div class="story-vuetube-container">
<vue-tube
v-bind="$props"
@player:ready="onReady"
@player:statechange="onStateChange"
@player:playbackqualitychange="onPlaybackRateChange"
@player:error="onError"
@player:apichange="onApiChange"
@player:load="onLoad"
@player:play="onPlay"
>
<template #thumbnail>
<img class="story-vuetube-thumbnail" :src="src" :alt="alt">
</template>
</vue-tube>
</div>
`,
});

const TemplateWithMultipleVideos: Story = (_args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { VueTube },
methods: {
onReady: action('emit player:ready'),
onStateChange: action('emit player:statechange'),
onPlaybackQualityChange: action('emit player:playbackqualitychange'),
onPlaybackRateChange: action('emit player:playbackratechange'),
onError: action('emit player:error'),
onApiChange: action('emit player:apichange'),
onLoad: action('emit player:load'),
onPlay: action('emit player:play'),
},
template: `
<div class="story-vuetube-container">
<vue-tube
v-bind="$props"
@player:ready="onReady"
@player:statechange="onStateChange"
@player:playbackqualitychange="onPlaybackRateChange"
@player:error="onError"
@player:apichange="onApiChange"
@player:load="onLoad"
@player:play="onPlay"
>
</vue-tube>
<vue-tube
v-bind="$props"
video-id="QH2-TGUlwu4"
image-alt="Nyan Cat"
iframe-title="Nyan Cat [original]"
@player:ready="onReady"
@player:statechange="onStateChange"
@player:playbackqualitychange="onPlaybackRateChange"
@player:error="onError"
@player:apichange="onApiChange"
@player:load="onLoad"
@player:play="onPlay"
>
</vue-tube>
</div>
`,
});

const NativeIframeTemplate: Story = () => ({
template: `
<div class="story-vuetube-container story-vuetube-aspect-ratio">
<iframe
class="story-vuetube-iframe"
src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
Expand All @@ -61,20 +223,88 @@ const NativeIframeTemplate: Story = () => ({

export const Default = Template.bind({});
Default.args = {
videoId: 'dQw4w9WgXcQ',
isPlaylist: false,
aspectRatio: 16 / 9,
enableCookies: false,
playerVars: {},
disableWarming: false,
disableWebp: false,
imageAlt: 'Rick Astley',
imageLoading: 'lazy',
resolution: 'sddefault',
buttonLabel: 'Play video',
iframeTitle: 'Rick Astley - Never Gonna Give You Up (Video)',
iframeAllow: 'accelerometer;autoplay;encrypted-media;gyroscope;picture-in-picture',
};

export const withAPI = TemplateWithAPI.bind({});
withAPI.args = {
videoId: 'dQw4w9WgXcQ',
isPlaylist: false,
aspectRatio: 16 / 9,
enableCookies: false,
playerVars: { enablejsapi: 1 },
disableWarming: false,
disableWebp: false,
imageAlt: 'Rick Astley',
imageLoading: 'lazy',
resolution: 'sddefault',
buttonLabel: 'Play video',
iframeTitle: 'Rick Astley - Never Gonna Give You Up (Video)',
iframeAllow: 'accelerometer;autoplay;encrypted-media;gyroscope;picture-in-picture',
};

export const withCustomButton = TemplateWithCustomButton.bind({});
withCustomButton.args = {
videoId: 'dQw4w9WgXcQ',
isPlaylist: false,
aspectRatio: 16 / 9,
enableCookies: false,
playerVars: {},
disableWarming: false,
disableWebp: false,
imageAlt: 'Rick Astley',
imageLoading: 'lazy',
resolution: 'sddefault',
buttonLabel: 'Play video',
iframeTitle: 'Rick Astley - Never Gonna Give You Up (Video)',
iframeAllow: 'accelerometer;autoplay;encrypted-media;gyroscope;picture-in-picture',
};

export const withCustomThumbnail = TemplateWithCustomThumbnail.bind({});
withCustomThumbnail.args = {
videoId: 'dQw4w9WgXcQ',
isPlaylist: false,
aspectRatio: 16 / 9,
enableCookies: false,
playerVars: {},
disableWarming: false,
disableWebp: false,
imageAlt: 'Rick Astley',
imageLoading: 'lazy',
resolution: 'sddefault',
buttonLabel: 'Play video',
iframeTitle: 'Rick Astley - Never Gonna Give You Up (Video)',
iframeAllow: 'accelerometer;autoplay;encrypted-media;gyroscope;picture-in-picture',
};

export const withMultipleVideos = TemplateWithMultipleVideos.bind({});
withMultipleVideos.args = {
videoId: 'dQw4w9WgXcQ',
isPlaylist: false,
aspectRatio: 16 / 9,
enableCookies: false,
playerVars: { enablejsapi: 1 },
disableWarming: false,
disableWebp: false,
imageAlt: '',
imageAlt: 'Rick Astley',
imageLoading: 'lazy',
resolution: 'sddefault',
buttonLabel: 'Play video',
iframeTitle: undefined,
iframeTitle: 'Rick Astley - Never Gonna Give You Up (Video)',
iframeAllow: 'accelerometer;autoplay;encrypted-media;gyroscope;picture-in-picture',
};

export const NativeIframe = NativeIframeTemplate.bind({});
NativeIframe.args = {};
export const withNativeIframe = NativeIframeTemplate.bind({});
withNativeIframe.args = {};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions types/shims-png.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.png' {
const value: unknown;
export default value;
}

0 comments on commit 7221f17

Please sign in to comment.