File size: 1,664 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import { storiesOf } from '@storybook/react';
import * as React from 'react';
import { useCounter } from '../src';
import ShowDocs from './util/ShowDocs';
const Demo = () => {
const [initialValue, setInitialValue] = React.useState(5);
const [min, { inc: incMin, dec: decMin }] = useCounter(1);
const [max, { inc: incMax, dec: decMax }] = useCounter(10);
const [value, { inc, dec, set, reset }] = useCounter(initialValue, max, min);
return (
<div>
<div>
current: {value} [min: {min}; max: {max}]
</div>
<br />
Current value: <button onClick={() => inc()}>Increment</button>
<button onClick={() => dec()}>Decrement</button>
<button onClick={() => inc(5)}>Increment (+5)</button>
<button onClick={() => dec(5)}>Decrement (-5)</button>
<button onClick={() => set(100)}>Set 100</button>
<button onClick={() => reset()}>Reset</button>
<button onClick={() => reset(25)}>Reset (25)</button>
<br />
<br />
Min value:
<button onClick={() => incMin()}>Increment</button>
<button onClick={() => decMin()}>Decrement</button>
<br />
<br />
Max value:
<button onClick={() => incMax()}>Increment</button>
<button onClick={() => decMax()}>Decrement</button>
<br />
<br />
Initial value: {initialValue}
<button onClick={() => setInitialValue((v) => ++v)}>Increment</button>
<button onClick={() => setInitialValue((v) => --v)}>Decrement</button>
</div>
);
};
storiesOf('State/useCounter', module)
.add('Docs', () => <ShowDocs md={require('../docs/useCounter.md')} />)
.add('Demo', () => <Demo />);
|