{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-text-area",
  "type": "registry:ui",
  "title": "react-tw/text-area.tsx",
  "description": "Carbon `TextArea` as a React + Tailwind component: the look of `<ui-text-area>` — 11px / 16px Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "class-variance-authority@0.7.1",
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-field",
    "@kanok-ui/tw-field",
    "@kanok-ui/tw-skeleton",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/text-area.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/text-area.tsx",
      "content": "import type { ChangeEvent, ComponentProps, ReactNode } from 'react';\nimport type { CounterMode } from '../core/field.ts';\nimport { TextArea as TextAreaPrimitive } from '@purpurabog/ui/headless';\nimport { cva } from 'class-variance-authority';\nimport { FieldCounter, FieldLabel, FieldMessageLine, StatusIcon, fluidBoxClasses, fluidControlClasses, useFluid, useTextField, useFieldDisabled, fieldBoxClasses, fieldStateEdges, fieldInvalidRing, fieldTextSize } from './field.tsx';\nimport { cn } from './lib/utils.ts';\nimport { FieldSkeleton, type FieldSkeletonProps } from './skeleton.tsx';\n\n/**\n * Carbon `TextArea` as a React + Tailwind component: the look of `<ui-text-area>` — 11px / 16px\n * padding, 20px lines, vertical resize, the status icon in the top-right corner, a soft\n * `maxCount` counter. Validation is the app's: `invalid` + `invalidText`. `fluid` (or a `FluidForm`\n * around it) is Carbon `FluidTextArea`: the label inside the box, the text starting 32px down.\n * `counterMode=\"word\"` counts words (Thai whole, by the browser's segmenter), still a soft limit;\n * `autoGrow` (no Carbon counterpart) sizes it to the text from `rows` up to `maxRows`, as `<ui-text-area>`.\n * The text area's behaviour (auto-grow) is the headless TextArea; the counter and messages are the shared field's.\n */\nexport const textAreaVariants = cva(\n    [\n        'box-border m-0 block min-h-10 w-full min-w-40 px-4 py-[11px]',\n        fieldBoxClasses,\n        'text-ink type-body-sm leading-5! resize-y',\n        fieldTextSize,\n        'outline-[length:var(--ui-field-focus-width,2px)] [outline-offset:calc(-1*var(--ui-field-focus-width,2px))] outline-transparent transition-[background-color,outline-color] duration-(--ui-duration-fast) ease-carbon',\n        'placeholder:text-ink-placeholder placeholder:opacity-100 focus:outline-focus focus:[box-shadow:var(--ui-field-focus-halo,none)]',\n        'disabled:cursor-not-allowed disabled:resize-none disabled:text-ink-disabled disabled:placeholder:text-ink-disabled',\n        'read-only:not-disabled:bg-[var(--ui-field-readonly-background,transparent)]',\n        fieldStateEdges,\n        'forced-colors:border forced-colors:border-[FieldText] forced-colors:focus:outline-[Highlight]',\n    ],\n    {\n        variants: {\n            invalid: { true: fieldInvalidRing, false: '' },\n            /** Room for the status icon so text doesn't run under it. */\n            status: { true: 'pe-12', false: '' },\n        },\n        defaultVariants: { invalid: false, status: false },\n    },\n);\n\nexport interface TextAreaProps extends ComponentProps<'textarea'> {\n    label: ReactNode;\n    hideLabel?: boolean;\n    helperText?: ReactNode;\n    invalid?: boolean;\n    invalidText?: ReactNode;\n    warn?: boolean;\n    warnText?: ReactNode;\n    /** Soft limit with a visible counter: typing past it isn't blocked, it becomes an error. */\n    maxCount?: number;\n    /** What `maxCount` counts: `character` (default) or `word` (Carbon `counterMode`). */\n    counterMode?: CounterMode;\n    /** Grows with the text from `rows` (no Carbon counterpart); `maxRows` caps it, then it scrolls. */\n    autoGrow?: boolean;\n    /** The most lines `autoGrow` shows before scrolling (default: no cap). */\n    maxRows?: number;\n    tooLongText?: string;\n    nearLimitText?: string;\n    lang?: string;\n    /** Carbon `FluidTextArea` (also set by `FluidForm`). */\n    fluid?: boolean;\n}\n\nexport function TextArea({ label, hideLabel, helperText, invalid, invalidText, warn, warnText, maxCount, counterMode, autoGrow = false, maxRows, tooLongText, nearLimitText, lang, fluid: fluidProp, className, id, rows = 4, value, defaultValue, onChange, disabled: ownDisabled, readOnly, ref, ...rest }: Readonly<TextAreaProps>) {\n    const disabled = useFieldDisabled(ownDisabled);\n    const field = useTextField({ id, value, defaultValue, maxCount, counterMode, tooLongText, nearLimitText, invalid, invalidText, warn, warnText, helperText, disabled, readOnly, lang });\n    const { message } = field;\n    const fluid = useFluid(fluidProp);\n    const status = message?.kind === 'helper' ? undefined : message?.kind;\n    return (\n        <TextAreaPrimitive.Root value={value} defaultValue={defaultValue}>\n            <div className={cn('block font-sans', fluid && fluidBoxClasses(status, readOnly), className)}>\n                <div className={fluid ? 'contents' : 'flex justify-between gap-2'}>\n                    <FieldLabel htmlFor={field.id} hidden={hideLabel} disabled={disabled} fluid={fluid}>\n                        {label}\n                    </FieldLabel>\n                    <FieldCounter length={field.length} max={maxCount} over={field.count.over} announcement={field.announcement} fluid={fluid} />\n                </div>\n                <div className=\"relative\">\n                    <TextAreaPrimitive.Input\n                        {...rest}\n                        ref={ref}\n                        autoGrow={autoGrow}\n                        maxRows={maxRows}\n                        id={field.id}\n                        rows={rows}\n                        disabled={disabled}\n                        readOnly={readOnly}\n                        aria-invalid={field.showError}\n                        aria-describedby={field.messageId}\n                        className={cn(\n                            textAreaVariants({ invalid: field.showError, status: !!status }),\n                            autoGrow && 'resize-none',\n                            // fluid: the text starts 32px down, under the label; the status icon moves to the message row\n                            fluid && cn('mt-8 pt-0 pb-[13px]', status && 'pe-4', fluidControlClasses(status)),\n                        )}\n                        onChange={(event: ChangeEvent<HTMLTextAreaElement>) => {\n                            field.onTyped(event.target.value);\n                            onChange?.(event);\n                        }}\n                    />\n                    {/* Carbon: the icon sits in the top-right corner, not vertically centred */}\n                    <span className={cn('pointer-events-none absolute end-4 top-2 flex', fluid && 'inset-y-0 end-0')}>\n                        <StatusIcon kind={message?.kind} className={fluid ? 'absolute end-4 top-[calc(100%+8px)]' : undefined} />\n                    </span>\n                </div>\n                <FieldMessageLine id={`${field.id}-message`} message={message} content={field.messageContent} disabled={disabled} fluid={fluid} />\n            </div>\n        </TextAreaPrimitive.Root>\n    );\n}\n\n/**\n * Carbon `TextAreaSkeleton`: a label bar, 8px, a 100px field bar. `fluid` (Carbon `FluidTextAreaSkeleton`): a box padded\n * 16px in skeleton-background with a 1px line below — a 75×8 label bar, 12px, an 80% × 64px bar. Hidden from assistive tech.\n */\nexport function TextAreaSkeleton({ fluid: fluidProp, className, ...props }: Readonly<Omit<FieldSkeletonProps, 'size'>>) {\n    const fluid = useFluid(fluidProp);\n    if (!fluid) return <FieldSkeleton {...props} className={className} height=\"h-[100px]\" />;\n    return (\n        <div {...props} aria-hidden=\"true\" className={cn('block', className)}>\n            <div className=\"box-border border-0 border-b border-solid border-skeleton-element bg-skeleton-background p-4\">\n                <span className=\"skeleton mb-3 block h-2 w-[75px]\" />\n                <div className=\"skeleton block h-16 w-4/5\" />\n            </div>\n        </div>\n    );\n}\n"
    }
  ]
}
