react-use/stories/useKeyPress.story.tsx
Anton Zinovyev 2832b7a37e
chore: move all stories from src directory. (#715)
chore: clean tsconfig.json;

feat: updated webpack config to export a function to achieve full-control mode, instead of deprecated Extend Mode;
2019-12-09 23:36:40 +03:00

29 lines
795 B
TypeScript

import { storiesOf } from '@storybook/react';
import * as React from 'react';
import { useKeyPress } from '../src';
import { CenterStory } from './util/CenterStory';
import ShowDocs from './util/ShowDocs';
const keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
const Demo = () => {
const states = [];
for (const key of keys) {
states.push(useKeyPress(key)[0]);
}
return (
<CenterStory>
<div style={{ textAlign: 'center' }}>
Try pressing numbers
<br />
{states.reduce((s, pressed, index) => s + (pressed ? (s ? ' + ' : '') + keys[index] : ''), '')}
</div>
</CenterStory>
);
};
storiesOf('Sensors|useKeyPress', module)
.add('Docs', () => <ShowDocs md={require('../docs/useKeyPress.md')} />)
.add('Demo', () => <Demo />);