From 00842795f5934f84796e1129eca8e3473196a184 Mon Sep 17 00:00:00 2001 From: Kristofer Selbekk Date: Tue, 16 Aug 2016 14:00:15 +0200 Subject: [PATCH] Use firstOption / lastOption for props This commit changes the RadioSwitch API to accept two options - `firstOption` and `lastOption`, both accepting an object with `label` and `value` properties. --- README.md | 6 ++---- src/radio-switch.jsx | 30 ++++++++++++++++-------------- src/radio-switch.test.js | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index f323d4d44b..239cf07094 100644 --- a/README.md +++ b/README.md @@ -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 } /> ``` diff --git a/src/radio-switch.jsx b/src/radio-switch.jsx index 16ec4a0308..be6a59c32b 100644 --- a/src/radio-switch.jsx +++ b/src/radio-switch.jsx @@ -8,12 +8,10 @@ const RadioSwitch = (props) => { value, disabled, label, - switch1Label, - switch2Label, + firstOption, + lastOption, name, onChange, - switch1Value, - switch2Value, } = props; return ( @@ -25,17 +23,17 @@ const RadioSwitch = (props) => { onChange={onChange} > ); @@ -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; diff --git a/src/radio-switch.test.js b/src/radio-switch.test.js index 717348f0e6..09359d37f0 100644 --- a/src/radio-switch.test.js +++ b/src/radio-switch.test.js @@ -13,8 +13,8 @@ describe('', () => { const checkedValue = 2; const wrapper = shallow( );