{"version":3,"file":"TextArea.mjs","names":[],"sources":["../../../src/text-area/TextArea.tsx"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport type React from 'react';\nimport { type ReactNode, useMemo } from 'react';\n\nimport {\n  FormFieldLabel,\n  FormFieldMessage,\n  useFormField,\n} from '../_common/form-control';\nimport { customLabelAndNoAriaLabelWarningMessage } from '../_common/messages';\nimport {\n  type CommonProps,\n  type HtmlAttributes,\n  type TooltipObjectProps,\n} from '../_common/types';\nimport { needleWarningMessage } from '../_common/utils';\n\n/**\n *\n *\n * Types\n *\n *\n */\n\n/**\n * @remarks\n * When `moreInformationText` is provided, a tooltip is rendered next to the label, and the `tooltipProps` prop is used to configure the tooltip. The `TooltipObjectProps` type is defined as: `{ root?: Partial<React.ComponentProps<typeof Tooltip>>; trigger?: Partial<React.ComponentProps<typeof Tooltip.Trigger>>; content?: Partial<React.ComponentProps<typeof Tooltip.Content>>; }`, see the Tooltip component for more details.\n */\ntype TextAreaProps = {\n  // TODO v5: inconsistent naming. The label is optional here and pairs with the\n  // `ariaLabel` prop below, while Combobox requires the label and clips it with\n  // `hasVisuallyHiddenLabel`, and TextInput has no aria label prop at all.\n  /** The label displayed above the textarea */\n  label?: ReactNode;\n\n  /** Whether the textarea should take the full available width */\n  isFluid?: boolean;\n\n  /** Assistive text displayed below the textarea */\n  helpText?: string | ReactNode;\n\n  /** Error message displayed below the textarea. When provided, it overrides `helpText` and shows an error icon */\n  errorText?: string | ReactNode;\n\n  /** Size of the textarea */\n  size?: 'small' | 'medium' | 'large';\n\n  // TODO v5: inconsistent naming, and one prop doing two jobs. The same switch\n  // is `showRequiredOrOptionalLabel` on TextInput and `hasRequiredIndicator` on\n  // Combobox and on the internal form control this maps onto. Here it also\n  // decides both whether the indicator shows at all and which word it shows,\n  // because TextArea exposes no `isRequired` to pair it with: requiredness has\n  // to be set through htmlAttributes.required, and exposing `isRequired` on its\n  // own would silently render no indicator.\n  /** Whether to display the Optional label next to the field label */\n  isOptional?: boolean;\n\n  /** Text displayed in the information tooltip shown next to the label */\n  moreInformationText?: React.ReactNode;\n\n  /** Props for the Tooltip component used by the information icon */\n  tooltipProps?: TooltipObjectProps;\n\n  /** Whether the textarea is disabled */\n  isDisabled?: boolean;\n\n  /** Additional HTML attributes passed to the textarea element */\n  htmlAttributes?: HtmlAttributes<'textarea'>;\n\n  // TODO v5: inconsistent naming. This replaces the accessible name rather than\n  // hiding the label, which is a second way of naming the control alongside\n  // `label` above. TextInput reaches for htmlAttributes['aria-label'] for the\n  // same case and Combobox clips the label with `hasVisuallyHiddenLabel`.\n  /** Aria label for accessibility when no visible label is provided */\n  ariaLabel?: string;\n\n  /** Additional class names */\n  className?: string;\n\n  /** Additional styles applied to the root element */\n  style?: React.CSSProperties;\n\n  /** Whether the textarea is read-only */\n  isReadOnly?: boolean;\n\n  /** The current value of the textarea */\n  value?: React.ComponentPropsWithoutRef<'textarea'>['value'];\n\n  /** Placeholder text displayed when the textarea is empty */\n  placeholder?: React.ComponentPropsWithoutRef<'textarea'>['placeholder'];\n};\n\n/**\n *\n *\n * TextArea Component\n *\n *\n */\n\nexport const TextArea = ({\n  label,\n  isFluid = false,\n  errorText,\n  helpText,\n  isOptional = false,\n  moreInformationText,\n  size = 'medium',\n  ariaLabel,\n  tooltipProps,\n  isDisabled = false,\n  className,\n  isReadOnly = false,\n  style,\n  value,\n  placeholder,\n  htmlAttributes,\n  ref,\n  ...restProps\n}: CommonProps<'textarea', TextAreaProps>) => {\n  const { field, controlProps } = useFormField({\n    errorText,\n    hasRequiredIndicator: isOptional,\n    helpText,\n    label,\n  });\n  const containerWrappingClasses = classNames(\n    `ndl-text-area ndl-type-text`,\n    className,\n    {\n      'ndl-disabled': isDisabled,\n      'ndl-has-error': errorText,\n      'ndl-has-icon': errorText,\n      'ndl-has-trailing-icon': errorText,\n      'ndl-large': size === 'large',\n      'ndl-medium': size === 'medium',\n      'ndl-small': size === 'small',\n    },\n  );\n\n  const hasEmptyLabelValue = !label || label === '';\n\n  const labelWrappingClasses = classNames('ndl-text-area-label', {\n    'ndl-fluid': isFluid,\n  });\n\n  const isCustomLabel = label && typeof label !== 'string';\n  const hasCustomLabelAndNoAriaLabel = isCustomLabel && !ariaLabel;\n\n  useMemo(() => {\n    if (!label && !ariaLabel) {\n      needleWarningMessage(\n        'A TextArea without a label does not have an aria label, be sure to include an aria label for screen readers link: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI',\n      );\n    }\n\n    if (hasCustomLabelAndNoAriaLabel) {\n      needleWarningMessage(customLabelAndNoAriaLabelWarningMessage);\n    }\n  }, [label, ariaLabel, hasCustomLabelAndNoAriaLabel]);\n\n  return (\n    <div className={containerWrappingClasses}>\n      {/* We enable implicit label wrapping */}\n      {/* Source: https://dequeuniversity.com/rules/axe/4.2/label?application=axeAPI */}\n      <label className={labelWrappingClasses}>\n        {!hasEmptyLabelValue && (\n          <FormFieldLabel\n            field={field}\n            size={size}\n            association=\"implicit\"\n            moreInformationText={moreInformationText}\n            tooltipProps={tooltipProps}\n          />\n        )}\n        <div className=\"ndl-text-area-wrapper\">\n          <textarea\n            disabled={isDisabled}\n            ref={ref}\n            aria-label={ariaLabel}\n            readOnly={isReadOnly}\n            value={value}\n            placeholder={placeholder}\n            style={style}\n            {...controlProps}\n            {...restProps}\n            {...htmlAttributes}\n          />\n        </div>\n      </label>\n      <FormFieldMessage field={field} size={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