UNPKG

948 BJavaScriptView Raw
1import React from 'react'
2import { storiesOf } from '@storybook/react'
3import { action, decorateAction } from '@storybook/addon-actions'
4//import ReactJson from 'react-json-view'
5import roles from './app-roles.json'
6import { RoleSelection } from '../src'
7import R from 'ramda'
8
9const toggleSelection = role => selected =>
10 selected.includes(role)
11 ? R.filter(r => r !== role, selected)
12 : [...selected, role]
13
14class 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
34storiesOf('Access Role Selection', module).add(
35 'Controlled Role Selection',
36 () => <RoleSelectionDemo />
37)
38
\No newline at end of file