Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import React, { useState } from 'react'; import { Meta, Story } from '@storybook/react'; import Button from '../Button/Button'; import { ISearchFieldProps, SearchFieldDumb as SearchField, } from './SearchField'; import LoadingIcon from '../Icon/LoadingIcon/LoadingIcon'; export default { title: 'Controls/SearchField', component: SearchField, parameters: { docs: { description: { component: SearchField.peek.description, }, }, }, } as Meta; export const Basic: Story<ISearchFieldProps> = (args) => { return <SearchField {...args} />; }; export const Interactive: Story<ISearchFieldProps> = (args) => { const [state, setState] = useState(''); return ( <div> <SearchField {...args} onSubmit={(value) => setState(value)} /> <div style={{ marginTop: '10px', marginLeft: '10px' }}> Hit "enter" to submit: {state} </div> </div> ); }; export const Placeholder: Story<ISearchFieldProps> = (args) => { return <SearchField {...args} placeholder='Name/ID' />; }; export const Disabled: Story<ISearchFieldProps> = (args) => { return <SearchField {...args} isDisabled />; }; export const CustomIcon: Story<ISearchFieldProps> = (args) => { return ( <SearchField {...args}> <SearchField.Icon> <LoadingIcon /> </SearchField.Icon> </SearchField> ); }; export const CustomTextField: Story<ISearchFieldProps> = (args) => { const [state, setState] = useState({ value: '', submission: '', lastValue: '', }); const [key, setKey] = useState(''); return ( <div> <SearchField {...args} placeholder='Name/ID'> <SearchField.TextField value={state.value} onSubmit={(submission) => setState({ ...state, submission })} onChange={(value) => setState({ ...state, value })} onKeyDown={({ event: { key } }) => setKey(key)} onBlur={(lastValue) => setState({ ...state, lastValue })} /> </SearchField> <div style={{ marginTop: '10px', marginLeft: '10px' }}> <div>Hit "enter" to submit: {state.submission}</div> <div>Last keydown: {key}</div> <div>Value on blur: {state.lastValue}</div> </div> </div> ); }; export const ValidSearch: Story<ISearchFieldProps> = (args) => { const [state, setState] = useState({ value: '', submission: '', lastValue: '', }); return ( <SearchField {...args} placeholder="Search icon doesn't become active until you type at least three characters ----->" isValid={state.value.length > 2} value={state.value} onSubmit={(submission) => setState({ ...state, submission })} onChange={(value) => setState({ ...state, value })} /> ); }; export const Props: Story<ISearchFieldProps> = (args) => { return ( <div> <SearchField {...args} value='foo' /> <SearchField {...args} placeholder='bar' /> <SearchField {...args} isDisabled /> <SearchField {...args} isValid={false} /> <SearchField {...args}> <SearchField.Icon> <LoadingIcon /> </SearchField.Icon> </SearchField> <SearchField {...args} value='foo'> <SearchField.Icon> <LoadingIcon /> </SearchField.Icon> </SearchField> <SearchField {...args}> <SearchField.TextField value='bar' /> </SearchField> </div> ); }; export const Debounced: Story<ISearchFieldProps> = (args) => { const [value, setValue] = useState('foo'); return ( <div> <SearchField {...args} style={{ marginBottom: '10px' }} value={value} onChangeDebounced={(value) => setValue(value)} /> <div style={{ marginBottom: '10px', marginLeft: '10px', }} > Value: {value} </div> <Button {...Button.defaultProps} onClick={() => { setValue('foo'); }} > Set TextField to "foo" </Button> </div> ); }; |