import { type ReactElement, useMemo } from "react"; import { cva, type VariantProps } from "class-variance-authority"; import { cn } from "@/lib/utils"; import { Label } from "@/components/ui/label"; import { Separator } from "@/components/ui/separator"; /** * Field — shadcn/WealthX * Base: npx shadcn\@latest add field * Figma: https://www.figma.com/design/9V9F0NGVsif8LGmEhVjOcT/Design-System---shadcn?node-id=1188-4205 * * WealthX additions: * - FieldDescription/FieldError: text-xs (12px) per Figma helper text spec * - FieldError.uniqueErrors: Array.from() instead of spread on Map iterator (es5 compat) */ export type FieldSetProps = React.ComponentProps<"fieldset">; function FieldSet({ className, ...props }: FieldSetProps): ReactElement { return (
[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3", className )} data-slot="field-set" {...props} /> ); } export type FieldLegendProps = React.ComponentProps<"legend"> & { variant?: "legend" | "label"; }; function FieldLegend({ className, variant = "legend", ...props }: FieldLegendProps): ReactElement { return ( ); } export type FieldGroupProps = React.ComponentProps<"div">; function FieldGroup({ className, ...props }: FieldGroupProps): ReactElement { return (
[data-slot=field-group]]:gap-4", className )} data-slot="field-group" {...props} /> ); } const fieldVariants = cva( "group/field flex w-full gap-3 data-[invalid=true]:text-destructive", { variants: { orientation: { vertical: ["flex-col [&>*]:w-full [&>.sr-only]:w-auto"], horizontal: [ "flex-row items-center", "[&>[data-slot=field-label]]:flex-auto", "has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px", ], responsive: [ "flex-col @md/field-group:flex-row @md/field-group:items-center [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto", "@md/field-group:[&>[data-slot=field-label]]:flex-auto", "@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px", ], }, }, defaultVariants: { orientation: "vertical", }, } ); export type FieldProps = React.ComponentProps<"div"> & VariantProps; function Field({ className, orientation = "vertical", ...props }: FieldProps): ReactElement { return (
); } export type FieldContentProps = React.ComponentProps<"div">; function FieldContent({ className, ...props }: FieldContentProps): ReactElement { return (
); } export type FieldLabelProps = React.ComponentProps; function FieldLabel({ className, ...props }: FieldLabelProps): ReactElement { return (