Skip to content

Commit 4ef4fc1

Browse files
committed
feat: Add TextArea form Component
1 parent 4ada53c commit 4ef4fc1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { forwardRef, ElementRef } from 'react'
2+
import { TextInput as BaseTextInput } from '@green-stack/forms/TextInput.primitives'
3+
import { cn } from '../components/styled'
4+
import { z, PropsOf } from '@green-stack/schemas'
5+
import { TextInputProps } from './TextInput.styled'
6+
7+
/* --- Props ----------------------------------------------------------------------------------- */
8+
9+
export const TextAreaProps = TextInputProps.extendSchema('TextAreaProps', {
10+
multiline: z.boolean().default(true),
11+
numberOfLines: z.number().optional(),
12+
textAlign: z.enum(['left', 'center', 'right']).default('left'),
13+
textAlignVertical: z.enum(['top', 'center', 'bottom']).default('top'),
14+
})
15+
16+
export type TextAreaProps = PropsOf<typeof BaseTextInput, typeof TextAreaProps>
17+
18+
/* --- <TextArea/> ----------------------------------------------------------------------------- */
19+
20+
export const TextArea = forwardRef<
21+
ElementRef<typeof BaseTextInput>,
22+
TextAreaProps
23+
>((rawProps, ref) => {
24+
// Props
25+
const props = TextAreaProps.applyDefaults(rawProps)
26+
27+
// -- Render --
28+
29+
return (
30+
<BaseTextInput
31+
ref={ref}
32+
{...props}
33+
placeholderClassName={cn(
34+
'text-muted',
35+
props.placeholderClassName,
36+
)}
37+
className={cn(
38+
'min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base text-foreground',
39+
'web:flex web:focus-visible:outline-none web:focus-visible:ring-2 web:focus-visible:ring-ring web:focus-visible:ring-offset-2 web:ring-offset-background',
40+
'native:text-lg native:leading-[1.25]',
41+
'lg:text-sm',
42+
'placeholder:text-muted',
43+
props.editable === false && 'opacity-50 web:cursor-not-allowed',
44+
props.className,
45+
)}
46+
/>
47+
)
48+
})

0 commit comments

Comments
 (0)