diff --git a/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.js b/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.js index d5beb9ee0b2..7038b1648ee 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.js +++ b/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.js @@ -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, @@ -24,19 +22,12 @@ const CountryInput = ( { } ) ); return ( - { - onChange( selectedItem.key ); - } } - value={ { - key: value, - name: decodeEntities( countries[ value ] ), - } } + value={ options.find( ( option ) => option.key === value ) } /> ); }; diff --git a/plugins/woocommerce-blocks/assets/js/base/components/county-input/billing-county-input.js b/plugins/woocommerce-blocks/assets/js/base/components/county-input/billing-county-input.js new file mode 100644 index 00000000000..c01a1ca0675 --- /dev/null +++ b/plugins/woocommerce-blocks/assets/js/base/components/county-input/billing-county-input.js @@ -0,0 +1,23 @@ +/** + * External dependencies + */ +import PropTypes from 'prop-types'; +import { ALLOWED_COUNTIES } from '@woocommerce/block-settings'; + +/** + * Internal dependencies + */ +import CountyInput from './county-input.js'; + +const BillingCountyInput = ( props ) => { + return ; +}; + +BillingCountyInput.propTypes = { + onChange: PropTypes.func.isRequired, + className: PropTypes.string, + label: PropTypes.string, + value: PropTypes.string, +}; + +export default BillingCountyInput; diff --git a/plugins/woocommerce-blocks/assets/js/base/components/county-input/county-input.js b/plugins/woocommerce-blocks/assets/js/base/components/county-input/county-input.js new file mode 100644 index 00000000000..bf7ca001b12 --- /dev/null +++ b/plugins/woocommerce-blocks/assets/js/base/components/county-input/county-input.js @@ -0,0 +1,63 @@ +/** + * External dependencies + */ +import PropTypes from 'prop-types'; +import { decodeEntities } from '@wordpress/html-entities'; + +/** + * Internal dependencies + */ +import TextInput from '../text-input'; +import Select from '../select'; + +const CountyInput = ( { + className, + counties, + country, + label, + onChange, + value = '', +} ) => { + const countryCounties = counties[ country ]; + if ( ! countryCounties || Object.keys( countryCounties ).length === 0 ) { + return ( + + ); + } + + const options = Object.keys( countryCounties ).map( ( key ) => ( { + key, + name: decodeEntities( countryCounties[ key ] ), + } ) ); + + return ( +