-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
621dbd3
commit ff27400
Showing
3 changed files
with
77 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,89 @@ | ||
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<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'size'>, | ||
FieldProps, | ||
VariantProps<typeof textareaVariants> { | ||
name: string | ||
controls?: ReactNode | ||
value?: string | ||
rows?: number | ||
resize?: boolean | ||
} | ||
|
||
export const TextArea: PolymorphicComponent<TextAreaProps, 'textarea'> = | ||
forwardRef( | ||
<T extends ElementType>( | ||
props: PolymorphicProps<TextAreaProps, T>, | ||
ref: PolymorphicRef<T> | ||
) => { | ||
const { | ||
as = 'textarea', | ||
autoComplete = 'off', | ||
borderRadius = 'md', | ||
description, | ||
disabled = false, | ||
id, | ||
label = '', | ||
labelLocation = 'hidden', | ||
name, | ||
rows, | ||
resize = false, | ||
...rest | ||
} = props | ||
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>( | ||
(props, ref) => { | ||
const { | ||
autoComplete = 'off', | ||
borderRadius = 'md', | ||
description, | ||
disabled = false, | ||
id, | ||
label = '', | ||
labelLocation = 'hidden', | ||
name, | ||
rows, | ||
resize = false, | ||
className, | ||
...rest | ||
} = props | ||
|
||
return ( | ||
<Field | ||
description={description} | ||
return ( | ||
<Field | ||
description={description} | ||
disabled={disabled} | ||
id={id ?? name} | ||
label={label} | ||
labelLocation={labelLocation} | ||
className="grid" | ||
> | ||
<textarea | ||
autoComplete={autoComplete} | ||
spellCheck="false" | ||
className={cn(textareaVariants({ borderRadius, resize }), className)} | ||
disabled={disabled} | ||
display="grid" | ||
id={id ?? name} | ||
label={label} | ||
labelLocation={labelLocation} | ||
> | ||
<Box | ||
as={as} | ||
autoComplete={autoComplete} | ||
spellCheck="false" | ||
className={clsx(styles.textarea, resize && styles.resize)} | ||
disabled={disabled} | ||
id={id ?? name} | ||
name={name} | ||
ref={ref} | ||
rows={rows} | ||
borderRadius={borderRadius} | ||
{...rest} | ||
/> | ||
</Field> | ||
) | ||
} | ||
) | ||
name={name} | ||
ref={ref} | ||
rows={rows} | ||
{...rest} | ||
/> | ||
</Field> | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters