Migrate countdown to storybook
This commit is contained in:
parent
1ca3ec47f8
commit
6aeaabf505
3 changed files with 45 additions and 24 deletions
44
ts/components/Countdown.stories.tsx
Normal file
44
ts/components/Countdown.stories.tsx
Normal file
|
@ -0,0 +1,44 @@
|
|||
import React from 'react';
|
||||
|
||||
import { action } from '@storybook/addon-actions';
|
||||
import { date, number } from '@storybook/addon-knobs';
|
||||
import { storiesOf } from '@storybook/react';
|
||||
|
||||
import { Countdown, Props } from './Countdown';
|
||||
|
||||
const defaultDuration = 10 * 1000;
|
||||
const createProps = (overrideProps: Partial<Props> = {}): Props => ({
|
||||
duration: number('duration', overrideProps.duration || defaultDuration),
|
||||
expiresAt: date(
|
||||
'expiresAt',
|
||||
overrideProps.expiresAt
|
||||
? new Date(overrideProps.expiresAt)
|
||||
: new Date(Date.now() + defaultDuration)
|
||||
),
|
||||
onComplete: action('onComplete'),
|
||||
});
|
||||
|
||||
const story = storiesOf('Components/Countdown', module);
|
||||
|
||||
story.add('Just Started', () => {
|
||||
const props = createProps();
|
||||
|
||||
return <Countdown {...props} />;
|
||||
});
|
||||
|
||||
story.add('In Progress', () => {
|
||||
const props = createProps({
|
||||
duration: 3 * defaultDuration,
|
||||
expiresAt: Date.now() + defaultDuration,
|
||||
});
|
||||
|
||||
return <Countdown {...props} />;
|
||||
});
|
||||
|
||||
story.add('Done', () => {
|
||||
const props = createProps({
|
||||
expiresAt: Date.now() - defaultDuration,
|
||||
});
|
||||
|
||||
return <Countdown {...props} />;
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue