import { FormField } from '@oryd/kratos-client' import React from 'react' import { Keyboard, TextInputProps, View } from 'react-native' import { getTitle } from '../../translations' import StyledTextInput from '../Styled/StyledTextInput' import styled from 'styled-components/native' import { textInputSubtitleStyles, textInputTitleStyles } from '@oryd/themes' interface FieldProps { field: FormField onChange: (value: any) => void value: any disabled?: boolean fieldTypeOverride?: ( field: FormField, props: TextInputProps ) => TextInputProps } const guessVariant = (field: FormField) => { if (field.name === 'identifier') { return 'username' } switch (field.type) { case 'hidden': return null case 'email': return 'email' case 'submit': return null case 'password': return 'password' default: return 'text' } } const Title = styled.Text(textInputTitleStyles) const Subtitle = styled.Text(textInputSubtitleStyles) const typeToState = ({ type, disabled }: { type?: string disabled?: boolean }) => { if (disabled) { return 'disabled' } switch (type) { case 'error': return 'error' } return undefined } export default ({ field, value, onChange, disabled, fieldTypeOverride }: FieldProps) => { const variant = guessVariant(field) if (!variant) { return null } let extraProps: TextInputProps = {} switch (variant) { case 'email': extraProps.autoCompleteType = 'email' extraProps.keyboardType = 'email-address' extraProps.textContentType = 'emailAddress' extraProps.autoCapitalize = 'none' extraProps.autoCorrect = false break case 'password': extraProps.autoCompleteType = 'password' extraProps.textContentType = 'password' extraProps.autoCapitalize = 'none' extraProps.secureTextEntry = true extraProps.autoCorrect = false break case 'username': extraProps.autoCompleteType = 'username' extraProps.textContentType = 'username' extraProps.autoCapitalize = 'none' extraProps.autoCorrect = false break } if (fieldTypeOverride) { extraProps = fieldTypeOverride(field, extraProps) } return ( {getTitle(field.name)} <> {field.messages?.map(({ text, id, type }, k) => ( {text} ))} ) }