Files
fn_registry/frontend/functions/ui/form_field.tsx
T
egutierrez 2d108c295a refactor: migrate frontend from shadcn/Tailwind to Mantine v9
Reescribe todos los componentes UI para usar Mantine v9 en lugar de shadcn/Tailwind.
Elimina cn(), CVA, components.json, theme_provider custom y globals.css con Tailwind.
Añade 25+ componentes nuevos (AppShell, AuthForm, DatePickerInput, Dropzone, etc.)
y MantineProvider como wrapper estándar del sistema de temas.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 23:46:44 +02:00

56 lines
1.4 KiB
TypeScript

import * as React from 'react'
import { Box, Text } from '@mantine/core'
interface FormFieldProps {
label?: string
helperText?: string
error?: string
children: React.ReactNode
className?: string
}
function FormField({ label, helperText, error, children, className }: FormFieldProps) {
const id = React.useId()
const inputId = `${id}-input`
const helperId = `${id}-helper`
const errorId = `${id}-error`
const describedBy = [helperText ? helperId : null, error ? errorId : null].filter(Boolean).join(' ') || undefined
const childWithProps = React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
return React.cloneElement(child as React.ReactElement<Record<string, unknown>>, {
id: inputId,
'aria-invalid': error ? true : undefined,
'aria-describedby': describedBy,
error: error || undefined,
})
}
return child
})
return (
<Box className={className}>
{label && (
<Text component="label" htmlFor={inputId} size="sm" fw={500} mb={4} display="block">
{label}
</Text>
)}
{childWithProps}
{helperText && !error && (
<Text id={helperId} size="sm" c="dimmed" mt={4}>
{helperText}
</Text>
)}
{error && (
<Text id={errorId} size="sm" c="red" mt={4}>
{error}
</Text>
)}
</Box>
)
}
export { FormField }
export type { FormFieldProps }