From ff274009efa97b003e930fc336cd3af58fed8026 Mon Sep 17 00:00:00 2001 From: Corban Riley Date: Tue, 14 Jan 2025 17:53:29 -0500 Subject: [PATCH] TextArea converted to tailwind --- .../TextArea/ControlledTextArea.tsx | 4 +- src/components/TextArea/TextArea.tsx | 130 ++++++++++-------- .../TextInput/ControlledTextInput.tsx | 4 +- 3 files changed, 77 insertions(+), 61 deletions(-) diff --git a/src/components/TextArea/ControlledTextArea.tsx b/src/components/TextArea/ControlledTextArea.tsx index 5b36f3383..e3f1d6fea 100644 --- a/src/components/TextArea/ControlledTextArea.tsx +++ b/src/components/TextArea/ControlledTextArea.tsx @@ -1,10 +1,8 @@ import { Control, Controller } from 'react-hook-form' -import { PolymorphicProps } from '~/components/Box' - import { TextArea, TextAreaProps } from './TextArea' -type ControlledTextAreaProps = PolymorphicProps & { +type ControlledTextAreaProps = TextAreaProps & { control: Control defaultValue?: string name: string diff --git a/src/components/TextArea/TextArea.tsx b/src/components/TextArea/TextArea.tsx index 5312f1e8e..34a893a13 100644 --- a/src/components/TextArea/TextArea.tsx +++ b/src/components/TextArea/TextArea.tsx @@ -1,18 +1,44 @@ -import { clsx } from 'clsx' -import { ElementType, forwardRef, ReactNode } from 'react' +import { cva, VariantProps } from 'class-variance-authority' +import { forwardRef, ReactNode } from 'react' -import { - Box, - PolymorphicComponent, - PolymorphicProps, - PolymorphicRef, -} from '~/components/Box' import { Field, FieldProps } from '~/components/Field' +import { cn } from '~/utils' -import * as styles from './styles.css' +import { textVariants } from '../Text' -export type TextAreaProps = FieldProps & { - disabled?: boolean +const textareaVariants = cva( + [ + textVariants({ variant: 'normal' }), + 'block bg-transparent text-text-100 w-full p-4', + 'outline-none ring-inset ring-1 ring-border-normal', + 'cursor-text disabled:cursor-default disabled:opacity-50', + 'focus:opacity-100 focus:ring-2 focus:ring-border-focus', + 'placeholder-text-50', + 'resize-none', + ], + { + variants: { + borderRadius: { + xs: 'rounded', + sm: 'rounded-lg', + md: 'rounded-xl', + }, + resize: { + true: 'resize-y', + false: 'resize-none', + }, + }, + defaultVariants: { + borderRadius: 'md', + resize: false, + }, + } +) + +export interface TextAreaProps + extends Omit, 'size'>, + FieldProps, + VariantProps { name: string controls?: ReactNode value?: string @@ -20,50 +46,44 @@ export type TextAreaProps = FieldProps & { resize?: boolean } -export const TextArea: PolymorphicComponent = - forwardRef( - ( - props: PolymorphicProps, - ref: PolymorphicRef - ) => { - const { - as = 'textarea', - autoComplete = 'off', - borderRadius = 'md', - description, - disabled = false, - id, - label = '', - labelLocation = 'hidden', - name, - rows, - resize = false, - ...rest - } = props +export const TextArea = forwardRef( + (props, ref) => { + const { + autoComplete = 'off', + borderRadius = 'md', + description, + disabled = false, + id, + label = '', + labelLocation = 'hidden', + name, + rows, + resize = false, + className, + ...rest + } = props - return ( - +