|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import * as React from 'react';
- import * as TextControlBase from '@tesseract-design/web-base-textcontrol';
-
- export type MultilineTextInputProps = Omit<React.HTMLProps<HTMLTextAreaElement>, 'size' | 'style'> & {
- /**
- * Short textual description indicating the nature of the component's value.
- */
- label?: React.ReactNode,
- /**
- * Short textual description as guidelines for valid input values.
- */
- hint?: React.ReactNode,
- /**
- * Size of the component.
- */
- size?: TextControlBase.TextControlSize,
- /**
- * Additional description, usually graphical, indicating the nature of the component's value.
- */
- indicator?: React.ReactNode,
- /**
- * Should the component display a border?
- */
- border?: boolean,
- /**
- * Should the component occupy the whole width of its parent?
- */
- block?: boolean,
- /**
- * Style of the component.
- */
- style?: TextControlBase.TextControlStyle,
- /**
- * Is the label hidden?
- */
- hiddenLabel?: boolean,
- }
-
- /**
- * Component for inputting textual values.
- *
- * This component supports multiline input and adjusts its layout accordingly.
- */
- export const MultilineTextInput = React.forwardRef<HTMLTextAreaElement, MultilineTextInputProps>(
- (
- {
- label = '',
- hint = '',
- indicator = null,
- size = TextControlBase.TextControlSize.MEDIUM,
- border = false,
- block = false,
- style = TextControlBase.TextControlStyle.DEFAULT,
- hiddenLabel = false,
- className: _className,
- placeholder: _placeholder,
- as: _as,
- ...etcProps
- }: MultilineTextInputProps,
- ref,
- ) => {
- const textInputBaseArgs = React.useMemo<TextControlBase.TextControlBaseArgs>(() => ({
- block,
- border,
- size,
- indicator: Boolean(indicator),
- style,
- resizable: true,
- predefinedValues: false,
- }), [block, border, size, indicator, style]);
-
- return (
- <div
- className={TextControlBase.Root(textInputBaseArgs)}
- >
- <textarea
- {...etcProps}
- className={TextControlBase.Input(textInputBaseArgs)}
- ref={ref}
- aria-label={label}
- style={{
- height: TextControlBase.MIN_HEIGHTS[size],
- }}
- data-testid="input"
- />
- {
- border && (
- <span
- data-testid="border"
- />
- )
- }
- {
- label && !hiddenLabel && (
- <div
- data-testid="label"
- className={TextControlBase.LabelWrapper(textInputBaseArgs)}
- >
- {label}
- </div>
- )
- }
- {hint && (
- <div
- className={TextControlBase.HintWrapper(textInputBaseArgs)}
- data-testid="hint"
- >
- <div
- className={TextControlBase.Hint()}
- >
- {hint}
- </div>
- </div>
- )}
- {indicator && (
- <div
- className={TextControlBase.IndicatorWrapper(textInputBaseArgs)}
- >
- {indicator}
- </div>
- )}
- </div>
- );
- }
- );
-
- MultilineTextInput.displayName = 'MultilineTextInput';
|