import { useId, useState, type ChangeEvent, type InputHTMLAttributes, type ReactNode } from "react"; import { MagnifyingGlass, WarningCircle, X } from "@phosphor-icons/react"; import { cn } from "../../lib/cn"; export type FieldMeta = { error?: string; hint?: string; label?: string; prefixIcon?: ReactNode; suffixIcon?: ReactNode; suffixInteractive?: boolean; }; export type FormFieldProps = FieldMeta & { children: ReactNode; className?: string; }; export function fieldClassName(hasError?: boolean) { return cn( "h-[var(--uhuru-control-height)] rounded-[var(--uhuru-radius-control)] border border-[var(--uhuru-border-default)] bg-[var(--uhuru-surface-default)] px-[var(--uhuru-control-padding-x)] text-sm text-[var(--uhuru-text-primary)] outline-none transition placeholder:text-[var(--uhuru-text-tertiary)] focus:border-[var(--uhuru-border-accent)] focus:ring-1 focus:ring-[var(--uhuru-border-accent)]", hasError ? "border-[var(--uhuru-error-border)] focus:ring-[var(--uhuru-error-border)]" : "", ); } export function fieldNote(error?: string, hint?: string, hintId?: string, errorId?: string, onDismiss?: () => void) { if (error) { return ( ); } if (hint) { return ( {hint} ); } return null; } type PrefixFieldShellProps = { children: ReactNode; className?: string; prefixIcon?: ReactNode; suffixIcon?: ReactNode; suffixInteractive?: boolean; }; export function PrefixFieldShell({ children, className, prefixIcon, suffixIcon, suffixInteractive = false, }: PrefixFieldShellProps) { if (!prefixIcon && !suffixIcon) { return <>{children}; } return (
{prefixIcon ? ( {prefixIcon} ) : null} {children} {suffixIcon ? ( {suffixIcon} ) : null}
); } export function SearchGlyph() { return