hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import type { ComponentProps } from "solid-js"; |
| 2 | import { Show, splitProps } from "solid-js"; |
| 3 | import { cn } from "@/lib/cn"; |
| 4 | |
| 5 | export type InputProps = ComponentProps<"input"> & { |
| 6 | /** |
| 7 | * Message shown under the field. Marks it invalid and describes it for |
| 8 | * assistive tech; needs an `id` so the message can be linked. |
| 9 | */ |
| 10 | error?: string; |
| 11 | }; |
| 12 | |
| 13 | export function Input(props: InputProps) { |
| 14 | const [local, rest] = splitProps(props, ["class", "error"]); |
| 15 | const errorId = () => (props.id ? `${props.id}-error` : undefined); |
| 16 | return ( |
| 17 | <> |
| 18 | <input |
| 19 | class={cn( |
| 20 | "flex h-9 w-full rounded-md border border-input bg-surface-base px-3 py-1 text-base shadow-sm transition-all file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-text-placeholder hover:border-ring/45 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive aria-invalid:ring-destructive disabled:cursor-not-allowed disabled:bg-surface-tint disabled:text-muted-foreground disabled:opacity-70 md:text-sm", |
| 21 | local.class, |
| 22 | )} |
| 23 | aria-invalid={local.error ? true : undefined} |
| 24 | aria-describedby={local.error ? errorId() : undefined} |
| 25 | {...rest} |
| 26 | /> |
| 27 | <Show when={local.error}> |
| 28 | <p id={errorId()} class="text-xs font-medium text-destructive-text">{local.error}</p> |
| 29 | </Show> |
| 30 | </> |
| 31 | ); |
| 32 | } |