-
Notifications
You must be signed in to change notification settings - Fork 15
/
stories.tsx
44 lines (39 loc) · 1.46 KB
/
stories.tsx
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
/**
* Copyright Zendesk, Inc.
*
* Use of this source code is governed under the Apache License, Version 2.0
* found at http://www.apache.org/licenses/LICENSE-2.0.
*/
import React from 'react';
import { uid } from 'react-uid';
import { storiesOf } from '@storybook/react';
import { withKnobs, text } from '@storybook/addon-knobs';
import { FieldContainer, useField } from './src';
storiesOf('Field Container', module)
.addDecorator(withKnobs)
.add('useField', () => {
const Field = ({ id }: { id: string }) => {
const { getLabelProps, getInputProps, getHintProps } = useField(id);
const [value, setVal] = React.useState('');
const onChange = (event: React.ChangeEvent<HTMLInputElement>) => setVal(event.target.value);
return (
<>
<label {...getLabelProps()}>Accessible Native Input</label>
<div {...getHintProps()}>Optional Hint</div>
<input {...getInputProps({ value, onChange }, { isDescribed: true })} />
</>
);
};
return <Field id={text('id', uid({ name: 'useField' }))} />;
})
.add('FieldContainer', () => (
<FieldContainer id={text('id', uid({ name: 'FieldContainer' }))}>
{({ getLabelProps, getInputProps, getHintProps }) => (
<>
<label {...getLabelProps()}>Accessible Native Input</label>
<div {...getHintProps()}>Optional Hint</div>
<input {...getInputProps({}, { isDescribed: true })} />
</>
)}
</FieldContainer>
));