import { FC } from 'react'; import { Container, Row, StyleSystemThemedProps, TextInput } from 'components/layout'; import { GestureResponderEvent, Platform, TextInputProps } from 'react-native'; import styled from '@emotion/native'; import { variant } from 'styled-system'; import { ColorName, TextStyle, ViewStyle } from '@emotion/react'; import { Visible } from 'components/visible'; import { Fab } from 'components/fab'; import { useTheme } from 'hooks/theme'; import { COLOR_VALUES } from 'theme/color'; import { Card } from 'components/card'; import { Text } from 'components/text/Text'; import { Avatar } from 'components/avatar'; import { TouchableTile } from 'components/touchable-tile'; const variants: Record = { outline: { borderWidth: 1, }, plain: { borderWidth: 0, }, float: { borderWidth: 1, }, }; const shapeVariants: Record = { round: { borderRadius: 5, }, square: { borderRadius: 0, }, }; const colorVariants: Record = { primary: { borderColor: 'primary', }, secondary: { borderColor: 'secondary', }, base: { borderColor: 'base', }, 'base-01': { borderColor: 'base-01', }, 'base-02': { borderColor: 'base-02', }, body: { borderColor: 'body', }, transparent: { borderColor: 'transparent', }, }; const backgroundVariants: Record = { primary: { backgroundColor: 'primary', }, secondary: { backgroundColor: 'secondary', }, base: { backgroundColor: 'base', }, 'base-01': { backgroundColor: 'base-01', }, 'base-02': { backgroundColor: 'base-02', }, body: { backgroundColor: 'body', }, transparent: { backgroundColor: 'transparent', }, }; export const sizeVariants: Record = { 'extra-small': { height: 25, fontSize: 14, }, small: { height: 32, fontSize: 14, }, medium: { px: 'xs', height: 35, fontSize: 14, }, large: { px: 's', height: 40, fontSize: 15, }, 'extra-large': { px: 'm', height: 45, }, content: { px: 'xs', height: undefined, }, }; const TextFieldLocal = styled(TextInput)( variant({ prop: 'sizeVariant', variants: sizeVariants, }) ); const TextFieldWrapper = styled(Container)( variant({ variants, }), variant({ prop: 'colorVariant', variants: colorVariants, }), variant({ prop: 'shapeVariant', variants: shapeVariants, }), variant({ prop: 'backgroundVariant', variants: backgroundVariants, }) ); const localFieldStyle = Platform.select({ web: { outline: 'none', }, }); export const TextField: FC = ({ leftElement, leftOnPress, rightOnPress, sizeVariant, isAutoComplete, colorVariant = 'body', shapeVariant, rightElement, refs, labelColorVariant = 'caption', captionColorVariant = 'secondary', caption, label, ...props }) => { const { activeThemeMode } = useTheme(); const textColor = activeThemeMode === 'dark' ? COLOR_VALUES.dark['grey-08'] : COLOR_VALUES.light['grey-08']; const placeholderColor = COLOR_VALUES.light['grey-04']; const pl = leftElement ? undefined : 'xs'; const pr = rightElement ? undefined : 'xs'; return ( <> {label} {/* TODO: directly render leftElement and leftElement child */} {}} leftElement={ sufi@gmail.com } /> {caption} ); }; export type TextFieldVariants = 'plain' | 'outline' | 'float'; export type TextFieldShapeVariants = 'round' | 'square'; export type TextFieldSizeVariants = | 'extra-small' | 'small' | 'medium' | 'large' | 'extra-large' | 'content'; export type TextFieldColorVariants = | 'primary' | 'secondary' | 'base' | 'base-01' | 'base-02' | 'body' | 'transparent'; export type TextFieldWrapperType = StyleSystemThemedProps & TextFieldProps; export type TextFieldType = StyleSystemThemedProps & TextFieldProps & TextInputProps; export interface TextFieldProps { isAutoComplete?: boolean; leftElement?: JSX.Element; rightElement?: JSX.Element; shapeVariant?: TextFieldShapeVariants; colorVariant?: TextFieldColorVariants; backgroundVariant?: TextFieldColorVariants; variant: TextFieldVariants; leftOnPress?: ((event: GestureResponderEvent) => void) | undefined; rightOnPress?: ((event: GestureResponderEvent) => void) | undefined; refs?: any; caption?: string; label?: string; labelColorVariant?: ColorName; captionColorVariant?: ColorName; sizeVariant: TextFieldSizeVariants; }