addons/components/TextArea.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {ForwardedRef, ReactNode} from 'react';
b69ab319
b69ab3110import * as stylex from '@stylexjs/stylex';
b69ab3111import {forwardRef, useId} from 'react';
b69ab3112import {Column} from './Flex';
b69ab3113
b69ab3114const styles = stylex.create({
b69ab3115 root: {
b69ab3116 gap: '2px',
b69ab3117 },
b69ab3118 label: {
b69ab3119 marginBlock: '0px',
b69ab3120 },
b69ab3121 textarea: {
b69ab3122 fontFamily: 'var(--font-family)',
b69ab3123 boxSizing: 'border-box',
b69ab3124 padding: '8px',
b69ab3125 minWidth: '100px',
b69ab3126 minHeight: '42px',
b69ab3127 width: '100%',
b69ab3128 background: 'var(--input-background)',
b69ab3129 color: 'var(--input-foreground)',
b69ab3130 border: '1px solid var(--dropdown-border)',
b69ab3131 outline: {
b69ab3132 default: 'none',
b69ab3133 ':focus-visible': '1px solid var(--focus-border)',
b69ab3134 },
b69ab3135 outlineOffset: '-1px',
b69ab3136 },
b69ab3137});
b69ab3138
b69ab3139export type TextAreaProps = {
b69ab3140 children?: ReactNode;
b69ab3141 xstyle?: stylex.StyleXStyles;
b69ab3142 containerXstyle?: stylex.StyleXStyles;
b69ab3143 resize?: 'none' | 'vertical' | 'horizontal' | 'both';
b69ab3144} & React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>;
b69ab3145
b69ab3146export const TextArea = forwardRef(
b69ab3147 (
b69ab3148 {children, xstyle, containerXstyle, resize = 'none', ...rest}: TextAreaProps,
b69ab3149 ref: ForwardedRef<HTMLTextAreaElement>,
b69ab3150 ) => {
b69ab3151 const id = useId();
b69ab3152 return (
b69ab3153 <Column xstyle={[styles.root, containerXstyle ?? null]} alignStart>
b69ab3154 {children && (
b69ab3155 <label htmlFor={id} {...stylex.props(styles.label)}>
b69ab3156 {children}
b69ab3157 </label>
b69ab3158 )}
b69ab3159 <textarea
b69ab3160 ref={ref}
b69ab3161 style={{resize}}
b69ab3162 {...stylex.props(styles.textarea, xstyle)}
b69ab3163 id={id}
b69ab3164 {...rest}
b69ab3165 />
b69ab3166 </Column>
b69ab3167 );
b69ab3168 },
b69ab3169);