Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Split CountryInput and Select
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Feb 13, 2020
1 parent 5a1fcbf commit bb1efa4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
25 changes: 11 additions & 14 deletions assets/js/base/components/country-input/country-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
* External dependencies
*/
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { CustomSelectControl } from 'wordpress-components';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import './style.scss';
import Select from '../select';

const CountryInput = ( {
className,
Expand All @@ -22,21 +20,20 @@ const CountryInput = ( {
key,
name: decodeEntities( countries[ key ] ),
} ) );
const formattedValue = value
? {
key: value,
name: decodeEntities( countries[ value ] ),
}
: null;

return (
<CustomSelectControl
className={ classnames( 'wc-block-country-input', className, {
'is-active': value,
} ) }
<Select
className={ className }
label={ label }
onChange={ onChange }
options={ options }
onChange={ ( { selectedItem } ) => {
onChange( selectedItem.key );
} }
value={ {
key: value,
name: decodeEntities( countries[ value ] ),
} }
value={ formattedValue }
/>
);
};
Expand Down
2 changes: 1 addition & 1 deletion assets/js/base/components/input-row/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
flex-wrap: wrap;
justify-content: space-between;

> .wc-block-country-input,
> .wc-block-select,
> .wc-block-text-input {
margin-right: $gap-small;
flex-basis: 0;
Expand Down
45 changes: 45 additions & 0 deletions assets/js/base/components/select/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { CustomSelectControl } from 'wordpress-components';

/**
* Internal dependencies
*/
import './style.scss';

const Select = ( { className, label, onChange, options, value } ) => {
return (
<CustomSelectControl
className={ classnames( 'wc-block-select', className, {
'is-active': value,
} ) }
label={ label }
onChange={ ( { selectedItem } ) => {
onChange( selectedItem.key );
} }
options={ options }
value={ value }
/>
);
};

Select.propTypes = {
onChange: PropTypes.func.isRequired,
options: PropTypes.arrayOf(
PropTypes.shape( {
key: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
} ).isRequired
).isRequired,
className: PropTypes.string,
label: PropTypes.string,
value: PropTypes.shape( {
key: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
} ),
};

export default Select;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.wc-block-country-input {
.wc-block-select {
position: relative;
margin-top: $gap;

Expand Down

0 comments on commit bb1efa4

Please sign in to comment.