-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ZNTA-2070) WIP add SettingsOptions and SettingOption stories to …
…editor
- Loading branch information
kgough
committed
Jun 28, 2017
1 parent
12eda40
commit 61b95dc
Showing
5 changed files
with
56 additions
and
92 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...r/zanata-frontend/src/frontend/app/editor/components/SettingOption/SettingOption.story.js
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { storiesOf, action } from '@kadira/storybook' | ||
import SettingOption from '.' | ||
|
||
storiesOf('SettingOption', module) | ||
.add('default', () => ( | ||
<SettingOption | ||
setting={{ | ||
|
||
}} /> | ||
)) |
32 changes: 32 additions & 0 deletions
32
server/zanata-frontend/src/frontend/app/editor/components/SettingOption/index.js
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Checkbox } from 'react-bootstrap' | ||
|
||
const setting = | ||
|
||
class SettingOption extends React.Component { | ||
setting: PropTypes.shape({ | ||
id: PropTypes.any.isRequired, // I will update this to whatever I use when I wire it up | ||
label: PropTypes.string.isRequired, | ||
active: PropTypes.bool.isRequired | ||
}).isRequired | ||
/* arguments: (any: settingId, bool: active) */ | ||
updateSetting: PropTypes.func.isRequired | ||
} | ||
|
||
onChange = (event) => { | ||
this.props.onChange(this.props.setting, event.target.checked) | ||
} | ||
|
||
render () { | ||
const { setting, checked } = this.props | ||
return ( | ||
<Checkbox checked={checked} | ||
onChange={this.onChange}> | ||
{setting} | ||
</Checkbox> | ||
) | ||
} | ||
} | ||
|
||
export default SettingOption |
63 changes: 3 additions & 60 deletions
63
...nata-frontend/src/frontend/app/editor/components/SettingsOptions/SettingsOptions.story.js
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,73 +1,16 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { storiesOf, action } from '@kadira/storybook' | ||
import RealSettingsOptions from '.' | ||
import SettingsOptions from '.' | ||
|
||
/* Wrapper class for storybook. | ||
* The checkbox states will be stored and updated in the live | ||
* app. This wrapper stores the states so that we can see | ||
* them working in storybook too. | ||
*/ | ||
class SettingsOptions extends React.Component { | ||
static propTypes = { | ||
states: PropTypes.object.isRequired, | ||
updateSettingsOption: PropTypes.func.isRequired | ||
} | ||
constructor (props) { | ||
super(props) | ||
this.state = props.states | ||
} | ||
updateValidationOption = (setting, checked) => { | ||
// record the check state in the wrapper | ||
this.setState({ [setting]: checked }) | ||
// call the real one that was passed in | ||
this.props.updateSettingsOption(setting, checked) | ||
} | ||
render () { | ||
return ( | ||
<RealSettingsOptions | ||
updateSettingsOption={this.updateSettingsOption} | ||
states={this.state} /> | ||
) | ||
} | ||
} | ||
|
||
const updateAction = action('updateSettingsOption') | ||
/* | ||
* See .storybook/README.md for info on the component storybook. | ||
*/ | ||
storiesOf('SettingOptions', module) | ||
.add('default', () => ( | ||
<SettingsOptions | ||
updateValidationOption={updateAction} | ||
states={{ | ||
'Enter key saves immediately': false, | ||
'Syntax highlighting': false, | ||
'Suggestions diff': false, | ||
'Panel layout': false, | ||
}} /> | ||
)) | ||
settings={{ | ||
|
||
.add('half checked', () => ( | ||
<SettingsOptions | ||
updateValidationOption={updateAction} | ||
states={{ | ||
'Enter key saves immediately': true, | ||
'Syntax highlighting': false, | ||
'Suggestions diff': true, | ||
'Panel layout': false, | ||
}} /> | ||
}} /> | ||
)) | ||
|
||
.add('all checked', () => ( | ||
<SettingsOptions | ||
updateValidationOption={updateAction} | ||
states={{ | ||
'Enter key saves immediately': true, | ||
'Syntax highlighting': true, | ||
'Suggestions diff': true, | ||
'Panel layout': true, | ||
}} /> | ||
|
||
)) |
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