--- import type { HTMLAttributes } from "astro/types"; import { cn } from "../utils/cn"; import { Icon } from "astro-icon/components"; interface Rules { lower?: boolean; upper?: boolean; number?: boolean; symbol?: boolean; minLength?: number; // default 8 } interface Props extends HTMLAttributes<"div"> { id?: string; name: string; // required (used by form validator) label?: string; description?: string; placeholder?: string; required?: boolean; disabled?: boolean; value?: string; size?: "sm" | "md" | "lg"; class?: string; showMeter?: boolean; // default true showChecklist?: boolean; // default true rules?: Rules; // enable/disable rules + custom minLength error?: string; // SSR error (form client will overwrite) } const p = Astro.props as Props; const fieldId = p.id ?? p.name; const descId = p.description ? `${fieldId}-desc` : undefined; const errId = `${fieldId}-err`; const sizeKls = p.size === "sm" ? "wr:h-10 wr:px-3 wr:text-sm" : p.size === "lg" ? "wr:h-12 wr:px-4 wr:text-base" : "wr:h-11 wr:px-3 wr:text-sm"; const inputCls = cn( "wr:py-2.5 wr:sm:py-3 wr:px-4 wr:block wr:w-full wr:border-border wr:rounded-lg wr:sm:text-sm wr:focus:border-border wr:focus:ring-blue-500 wr:disabled:opacity-50 wr:disabled:pointer-events-none wr:dark:bg-input wr:dark:border-border wr:dark:text-neutral-400 wr:dark:placeholder-neutral-500 wr:dark:focus:ring-neutral-600", sizeKls, "wr:pr-10", // space for eye button p.error && "wr:border-danger wr:focus-visible:ring-danger/40", ); const containerId = `pf-${Math.random().toString(36).slice(2)}`; const rules = { lower: true, upper: true, number: true, symbol: true, minLength: 8, ...(p.rules ?? {}), }; const showMeter = p.showMeter ?? true; const showChecklist = p.showChecklist ?? true; ---
{ p.label && ( ) }
{ showMeter && (
) } { showChecklist && ( ) } { p.description && (

{p.description}

) }