-
Notifications
You must be signed in to change notification settings - Fork 43
feat: add searchable country dropdown and fix dropdown UX #1127
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f2134e7
feat: replace country/currency inputs with searchable dropdown
descorp ef81fc5
fix: prevent dropdown modal closing on inner whitespace tap, add chev…
descorp cc8e901
chore: add dynamic bottom paddings
descorp 2f9352f
refactor: split FormDropdown into separate compact and search variant…
descorp 22849dc
fix: address code review - Pressable, SafeAreaView, useCallback, min …
descorp a608e49
fix: add dynamic safe area bottom padding to all settings views
descorp 2a8bd0f
refactor: extract PageScrollView to remove safe area padding duplicat…
descorp 1eff274
fix: memoize renderItem in FormDropdown, guard labelExtractor, add ke…
descorp 0bd7bb6
fix: memoize contentContainerStyle in PageScrollView, use readonly T[…
descorp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| /* | ||
| * Copyright (c) 2024 Adyen N.V. | ||
| * This file is open source and available under the MIT license. | ||
| * See the LICENSE file for more info. | ||
| */ | ||
|
|
||
| export type CountryInfo = { | ||
| name: string; | ||
| currency: string; | ||
| }; | ||
|
|
||
| export const COUNTRY_DATA: Record<string, CountryInfo> = { | ||
| AE: { name: 'United Arab Emirates', currency: 'AED' }, | ||
| AT: { name: 'Austria', currency: 'EUR' }, | ||
| AU: { name: 'Australia', currency: 'AUD' }, | ||
| BE: { name: 'Belgium', currency: 'EUR' }, | ||
| BR: { name: 'Brazil', currency: 'BRL' }, | ||
| CA: { name: 'Canada', currency: 'CAD' }, | ||
| CH: { name: 'Switzerland', currency: 'CHF' }, | ||
| CN: { name: 'China', currency: 'CNY' }, | ||
| CZ: { name: 'Czech Republic', currency: 'CZK' }, | ||
| DE: { name: 'Germany', currency: 'EUR' }, | ||
| DK: { name: 'Denmark', currency: 'DKK' }, | ||
| ES: { name: 'Spain', currency: 'EUR' }, | ||
| FI: { name: 'Finland', currency: 'EUR' }, | ||
| FR: { name: 'France', currency: 'EUR' }, | ||
| GB: { name: 'United Kingdom', currency: 'GBP' }, | ||
| HK: { name: 'Hong Kong', currency: 'HKD' }, | ||
| ID: { name: 'Indonesia', currency: 'IDR' }, | ||
| IN: { name: 'India', currency: 'INR' }, | ||
| IT: { name: 'Italy', currency: 'EUR' }, | ||
| JP: { name: 'Japan', currency: 'JPY' }, | ||
| KE: { name: 'Kenya', currency: 'KES' }, | ||
| KR: { name: 'South Korea', currency: 'KRW' }, | ||
| MX: { name: 'Mexico', currency: 'MXN' }, | ||
| MY: { name: 'Malaysia', currency: 'MYR' }, | ||
| NL: { name: 'Netherlands', currency: 'EUR' }, | ||
| NO: { name: 'Norway', currency: 'NOK' }, | ||
| NZ: { name: 'New Zealand', currency: 'NZD' }, | ||
| PH: { name: 'Philippines', currency: 'PHP' }, | ||
| PL: { name: 'Poland', currency: 'PLN' }, | ||
| PT: { name: 'Portugal', currency: 'EUR' }, | ||
| RU: { name: 'Russia', currency: 'RUB' }, | ||
| SE: { name: 'Sweden', currency: 'SEK' }, | ||
| SG: { name: 'Singapore', currency: 'SGD' }, | ||
| TH: { name: 'Thailand', currency: 'THB' }, | ||
| US: { name: 'United States', currency: 'USD' }, | ||
| VN: { name: 'Vietnam', currency: 'VND' }, | ||
| ZA: { name: 'South Africa', currency: 'ZAR' }, | ||
| }; | ||
|
|
||
| export const COUNTRY_CODES = Object.keys(COUNTRY_DATA); | ||
|
|
||
| export const getCountryLabel = (countryCode: string): string => { | ||
| const data = COUNTRY_DATA[countryCode]; | ||
| return data ? `${data.name} - ${data.currency}` : countryCode; | ||
| }; | ||
|
|
||
| export const getCurrency = (countryCode: string): string | undefined => { | ||
| return COUNTRY_DATA[countryCode]?.currency; | ||
| }; | ||
|
descorp marked this conversation as resolved.
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
42 changes: 42 additions & 0 deletions
42
example/src/components/Settings/common/DropdownTrigger.tsx
This file contains hidden or 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,42 @@ | ||
| import { type PropsWithChildren } from 'react'; | ||
| import { TouchableOpacity, View, useColorScheme } from 'react-native'; | ||
| import Styles from '../../common/Styles'; | ||
| import AdaptiveText from '../../common/AdaptiveText'; | ||
| import Colors from '../../common/Assets'; | ||
|
|
||
| type DropdownTriggerProps = { | ||
| title: string; | ||
| label: string; | ||
| onPress: () => void; | ||
| }; | ||
|
|
||
| const DropdownTrigger = ({ | ||
| title, | ||
| label, | ||
| onPress, | ||
| children, | ||
| }: PropsWithChildren<DropdownTriggerProps>) => { | ||
| const isDarkMode = useColorScheme() === 'dark'; | ||
| const backgroundColor = isDarkMode | ||
| ? Colors.textBackgroundDark | ||
| : Colors.textBackgroundLight; | ||
| const textColor = isDarkMode ? Colors.textDark : Colors.textLight; | ||
|
|
||
| return ( | ||
| <View> | ||
| <AdaptiveText style={Styles.paddedTitle}>{title}</AdaptiveText> | ||
| <TouchableOpacity | ||
| style={[Styles.dropdown, { backgroundColor }]} | ||
| onPress={onPress} | ||
| > | ||
|
descorp marked this conversation as resolved.
|
||
| <AdaptiveText style={Styles.dropdownText}>{label}</AdaptiveText> | ||
| <AdaptiveText style={[Styles.dropdownText, { color: textColor }]}> | ||
| {'›'} | ||
| </AdaptiveText> | ||
| </TouchableOpacity> | ||
| {children} | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default DropdownTrigger; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.