'use client'; import { Text, View } from 'react-native'; import React from 'react'; import { createFormControl } from '@gluestack-ui/core/form-control/creator'; import { tva } from '@gluestack-ui/utils/nativewind-utils'; import { withStyleContext } from '@gluestack-ui/utils/nativewind-utils'; import { styled } from 'nativewind'; import type { VariantProps } from '@gluestack-ui/utils/nativewind-utils'; import { UIIcon } from '@gluestack-ui/core/icon/creator'; const SCOPE = 'FORM_CONTROL'; const formControlStyle = tva({ base: 'flex flex-col', }); const formControlErrorIconStyle = tva({ base: 'text-destructive fill-none h-[18px] w-[18px]', }); const formControlErrorStyle = tva({ base: 'flex flex-row justify-start items-center mt-1 gap-1', }); const formControlErrorTextStyle = tva({ base: 'text-destructive text-xs font-body', variants: { isTruncated: { true: 'web:truncate', }, bold: { true: 'font-bold', }, underline: { true: 'underline', }, strikeThrough: { true: 'line-through', }, sub: { true: 'text-xs', }, italic: { true: 'italic', }, highlight: { true: 'bg-yellow-500', }, }, }); const formControlHelperStyle = tva({ base: 'flex flex-row justify-start items-center mt-1 font-body', }); const formControlHelperTextStyle = tva({ base: 'text-foreground/70 font-body text-sm', variants: { isTruncated: { true: 'web:truncate', }, bold: { true: 'font-bold', }, underline: { true: 'underline', }, strikeThrough: { true: 'line-through', }, sub: { true: 'text-xs', }, italic: { true: 'italic', }, highlight: { true: 'bg-yellow-500', }, }, }); const formControlLabelStyle = tva({ base: 'flex flex-row justify-start items-center mb-1', }); const formControlLabelTextStyle = tva({ base: 'font-medium text-foreground text-base font-body', variants: { isTruncated: { true: 'web:truncate', }, bold: { true: 'font-bold', }, underline: { true: 'underline', }, strikeThrough: { true: 'line-through', }, sub: { true: 'text-xs', }, italic: { true: 'italic', }, highlight: { true: 'bg-yellow-500', }, }, }); const formControlLabelAstrickStyle = tva({ base: 'font-medium text-foreground text-base', variants: { isTruncated: { true: 'web:truncate', }, bold: { true: 'font-bold', }, underline: { true: 'underline', }, strikeThrough: { true: 'line-through', }, sub: { true: 'text-xs', }, italic: { true: 'italic', }, highlight: { true: 'bg-yellow-500', }, }, }); type IFormControlLabelAstrickProps = React.ComponentPropsWithoutRef< typeof Text > & VariantProps; const FormControlLabelAstrick = React.forwardRef< React.ComponentRef, IFormControlLabelAstrickProps >(function FormControlLabelAstrick({ className, ...props }, ref) { return ( ); }); const StyledUIIcon = styled(UIIcon, { className: "style" }); export const UIFormControl = createFormControl({ Root: withStyleContext(View, SCOPE), Error: View, ErrorText: Text, ErrorIcon: StyledUIIcon, Label: View, LabelText: Text, LabelAstrick: FormControlLabelAstrick, Helper: View, HelperText: Text, }); type IFormControlProps = React.ComponentProps & VariantProps; const FormControl = React.forwardRef< React.ComponentRef, IFormControlProps >(function FormControl({ className, ...props }, ref) { return ( ); }); type IFormControlErrorProps = React.ComponentProps & VariantProps; const FormControlError = React.forwardRef< React.ComponentRef, IFormControlErrorProps >(function FormControlError({ className, ...props }, ref) { return ( ); }); type IFormControlErrorTextProps = React.ComponentProps< typeof UIFormControl.Error.Text > & VariantProps; const FormControlErrorText = React.forwardRef< React.ComponentRef, IFormControlErrorTextProps >(function FormControlErrorText({ className, ...props }, ref) { return ( ); }); type IFormControlErrorIconProps = React.ComponentProps< typeof UIFormControl.Error.Icon > & VariantProps; const FormControlErrorIcon = React.forwardRef< React.ComponentRef, IFormControlErrorIconProps >(function FormControlErrorIcon({ className, ...props }, ref) { return ( ); }); type IFormControlLabelProps = React.ComponentProps & VariantProps & { htmlFor?: string; role?: string; }; const FormControlLabel = React.forwardRef< React.ComponentRef, IFormControlLabelProps >(function FormControlLabel({ className, ...props }, ref) { return ( ); }); type IFormControlLabelTextProps = React.ComponentProps< typeof UIFormControl.Label.Text > & VariantProps; const FormControlLabelText = React.forwardRef< React.ComponentRef, IFormControlLabelTextProps >(function FormControlLabelText({ className, ...props }, ref) { return ( ); }); type IFormControlHelperProps = React.ComponentProps< typeof UIFormControl.Helper > & VariantProps; const FormControlHelper = React.forwardRef< React.ComponentRef, IFormControlHelperProps >(function FormControlHelper({ className, ...props }, ref) { return ( ); }); type IFormControlHelperTextProps = React.ComponentProps< typeof UIFormControl.Helper.Text > & VariantProps; const FormControlHelperText = React.forwardRef< React.ComponentRef, IFormControlHelperTextProps >(function FormControlHelperText({ className, ...props }, ref) { return ( ); }); FormControl.displayName = 'FormControl'; FormControlError.displayName = 'FormControlError'; FormControlErrorText.displayName = 'FormControlErrorText'; FormControlErrorIcon.displayName = 'FormControlErrorIcon'; FormControlLabel.displayName = 'FormControlLabel'; FormControlLabelText.displayName = 'FormControlLabelText'; FormControlLabelAstrick.displayName = 'FormControlLabelAstrick'; FormControlHelper.displayName = 'FormControlHelper'; FormControlHelperText.displayName = 'FormControlHelperText'; export { FormControl, FormControlError, FormControlErrorText, FormControlErrorIcon, FormControlLabel, FormControlLabelText, FormControlLabelAstrick, FormControlHelper, FormControlHelperText, };