/* * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is located at * * http://aws.amazon.com/apache2.0/ * * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions * and limitations under the License. */ import React, { Component, FC } from 'react'; import { Image, Keyboard, Platform, Text, TextInput, TouchableHighlight, TouchableOpacity, TouchableWithoutFeedback, View, SafeAreaView, TextInputProperties, TouchableOpacityProps, } from 'react-native'; import { Picker } from '@react-native-picker/picker'; import { I18n } from 'aws-amplify'; import AmplifyTheme, { AmplifyThemeType, placeholderColor } from './AmplifyTheme'; import countryDialCodes from './CountryDialCodes'; import TEST_ID from './AmplifyTestIDs'; import icons from './icons'; import { setTestId } from './Utils'; interface IContainerProps { theme?: AmplifyThemeType; } export const Container: FC = (props) => { const theme = props.theme || AmplifyTheme; return {props.children}; }; interface IFormFieldProps extends TextInputProperties { label: string; required?: boolean; theme?: AmplifyThemeType; } export const FormField: FC = (props) => { const theme = props.theme || AmplifyTheme; return ( {props.label} {props.required ? '*' : ''} ); }; interface IPhoneProps extends TextInputProperties { defaultDialCode?: string; label: string; onChangeText: (phoneNumber: string) => void; required?: boolean; theme?: AmplifyThemeType; value?: string; } interface IPhoneState { dialCode: string; phone: string; } const minWidth = { minWidth: Platform.OS === 'android' ? 16 : 0 }; export class PhoneField extends Component { constructor(props: IPhoneProps) { super(props); this.state = { dialCode: this.props.defaultDialCode || '+1', phone: '', }; } onChangeText() { const { dialCode, phone } = this.state; const cleanedPhone = phone.replace(/[^0-9.]/g, '') || ''; const phoneNumber = cleanedPhone === '' ? '' : `${dialCode}${cleanedPhone}`; this.props.onChangeText(phoneNumber); } render() { const { label, required, value } = this.props; const { dialCode } = this.state; const theme = this.props.theme || AmplifyTheme; const phoneValue = value ? value.replace(dialCode, '') : undefined; return ( {label} {required ? '*' : ''} { this.setState({ dialCode }, () => { this.onChangeText(); }); }} > {countryDialCodes.map((dialCode) => ( ))} { this.setState({ phone }, () => { this.onChangeText(); }); }} /> ); } } interface ILinkCellProps { disabled?: boolean; onPress: () => void; testID?: string; theme?: AmplifyThemeType; } export const LinkCell: FC = (props) => { const { disabled } = props; const theme = props.theme || AmplifyTheme; return ( {props.children} ); }; interface IHeaderProps { testID?: string; theme?: AmplifyThemeType; } export const Header: FC = (props) => { const theme = props.theme || AmplifyTheme; return ( {props.children} ); }; interface IErrorRowProps { theme?: AmplifyThemeType; } export const ErrorRow: FC = (props) => { const theme = props.theme || AmplifyTheme; if (!props.children) return null; return ( {props.children} ); }; interface IAmplifyButtonProps extends TouchableOpacityProps { disabled?: boolean; style?: object; text: string; theme?: AmplifyThemeType; } export const AmplifyButton: FC = (props) => { const theme = props.theme || AmplifyTheme; let style = theme.button; if (props.disabled) { style = theme.buttonDisabled; } if (props.style) { style = [style, props.style]; } return ( {props.text} ); }; interface IWrapperProps { style?: AmplifyThemeType; accessible?: boolean; onPress?: Function; } export const Wrapper: FC = (props) => { const isWeb = Platform.OS === 'web'; const WrapperComponent: React.ElementType = isWeb ? View : TouchableWithoutFeedback; const wrapperProps: IWrapperProps = { style: AmplifyTheme.section, accessible: false, }; if (!isWeb) { wrapperProps.onPress = Keyboard.dismiss; } return {props.children}; }; export const SignedOutMessage = (props) => { const theme = props.theme || AmplifyTheme; const message = props.signedOutMessage || I18n.get('Please Sign In / Sign Up'); return ( {message} ); };