Migrate countdown to storybook
This commit is contained in:
parent
1ca3ec47f8
commit
6aeaabf505
3 changed files with 45 additions and 24 deletions
|
@ -1,23 +0,0 @@
|
||||||
#### New timer
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<div style={{ backgroundColor: 'darkgray' }}>
|
|
||||||
<Countdown
|
|
||||||
expiresAt={Date.now() + 10 * 1000}
|
|
||||||
duration={10 * 1000}
|
|
||||||
onComplete={() => console.log('onComplete - new timer')}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Already started
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
<div style={{ backgroundColor: 'darkgray' }}>
|
|
||||||
<Countdown
|
|
||||||
expiresAt={Date.now() + 10 * 1000}
|
|
||||||
duration={30 * 1000}
|
|
||||||
onComplete={() => console.log('onComplete - already started')}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
```
|
|
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} />;
|
||||||
|
});
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
// import classNames from 'classnames';
|
// import classNames from 'classnames';
|
||||||
|
|
||||||
interface Props {
|
export interface Props {
|
||||||
duration: number;
|
duration: number;
|
||||||
expiresAt: number;
|
expiresAt: number;
|
||||||
onComplete?: () => unknown;
|
onComplete?: () => unknown;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue