/** * Copyright (c) Paymium. * * This source code is licensed under the MIT license found in the * LICENSE file in the root of this projects source tree. */ import { Pressable, View } from 'react-native'; import type { FormComponent, FormFieldComponent, FormControlComponent, FormLabelComponent, FormMessageComponent, FieldContext, } from './types'; import { cloneElement, createContext, isValidElement, useContext, useEffect, useId, useRef, useState, } from 'react'; import { Label } from '../Label'; import { YBox } from '../../layout/YBox'; import { isWeb } from '@crossed/styled'; const fieldContext = createContext({} as FieldContext); const Form: FormComponent = ({ onSubmit, asChild, children, ...props }) => { const propsTmp = { role: 'form', ...props } as const; return asChild && isValidElement(children) ? ( cloneElement(children, propsTmp) ) : ( {children} ); }; const FormField: FormFieldComponent = ({ name, ...props }) => { const [inputId, setInputId] = useState(); const controlRef = useRef(null); return ( ); }; const FormControl: FormControlComponent = ({ children }) => { const { setInputId } = useContext(fieldContext); const localId = useId(); const id = (children as any).props?.id || `form-control${localId}`; useEffect(() => { setInputId(id); }, [id, setInputId]); return isValidElement(children) ? cloneElement(children, { id, 'nativeID': id, 'data-describedby': `${id}:helper`, } as any) : children; }; const FormLabel: FormLabelComponent = (props) => { const { inputId, controlRef } = useContext(fieldContext); const render =