Spaces:
Sleeping
Sleeping
Download packages/ui/src/components/FormField.tsx from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 2.51 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/packages/ui/src/components/FormField.tsx
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/packages/ui/src/components/FormField.tsx
-
curl -L -o FormField.tsx https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/packages/ui/src/components/FormField.tsx
2.51 kB
| import React from "react"; | |
| import { cn } from "../lib/cn"; | |
| export interface FormFieldProps | |
| extends React.HTMLAttributes<HTMLDivElement> { | |
| /** Label text */ | |
| label?: string; | |
| /** Whether the field is required */ | |
| required?: boolean; | |
| /** Error message (boolean shows generic error, string shows custom message) */ | |
| error?: boolean | string; | |
| /** Helper text shown below the field */ | |
| helperText?: string; | |
| /** Whether to show the field as disabled */ | |
| disabled?: boolean; | |
| /** Children (typically an Input, Textarea, or Select) */ | |
| children: React.ReactNode; | |
| } | |
| export const FormField = React.forwardRef<HTMLDivElement, FormFieldProps>( | |
| ({ label, required = false, error, helperText, disabled, className, children, ...props }, ref) => { | |
| const hasError = !!error; | |
| const errorMessage = typeof error === "string" ? error : null; | |
| return ( | |
| <div | |
| ref={ref} | |
| className={cn("flex flex-col gap-[calc(var(--space-2)*0.5)] mb-[var(--space-4)]", className)} | |
| style={{ display: "flex", flexDirection: "column", gap: "4px", marginBottom: "var(--space-4)", ...props.style }} | |
| {...props} | |
| > | |
| {label && ( | |
| <label | |
| className="form-label" | |
| style={{ | |
| display: "inline-flex", | |
| alignItems: "center", | |
| gap: "4px", | |
| fontSize: "var(--text-xs)", | |
| fontWeight: 600, | |
| color: "var(--text-secondary)", | |
| letterSpacing: "0.02em", | |
| marginBottom: 0, | |
| }} | |
| > | |
| {label} | |
| {required && ( | |
| <span | |
| style={{ color: "var(--color-primary)" }} | |
| aria-hidden="true" | |
| > | |
| * | |
| </span> | |
| )} | |
| </label> | |
| )} | |
| {children} | |
| {errorMessage && ( | |
| <span | |
| className="form-error-text" | |
| style={{ | |
| fontSize: "0.75rem", | |
| color: "var(--color-error)", | |
| paddingLeft: "2px", | |
| }} | |
| > | |
| {errorMessage} | |
| </span> | |
| )} | |
| {!errorMessage && helperText && ( | |
| <span | |
| className="form-helper-text" | |
| style={{ | |
| fontSize: "0.75rem", | |
| color: "var(--text-tertiary)", | |
| paddingLeft: "2px", | |
| }} | |
| > | |
| {helperText} | |
| </span> | |
| )} | |
| </div> | |
| ); | |
| }, | |
| ); | |
| FormField.displayName = "FormField"; | |