-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate from
@dump247/storybook-state
to useState
hook
- as per its archived docs - tried to make the diff as small as possible Signed-off-by: Anton Gilgur <[email protected]>
- Loading branch information
Anton Gilgur
committed
Jul 18, 2024
1 parent
ce69bfa
commit d7a4c73
Showing
6 changed files
with
39 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
import { Store, withState } from '@dump247/storybook-state'; | ||
import { storiesOf } from '@storybook/react'; | ||
import * as React from 'react'; | ||
|
||
import { Select } from '../src/components'; | ||
|
||
storiesOf('Select', module) | ||
.add('default', withState({ selected: 'option1' })(({store}: { store: Store<any> }) => ( | ||
() => ( | ||
.add('default', () => { | ||
const [selected, setSelected] = React.useState('option1'); | ||
return ( | ||
<div> | ||
<h4> | ||
Selected option value: {store.state.selected} | ||
<button className='argo-button argo-button--base' onClick={() => store.set({ selected: 'option2' })} >Select option 2</button> | ||
Selected option value: {selected} | ||
<button className='argo-button argo-button--base' onClick={() => setSelected('option2')} >Select option 2</button> | ||
</h4> | ||
<Select | ||
value={store.state.selected} | ||
value={selected} | ||
placeholder='Select something' | ||
options={['option1', { value: 'option2', title: 'Option 2' }]} | ||
onChange={(option) => store.set({ selected: option.value })} | ||
onChange={(option) => setSelected(option.value)} | ||
/> | ||
</div> | ||
))), | ||
).add('multi-select', withState({ selected: 'option1' })(({store}: { store: Store<any> }) => ( | ||
() => ( | ||
)}, | ||
).add('multi-select', () => { | ||
const [selected, setSelected] = React.useState(['option1']); | ||
return ( | ||
<div> | ||
<Select | ||
value={store.state.selected} | ||
value={selected} | ||
multiSelect={true} | ||
placeholder='Select something' | ||
options={['option1', { value: 'option2', title: 'Option 2' }]} | ||
onMultiChange={(options) => store.set({ selected: options.map((item) => item.value) })} | ||
onMultiChange={(options) => setSelected(options.map((item) => item.value))} | ||
/> | ||
</div> | ||
))), | ||
)}, | ||
); |
Oops, something went wrong.