File tree Expand file tree Collapse file tree 4 files changed +35
-15
lines changed
Expand file tree Collapse file tree 4 files changed +35
-15
lines changed Original file line number Diff line number Diff line change @@ -13,9 +13,9 @@ let intlShape;
1313
1414// this make react-intl optional to our component and our module
1515try {
16- const reactIntl = require ( 'react-intl' ) ; // eslint-disable-line
17- injectIntl = reactIntl . injectIntl ; // eslint-disable-line
18- intlShape = reactIntl . intlShape ; // eslint-disable-line
16+ const { injectIntl : injectIntlDefault , intlShape : intlShapeDefault } = require ( 'react-intl' ) ; // eslint-disable-line
17+ injectIntl = injectIntlDefault ; // eslint-disable-line
18+ intlShape = intlShapeDefault ; // eslint-disable-line
1919} catch ( er ) {
2020 injectIntl = null ;
2121 intlShape = null ;
@@ -30,8 +30,9 @@ const ToggleOption = ({
3030 value,
3131 message,
3232 intl,
33+ ...rest
3334} ) => (
34- < Tag value = { value } >
35+ < Tag value = { value } { ... rest } >
3536 { message && intl ? intl . formatMessage ( message ) : value }
3637 </ Tag >
3738) ;
Original file line number Diff line number Diff line change @@ -11,18 +11,30 @@ import Input from '@bootstrap-styled/v4/lib/Input';
1111import ToggleOption from './ToggleOption' ;
1212
1313function Toggle ( props ) {
14- const { tag : Tag , optionTag : OptionTag , defaultLabel } = props ;
15- let content = ( < Option > { defaultLabel } </ Option > ) ;
16-
14+ const {
15+ tag : Tag ,
16+ optionTag : OptionTag ,
17+ defaultLabel,
18+ className,
19+ onToggle,
20+ value,
21+ values,
22+ messages,
23+ ...rest
24+ } = props ;
1725 // If we have items, render them
18- if ( props . values ) {
19- content = props . values . map ( ( value ) => (
20- < OptionTag key = { value } value = { value } message = { props . messages [ value ] } />
21- ) ) ;
22- }
23-
26+ const content = ! values . length ? < Option > { defaultLabel } </ Option > : values . map ( ( v ) => (
27+ < OptionTag key = { v } value = { v } message = { messages [ v ] } />
28+ ) ) ;
2429 return (
25- < Tag type = "select" name = "select" value = { props . value } onChange = { props . onToggle } className = { props . className } >
30+ < Tag
31+ type = "select"
32+ name = "select"
33+ value = { value }
34+ onChange = { onToggle }
35+ className = { className }
36+ { ...rest }
37+ >
2638 { content }
2739 </ Tag >
2840 ) ;
@@ -33,6 +45,9 @@ Toggle.defaultProps = {
3345 optionTag : ToggleOption ,
3446 defaultLabel : '--' ,
3547 messages : { } ,
48+ value : '' ,
49+ values : [ ] ,
50+ onToggle : ( ) => { } ,
3651} ;
3752
3853/* eslint-disable react/require-default-props */
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ That will lock down the dependencies for the packages.
2222
2323That way npm install will look into npm-shrinkwrap.json before trying to install dependencies.
2424
25- You can read more about it here [ https://docs.npmjs.com/cli/shrinkwrap ] [ 1 ]
25+ You can read more about it here https://docs.npmjs.com/cli/shrinkwrap
2626
2727
2828 [ 1 ] : https://docs.npmjs.com/cli/shrinkwrap
Original file line number Diff line number Diff line change @@ -33,4 +33,8 @@ describe('<Toggle />', () => {
3333 expect ( renderedComponent . contains ( < Option > --</ Option > ) ) . toBe ( true ) ;
3434 expect ( renderedComponent . find ( 'Option' ) . length ) . toBe ( 1 ) ;
3535 } ) ;
36+ it ( 'should have ToggleOptions if props.values is defined' , ( ) => {
37+ const renderedComponent = shallow ( < Toggle value = "a" values = { [ 'a' , 'b' ] } /> ) ;
38+ expect ( renderedComponent . find ( 'InjectIntl(ToggleOption)' ) . length ) . toBe ( 2 ) ;
39+ } ) ;
3640} ) ;
You can’t perform that action at this time.
0 commit comments