This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
assets/js/base/components/county-input/billing-county-input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <CountyInput counties={ ALLOWED_COUNTIES } { ...props } />; | ||
}; | ||
|
||
BillingCountyInput.propTypes = { | ||
onChange: PropTypes.func.isRequired, | ||
className: PropTypes.string, | ||
label: PropTypes.string, | ||
value: PropTypes.string, | ||
}; | ||
|
||
export default BillingCountyInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Select from '../select'; | ||
|
||
const CountyInput = ( { | ||
className, | ||
counties, | ||
country, | ||
label, | ||
onChange, | ||
value = '', | ||
} ) => { | ||
const countryCounties = counties[ country ]; | ||
if ( ! countryCounties || Object.keys( countryCounties ).length === 0 ) { | ||
return null; | ||
} | ||
|
||
const options = Object.keys( countryCounties ).map( ( key ) => ( { | ||
key, | ||
name: decodeEntities( countryCounties[ key ] ), | ||
} ) ); | ||
const formattedValue = countryCounties[ value ] | ||
? { | ||
key: value, | ||
name: decodeEntities( countryCounties[ value ] ), | ||
} | ||
: null; | ||
|
||
return ( | ||
<Select | ||
className={ className } | ||
label={ label } | ||
onChange={ onChange } | ||
options={ options } | ||
value={ formattedValue } | ||
/> | ||
); | ||
}; | ||
|
||
CountyInput.propTypes = { | ||
counties: PropTypes.objectOf( | ||
PropTypes.oneOfType( [ | ||
PropTypes.array, | ||
PropTypes.objectOf( PropTypes.string ), | ||
] ) | ||
).isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
className: PropTypes.string, | ||
country: PropTypes.string, | ||
label: PropTypes.string, | ||
value: PropTypes.string, | ||
}; | ||
|
||
export default CountyInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as CountyInput } from './county-input'; | ||
export { default as BillingCountyInput } from './billing-county-input'; | ||
export { default as ShippingCountyInput } from './shipping-county-input'; |
23 changes: 23 additions & 0 deletions
23
assets/js/base/components/county-input/shipping-county-input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
import { SHIPPING_COUNTIES } from '@woocommerce/block-settings'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CountyInput from './county-input.js'; | ||
|
||
const ShippingCountyInput = ( props ) => { | ||
return <CountyInput counties={ SHIPPING_COUNTIES } { ...props } />; | ||
}; | ||
|
||
ShippingCountyInput.propTypes = { | ||
onChange: PropTypes.func.isRequired, | ||
className: PropTypes.string, | ||
label: PropTypes.string, | ||
value: PropTypes.string, | ||
}; | ||
|
||
export default ShippingCountyInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters