-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace AddressInput Selects #321
Changes from all commits
5f5f961
7e04b21
2439584
551ce7a
92449c1
cf2ec6d
3863837
beedc40
a6055f6
802fe5a
9f1d1a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,13 @@ import PropTypes from 'prop-types'; | |
import React from 'react'; | ||
import flow from 'lodash.flow'; | ||
|
||
import Select from './Select'; | ||
import CountryInput from './CountryInput'; | ||
import StateInput from './StateInput'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name is slightly ambiguous. Should we call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, idea was it might handle determining provinces for various countries, but agreed "State" is vague |
||
import ValidatedFormGroup from './ValidatedFormGroup'; | ||
import Col from './Col'; | ||
import Input from './Input'; | ||
import Row from './Row'; | ||
|
||
// TODO Dynamic states based on country: | ||
import states from './address/USStates.js'; | ||
import COUNTRIES from './address/Countries.js'; | ||
|
||
const US_STATES = states.map(state => ({ | ||
label: state.value, | ||
value: state.value | ||
})); | ||
|
||
const readEvent = e => ({ [e.target.name]: e.target.value }); | ||
|
||
class AddressInput extends React.Component { | ||
|
@@ -48,11 +40,11 @@ class AddressInput extends React.Component { | |
value: {}, | ||
}; | ||
|
||
onChange = update => { | ||
onChange = (update) => { | ||
this.props.onChange({ ...this.props.value, ...update }); | ||
} | ||
|
||
propsFor = field => { | ||
propsFor = (field) => { | ||
if (this.props.value[field]) { | ||
return { value: this.props.value[field] }; | ||
} | ||
|
@@ -126,14 +118,13 @@ class AddressInput extends React.Component { | |
error={error.state} | ||
label={showLabels ? labels.state : null} | ||
> | ||
<Select | ||
<StateInput | ||
className="w-100" | ||
inputProps={{ id: id ? `${id}_state` : null }} | ||
id={id ? `${id}_state` : null} | ||
name="state" | ||
placeholder={labels.state} | ||
options={US_STATES} | ||
{...this.propsFor('state')} | ||
onChange={selection => this.onChange({ state: selection && selection.value })} | ||
onChange={state => this.onChange({ state })} | ||
disabled={disabled} | ||
/> | ||
</ValidatedFormGroup> | ||
|
@@ -161,14 +152,13 @@ class AddressInput extends React.Component { | |
className="mb-0" | ||
label={showLabels ? labels.countryCode : null} | ||
> | ||
<Select | ||
<CountryInput | ||
className="w-100" | ||
inputProps={{ id: id ? `${id}_countryCode` : null }} | ||
id={id ? `${id}_countryCode` : null} | ||
name="countryCode" | ||
options={COUNTRIES} | ||
placeholder={labels.countryCode} | ||
{...this.propsFor('countryCode')} | ||
onChange={selection => this.onChange({ countryCode: selection && selection.value })} | ||
onChange={countryCode => this.onChange({ countryCode })} | ||
disabled={disabled} | ||
/> | ||
</ValidatedFormGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Input from './Input'; | ||
import COUNTRIES from './address/Countries.js'; // TODO i18n country names based on locale | ||
|
||
export default class CountryInput extends React.Component { | ||
static propTypes = { | ||
className: PropTypes.string, | ||
disabled: PropTypes.bool, | ||
id: PropTypes.string, | ||
name: PropTypes.string, | ||
onChange: PropTypes.func, | ||
placeholder: PropTypes.string, | ||
value: PropTypes.string | ||
} | ||
|
||
static defaultProps = { | ||
onChange: () => {} | ||
} | ||
|
||
render() { | ||
const { | ||
className, | ||
disabled, | ||
id, | ||
name, | ||
onChange, | ||
placeholder, | ||
...props | ||
} = this.props; | ||
|
||
return ( | ||
<Input | ||
type="select" | ||
{...props} | ||
className={className} | ||
disabled={disabled} | ||
id={id} | ||
name={name} | ||
onChange={e => onChange(e.target.value === '' ? null : e.target.value)} | ||
> | ||
<option value="">{placeholder}</option> | ||
{COUNTRIES.map(country => | ||
<option value={country.value} key={country.value}>{country.label}</option>)} | ||
</Input> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Input from './Input'; | ||
import STATES from './address/USStates.js'; // TODO Dynamic states based on country | ||
|
||
export default class StateInput extends React.Component { | ||
static propTypes = { | ||
className: PropTypes.string, | ||
disabled: PropTypes.bool, | ||
id: PropTypes.string, | ||
name: PropTypes.string, | ||
onChange: PropTypes.func, | ||
placeholder: PropTypes.string, | ||
value: PropTypes.string | ||
} | ||
|
||
static defaultProps = { | ||
onChange: () => {} | ||
} | ||
|
||
render() { | ||
const { | ||
className, | ||
disabled, | ||
id, | ||
name, | ||
onChange, | ||
placeholder, | ||
...props | ||
} = this.props; | ||
|
||
return ( | ||
<Input | ||
type="select" | ||
{...props} | ||
className={className} | ||
disabled={disabled} | ||
id={id} | ||
name={name} | ||
onChange={e => onChange(e.target.value === '' ? null : e.target.value)} | ||
> | ||
<option value="">{placeholder}</option> | ||
{STATES.map(state => | ||
<option title={state.label} value={state.value} key={state.value}>{state.value}</option>)} | ||
</Input> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ export default [ | |
{ label: 'California', value: 'CA' }, | ||
{ label: 'Colorado', value: 'CO' }, | ||
{ label: 'Connecticut', value: 'CT' }, | ||
{ label: 'Deleware', value: 'DE' }, | ||
{ label: 'Delaware', value: 'DE' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
{ label: 'Washington, D.C.', value: 'DC' }, | ||
{ label: 'Florida', value: 'FL' }, | ||
{ label: 'Georgia', value: 'GA' }, | ||
|
@@ -16,7 +16,7 @@ export default [ | |
{ label: 'Indiana', value: 'IN' }, | ||
{ label: 'Iowa', value: 'IA' }, | ||
{ label: 'Kansas', value: 'KS' }, | ||
{ label: 'Kentuky', value: 'KY' }, | ||
{ label: 'Kentucky', value: 'KY' }, | ||
{ label: 'Louisiana', value: 'LA' }, | ||
{ label: 'Maine', value: 'ME' }, | ||
{ label: 'Maryland', value: 'MD' }, | ||
|
@@ -49,5 +49,15 @@ export default [ | |
{ label: 'Washington', value: 'WA' }, | ||
{ label: 'West Virginia', value: 'WV' }, | ||
{ label: 'Wisconsin', value: 'WI' }, | ||
{ label: 'Wyoming', value: 'WY' } | ||
{ label: 'Wyoming', value: 'WY' }, | ||
{ label: 'U.S. Armed Forces Americas', value: 'AA' }, | ||
{ label: 'U.S. Armed Forces Europe', value: 'AE' }, | ||
{ label: 'U.S. Armed Forces Pacific', value: 'AP' }, | ||
{ label: 'American Samoa', value: 'AS' }, | ||
{ label: 'Micronesia', value: 'FM' }, | ||
{ label: 'Guam', value: 'GU' }, | ||
{ label: 'Marshall Islands', value: 'MH' }, | ||
{ label: 'Northern Mariana Islands', value: 'MP' }, | ||
{ label: 'Puerto Rico', value: 'PR' }, | ||
{ label: 'Virgin Islands', value: 'VI' } | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this a lot as it allows us to even improve the looks over time.