| 1 | "use client"; |
| 2 | |
| 3 | import { Field as FieldPrimitive } from "@base-ui/react/field"; |
| 4 | import { mergeProps } from "@base-ui/react/merge-props"; |
| 5 | import type * as React from "react"; |
| 6 | |
| 7 | import { cn } from "~/lib/utils"; |
| 8 | |
| 9 | type TextareaProps = React.ComponentProps<"textarea"> & { |
| 10 | size?: "sm" | "default" | "lg" | number; |
| 11 | unstyled?: boolean; |
| 12 | }; |
| 13 | |
| 14 | function Textarea({ className, size = "default", unstyled = false, ...props }: TextareaProps) { |
| 15 | return ( |
| 16 | <span |
| 17 | className={ |
| 18 | cn( |
| 19 | !unstyled && |
| 20 | "relative inline-flex w-full rounded-lg border border-input bg-background not-dark:bg-clip-padding text-base text-foreground shadow-xs/5 ring-ring/24 transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] has-focus-visible:has-aria-invalid:border-destructive/64 has-focus-visible:has-aria-invalid:ring-destructive/16 has-aria-invalid:border-destructive/36 has-focus-visible:border-ring has-disabled:opacity-64 has-[:disabled,:focus-visible,[aria-invalid]]:shadow-none has-focus-visible:ring-[3px] has-focus-visible:ring-inset not-has-disabled:has-not-focus-visible:not-has-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] sm:text-sm dark:bg-input/32 dark:has-aria-invalid:ring-destructive/24 dark:not-has-disabled:has-not-focus-visible:not-has-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)]", |
| 21 | className, |
| 22 | ) || undefined |
| 23 | } |
| 24 | data-size={size} |
| 25 | data-slot="textarea-control" |
| 26 | > |
| 27 | <FieldPrimitive.Control |
| 28 | render={(defaultProps) => ( |
| 29 | <textarea |
| 30 | className={cn( |
| 31 | // Auto-grows with content up to one cap, then scrolls. |
| 32 | "field-sizing-content min-h-17.5 max-h-64 w-full rounded-[inherit] px-[calc(--spacing(3)-1px)] py-[calc(--spacing(1.5)-1px)] outline-none wrap-anywhere max-sm:min-h-20.5", |
| 33 | size === "sm" && |
| 34 | "min-h-16.5 px-[calc(--spacing(2.5)-1px)] py-[calc(--spacing(1)-1px)] max-sm:min-h-19.5", |
| 35 | size === "lg" && "min-h-18.5 py-[calc(--spacing(2)-1px)] max-sm:min-h-21.5", |
| 36 | )} |
| 37 | data-slot="textarea" |
| 38 | {...mergeProps(defaultProps, props)} |
| 39 | /> |
| 40 | )} |
| 41 | /> |
| 42 | </span> |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | export { Textarea, type TextareaProps }; |