1 | import React from 'react'
|
2 | import { storiesOf } from '@storybook/react'
|
3 | import { action, decorateAction } from '@storybook/addon-actions'
|
4 |
|
5 | import roles from './app-roles.json'
|
6 | import { RoleSelection } from '../src'
|
7 | import R from 'ramda'
|
8 |
|
9 | const toggleSelection = role => selected =>
|
10 | selected.includes(role)
|
11 | ? R.filter(r => r !== role, selected)
|
12 | : [...selected, role]
|
13 |
|
14 | class RoleSelectionDemo extends React.Component {
|
15 | state = { selection: [] }
|
16 |
|
17 | toggleRoleSelection = role =>
|
18 | this.setState(({ selection }) => ({
|
19 | selection: toggleSelection(role)(selection),
|
20 | }))
|
21 |
|
22 | render() {
|
23 | const { selection } = this.state
|
24 | return (
|
25 | <RoleSelection
|
26 | roles={roles}
|
27 | selection={selection}
|
28 | toggleSelection={this.toggleRoleSelection}
|
29 | />
|
30 | )
|
31 | }
|
32 | }
|
33 |
|
34 | storiesOf('Access Role Selection', module).add(
|
35 | 'Controlled Role Selection',
|
36 | () => <RoleSelectionDemo />
|
37 | )
|
38 |
|
\ | No newline at end of file |