| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import type {ForwardedRef, ReactNode} from 'react'; |
| 9 | |
| 10 | import * as stylex from '@stylexjs/stylex'; |
| 11 | import {forwardRef, useId} from 'react'; |
| 12 | import {Column} from './Flex'; |
| 13 | |
| 14 | const styles = stylex.create({ |
| 15 | root: { |
| 16 | gap: '2px', |
| 17 | }, |
| 18 | label: { |
| 19 | marginBlock: '0px', |
| 20 | }, |
| 21 | textarea: { |
| 22 | fontFamily: 'var(--font-family)', |
| 23 | boxSizing: 'border-box', |
| 24 | padding: '8px', |
| 25 | minWidth: '100px', |
| 26 | minHeight: '42px', |
| 27 | width: '100%', |
| 28 | background: 'var(--input-background)', |
| 29 | color: 'var(--input-foreground)', |
| 30 | border: '1px solid var(--dropdown-border)', |
| 31 | outline: { |
| 32 | default: 'none', |
| 33 | ':focus-visible': '1px solid var(--focus-border)', |
| 34 | }, |
| 35 | outlineOffset: '-1px', |
| 36 | }, |
| 37 | }); |
| 38 | |
| 39 | export type TextAreaProps = { |
| 40 | children?: ReactNode; |
| 41 | xstyle?: stylex.StyleXStyles; |
| 42 | containerXstyle?: stylex.StyleXStyles; |
| 43 | resize?: 'none' | 'vertical' | 'horizontal' | 'both'; |
| 44 | } & React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>; |
| 45 | |
| 46 | export const TextArea = forwardRef( |
| 47 | ( |
| 48 | {children, xstyle, containerXstyle, resize = 'none', ...rest}: TextAreaProps, |
| 49 | ref: ForwardedRef<HTMLTextAreaElement>, |
| 50 | ) => { |
| 51 | const id = useId(); |
| 52 | return ( |
| 53 | <Column xstyle={[styles.root, containerXstyle ?? null]} alignStart> |
| 54 | {children && ( |
| 55 | <label htmlFor={id} {...stylex.props(styles.label)}> |
| 56 | {children} |
| 57 | </label> |
| 58 | )} |
| 59 | <textarea |
| 60 | ref={ref} |
| 61 | style={{resize}} |
| 62 | {...stylex.props(styles.textarea, xstyle)} |
| 63 | id={id} |
| 64 | {...rest} |
| 65 | /> |
| 66 | </Column> |
| 67 | ); |
| 68 | }, |
| 69 | ); |
| 70 | |