Skip to content

Commit 5371d11

Browse files
committed
feat: add CountrySelect component and integrate react-international-phone for country selection
1 parent 3abec67 commit 5371d11

File tree

7 files changed

+67
-0
lines changed

7 files changed

+67
-0
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
"react-dates": "^21.8.0",
125125
"react-diff-viewer-continued": "^3.4.0",
126126
"react-draggable": "^4.4.5",
127+
"react-international-phone": "^4.5.0",
127128
"react-monaco-editor": "^0.54.0",
128129
"react-virtualized-sticky-tree": "^3.0.0-beta18",
129130
"sass": "^1.69.7",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { SelectPicker } from '../SelectPicker'
2+
import { COUNTRY_OPTIONS } from './constants'
3+
import { CountrySelectProps } from './types'
4+
5+
const CountrySelect = ({ selectedCountry, label, required, error, handleChange, placeholder }: CountrySelectProps) => {
6+
const onChange = (option: (typeof COUNTRY_OPTIONS)[number]) => {
7+
handleChange(option.value)
8+
}
9+
10+
const selectedValue: (typeof COUNTRY_OPTIONS)[number] = selectedCountry
11+
? COUNTRY_OPTIONS.find((option) => option.value === selectedCountry) || {
12+
value: 'XX',
13+
label: 'Unknown',
14+
startIcon: null,
15+
}
16+
: null
17+
18+
return (
19+
<SelectPicker
20+
inputId="select-picker__country-select"
21+
value={selectedValue}
22+
onChange={onChange}
23+
error={error}
24+
required={required}
25+
label={label}
26+
options={COUNTRY_OPTIONS}
27+
placeholder={placeholder}
28+
/>
29+
)
30+
}
31+
32+
export default CountrySelect
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defaultCountries, FlagImage, parseCountry } from 'react-international-phone'
2+
import { SelectPickerOptionType } from '../SelectPicker'
3+
import { CountryISO2Type } from './types'
4+
5+
export const COUNTRY_OPTIONS: SelectPickerOptionType<CountryISO2Type>[] = defaultCountries.map((countryData) => {
6+
const parsedCountry = parseCountry(countryData)
7+
8+
return {
9+
value: parsedCountry.iso2,
10+
label: parsedCountry.name,
11+
startIcon: <FlagImage iso2={parsedCountry.iso2} protocol={window.isSecureContext ? 'https' : 'http'} />,
12+
}
13+
})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as CountrySelect } from './CountrySelect.component'
2+
export { type CountryISO2Type } from './types'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ParsedCountry } from 'react-international-phone'
2+
import { SelectPickerProps } from '../SelectPicker'
3+
4+
export type CountryISO2Type = ParsedCountry['iso2']
5+
6+
export interface CountrySelectProps extends Pick<SelectPickerProps, 'required' | 'label' | 'error' | 'placeholder'> {
7+
selectedCountry: CountryISO2Type
8+
handleChange: (iso2: CountryISO2Type) => void
9+
}

src/Shared/Components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,4 @@ export * from './CodeEditorWrapper'
8585
export * from './SSOProviderIcon'
8686
export * from './Backdrop'
8787
export * from './LicenseInfoDialog'
88+
export * from './CountrySelect'

0 commit comments

Comments
 (0)