Skip to content

Replace defaultProps #538

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export default function App() {
- `renderFlagButton?`(props: (FlagButton['props'])): ReactNode ([FlagButton props](https://github.com/xcarpentier/react-native-country-picker-modal/blob/master/src/FlagButton.tsx#L73))
- `renderCountryFilter?`(props: CountryFilter['props']): ReactNode ([CountryFilter props is TextInputProps](https://facebook.github.io/react-native/docs/textinput#props))
- `onSelect`(country: Country): void ([Country](https://github.com/xcarpentier/react-native-country-picker-modal/blob/master/src/types.ts#L263))
- `onOpen`(): void
- `onClose`(): void
- `onOpen`: () => void
- `onClose`: () => void
- `closeButtonImage?`: [ImageSourcePropType](https://facebook.github.io/react-native/docs/image#props)
- `closeButtonStyle?`: StyleProp<ViewStyle>
- `closeButtonImageStyle?`: StyleProp<ImageStyle>
Expand Down
5 changes: 1 addition & 4 deletions src/AnimatedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface Props {
children: React.ReactNode
}

export const AnimatedModal = ({ children, visible }: Props) => {
export const AnimatedModal = ({ children, visible = false }: Props) => {
const translateY = new Animated.Value(height)

const showModal = Animated.timing(translateY, {
Expand Down Expand Up @@ -47,6 +47,3 @@ export const AnimatedModal = ({ children, visible }: Props) => {
)
}

AnimatedModal.defaultProps = {
visible: false,
}
2 changes: 1 addition & 1 deletion src/CloseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface CloseButtonProps {
style?: StyleProp<ViewStyle>
imageStyle?: StyleProp<ImageStyle>
image?: ImageSourcePropType
onPress?(): void
onPress?: () => void
}

const CloseButtonAndroid: React.FC<CloseButtonProps> = (props) => {
Expand Down
19 changes: 14 additions & 5 deletions src/CountryFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ const styles = StyleSheet.create({

export type CountryFilterProps = TextInputProps

export const CountryFilter = (props: CountryFilterProps) => {
export const CountryFilter = ({
autoFocus = false,
placeholder = 'Enter country name',
...rest
}: CountryFilterProps) => {
const {
filterPlaceholderTextColor,
fontFamily,
fontSize,
onBackgroundTextColor,
} = useTheme()

const props = {
autoFocus,
placeholder,
...rest,
}

return (
<TextInput
testID='text-input-country-filter'
Expand All @@ -34,12 +45,10 @@ export const CountryFilter = (props: CountryFilterProps) => {
styles.input,
{ fontFamily, fontSize, color: onBackgroundTextColor },
]}
placeholder={placeholder}
autoFocus={autoFocus}
{...props}
/>
)
}

CountryFilter.defaultProps = {
autoFocus: false,
placeholder: 'Enter country name',
}
12 changes: 2 additions & 10 deletions src/CountryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ const CountryItem = (props: CountryItemProps) => {
const {
country,
onSelect,
withFlag,
withFlag = true,
withEmoji,
withCallingCode,
withCallingCode = false,
withCurrency,
} = props
const extraContent: string[] = []
Expand Down Expand Up @@ -136,10 +136,6 @@ const CountryItem = (props: CountryItemProps) => {
</TouchableOpacity>
)
}
CountryItem.defaultProps = {
withFlag: true,
withCallingCode: false,
}
const MemoCountryItem = memo<CountryItemProps>(CountryItem)

const renderItem =
Expand Down Expand Up @@ -256,7 +252,3 @@ export const CountryList = (props: CountryListProps) => {
</View>
)
}

CountryList.defaultProps = {
filterFocus: undefined,
}
15 changes: 6 additions & 9 deletions src/CountryModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ const styles = StyleSheet.create({

export const CountryModal = ({
children,
withModal,
disableNativeModal,
...props
withModal = true,
disableNativeModal = false,
animated = true,
animationType = 'slide',
...rest
}: ModalProps & {
children: React.ReactNode
withModal?: boolean
disableNativeModal?: boolean
}) => {
const props = { animationType, animated, ...rest }
const { backgroundColor } = useTheme()
const { teleport } = React.useContext(CountryModalContext)
const content = (
Expand All @@ -45,9 +48,3 @@ export const CountryModal = ({
return content
}

CountryModal.defaultProps = {
animationType: 'slide',
animated: true,
withModal: true,
disableNativeModal: false,
}
21 changes: 7 additions & 14 deletions src/CountryPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ interface CountryPickerProps {
props: React.ComponentProps<typeof CountryFilter>,
): ReactNode
onSelect(country: Country): void
onOpen?(): void
onClose?(): void
onOpen?: () => void
onClose?: () => void
}

export const CountryPicker = (props: CountryPickerProps) => {
const {
allowFontScaling,
allowFontScaling = true,
countryCode,
region,
subregion,
Expand All @@ -107,11 +107,11 @@ export const CountryPicker = (props: CountryPickerProps) => {
withCallingCodeButton,
withCurrencyButton,
containerButtonStyle,
withAlphaFilter,
withCallingCode,
withAlphaFilter= false,
withCallingCode= false,
withCurrency,
withFlag,
withModal,
withModal= true,
disableNativeModal,
withFlagButton,
onClose: handleClose,
Expand All @@ -120,7 +120,7 @@ export const CountryPicker = (props: CountryPickerProps) => {
closeButtonStyle,
closeButtonImageStyle,
excludeCountries,
placeholder,
placeholder = 'Select Country',
preferredCountries,
} = props
const [state, setState] = useState<State>({
Expand Down Expand Up @@ -244,10 +244,3 @@ export const CountryPicker = (props: CountryPickerProps) => {
)
}

CountryPicker.defaultProps = {
withModal: true,
withAlphaFilter: false,
withCallingCode: false,
placeholder: 'Select Country',
allowFontScaling: true,
}
8 changes: 2 additions & 6 deletions src/Flag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ const EmojiFlag = memo(({ countryCode, flagSize }: FlagType) => {

export const Flag = ({
countryCode,
withEmoji,
withFlagButton,
withEmoji = true,
withFlagButton = true,
flagSize,
}: FlagType) =>
withFlagButton ? (
Expand All @@ -93,7 +93,3 @@ export const Flag = ({
</View>
) : null

Flag.defaultProps = {
withEmoji: true,
withFlagButton: true,
}
19 changes: 6 additions & 13 deletions src/FlagButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ export interface FlagButtonProps {
containerButtonStyle?: StyleProp<ViewStyle>
countryCode?: CountryCode
placeholder: string
onOpen?(): void
onOpen?: () => void
}

export const FlagButton = ({
allowFontScaling,
withEmoji,
withCountryNameButton,
withCallingCodeButton,
withCurrencyButton,
withFlagButton,
withEmoji = true,
withCountryNameButton = false,
withCallingCodeButton = false,
withCurrencyButton = false,
withFlagButton = true,
countryCode,
containerButtonStyle,
onOpen,
Expand Down Expand Up @@ -162,10 +162,3 @@ export const FlagButton = ({
)
}

FlagButton.defaultProps = {
withEmoji: true,
withCountryNameButton: false,
withCallingCodeButton: false,
withCurrencyButton: false,
withFlagButton: true,
}
8 changes: 2 additions & 6 deletions src/HeaderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ interface HeaderModalProps {
closeButtonImage?: ImageSourcePropType
closeButtonStyle?: StyleProp<ViewStyle>
closeButtonImageStyle?: StyleProp<ImageStyle>
onClose(): void
onClose: () => void
renderFilter(props: HeaderModalProps): ReactNode
}
export const HeaderModal = (props: HeaderModalProps) => {
const {
withFilter,
withCloseButton,
withCloseButton = true,
closeButtonImage,
closeButtonStyle,
closeButtonImageStyle,
Expand All @@ -49,7 +49,3 @@ export const HeaderModal = (props: HeaderModalProps) => {
</View>
)
}

HeaderModal.defaultProps = {
withCloseButton: true,
}
20 changes: 11 additions & 9 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ interface Props {
containerButtonStyle?: StyleProp<ViewStyle>
renderFlagButton?(props: FlagButtonProps): ReactNode
renderCountryFilter?(props: CountryFilterProps): ReactNode
onSelect(country: Country): void
onOpen?(): void
onClose?(): void
onSelect?: (country: Country) => void
onOpen?: () => void
onClose?: () => void
}

const Main = ({ theme, translation, ...props }: Props) => {
const Main = ({ theme, translation, ...rest }: Props) => {

const props = {
onSelect: () => {},
withEmoji: true,
...rest,
};

return (
<ThemeProvider theme={{ ...DEFAULT_THEME, ...theme }}>
<CountryProvider value={{ ...DEFAULT_COUNTRY_CONTEXT, translation }}>
Expand All @@ -59,11 +66,6 @@ const Main = ({ theme, translation, ...props }: Props) => {
)
}

Main.defaultProps = {
onSelect: () => {},
withEmoji: true,
}

export default Main
export {
getCountriesAsync as getAllCountries,
Expand Down