forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

textarea.tsx32 lines, 1.3 KiBHistoryRawDownload
1import type { ComponentProps } from "solid-js";
2import { Show, splitProps } from "solid-js";
3import { cn } from "@/lib/cn";
4
5export type TextareaProps = ComponentProps<"textarea"> & {
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
13export function Textarea(props: TextareaProps) {
14 const [local, rest] = splitProps(props, ["class", "error"]);
15 const errorId = () => (props.id ? `${props.id}-error` : undefined);
16 return (
17 <>
18 <textarea
19 class={cn(
20 "flex min-h-15 w-full rounded-md border border-input bg-background/90 px-3 py-2 text-base shadow-sm transition-all placeholder:text-muted-foreground/80 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:opacity-50 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}