Skip to content

Commit

Permalink
Use firstOption / lastOption for props
Browse files Browse the repository at this point in the history
This commit changes the RadioSwitch API to accept two options -
`firstOption` and `lastOption`, both accepting an object with
`label` and `value` properties.
  • Loading branch information
Kristofer Selbekk committed Aug 16, 2016
1 parent 6e12bae commit 0084279
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ import { RadioSwitch } from 'ffe-radio-button-react';
name="some-setting"
label="En innstilling"
onChange={ function }
switch1Label="På"
switch1Value={ true }
switch2Label="Av"
switch2Value={ false }
firstOption={ { label: 'På', value: true } }
lastOption={ { label: 'Av', value: false } }
value={ true }
/>
```
30 changes: 16 additions & 14 deletions src/radio-switch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ const RadioSwitch = (props) => {
value,
disabled,
label,
switch1Label,
switch2Label,
firstOption,
lastOption,
name,
onChange,
switch1Value,
switch2Value,
} = props;

return (
Expand All @@ -25,17 +23,17 @@ const RadioSwitch = (props) => {
onChange={onChange}
>
<RadioBase
checked={value === switch1Value}
label={switch1Label}
checked={value === firstOption.value}
label={firstOption.label}
labelClasses="ffe-radio-switch"
value={switch1Value}
value={firstOption.value}
/>
<span> </span>
<RadioBase
checked={value === switch2Value}
label={switch2Label}
checked={value === lastOption.value}
label={lastOption.label}
labelClasses="ffe-radio-switch"
value={switch2Value}
value={lastOption.value}
/>
</RadioButtonGroup>
);
Expand All @@ -44,13 +42,17 @@ const RadioSwitch = (props) => {
RadioSwitch.propTypes = {
value: PropTypes.string,
disabled: PropTypes.bool,
firstOption: PropTypes.shape({
label: PropTypes.node.isRequired,
value: PropTypes.any.isRequired
}).isRequired,
label: PropTypes.string,
switch1Label: PropTypes.any.isRequired,
switch2Label: PropTypes.any.isRequired,
lastOption: PropTypes.shape({
label: PropTypes.node.isRequired,
value: PropTypes.any.isRequired
}).isRequired,
name: PropTypes.string,
onChange: PropTypes.func,
switch1Value: PropTypes.any.isRequired,
switch2Value: PropTypes.any.isRequired,
};

export default RadioSwitch;
4 changes: 2 additions & 2 deletions src/radio-switch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('<RadioSwitch />', () => {
const checkedValue = 2;
const wrapper = shallow(
<RadioSwitch
switch1Label="one" switch2Label="two"
switch1Value={ 1 } switch2Value={ 2 }
firstOption={ { label: 'one', value: 1 } }
lastOption={ { label: 'two', value: 2 } }
value={ checkedValue }
/>
);
Expand Down

0 comments on commit 0084279

Please sign in to comment.