UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

68 lines (67 loc) 4.54 kB
/** * * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] * * This file is part of Neo4j. * * Neo4j is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { forwardRef, useMemo } from 'react'; import { classNames } from '../_common/defaultImports'; import { customLabelAndNoAriaLabelWarningMessage } from '../_common/messages'; import { needleWarningMessage } from '../_common/utils'; import { ExclamationCircleIconSolid, InformationCircleIconOutline, } from '../icons'; import { Tooltip } from '../tooltip'; /** * * * TextArea Component * * */ export const TextArea = forwardRef(function TextArea(props, ref) { const { label, isFluid, errorText, helpText, isOptional = false, informationIconText, size = 'medium', ariaLabel: ariaLabel, tooltipProps, isDisabled, className, isReadOnly, value, placeholder, htmlAttributes, } = props; const containerWrappingClasses = classNames(`ndl-text-area ndl-type-text`, className, { 'ndl-disabled': isDisabled, 'ndl-small': size === 'small', 'ndl-medium': size === 'medium', 'ndl-large': size === 'large', 'ndl-has-error': errorText, 'ndl-has-right-icon': errorText, 'ndl-has-icon': errorText, }); const hasEmptyLabelValue = !label || label === ''; const labelWrappingClasses = classNames('ndl-text-area-label', { 'ndl-fluid': isFluid, 'ndl-text-area-no-label': hasEmptyLabelValue, }); const isCustomLabel = label && typeof label !== 'string'; const hasCustomLabelAndNoAriaLabel = isCustomLabel && !ariaLabel; useMemo(() => { if (!label && !ariaLabel) { needleWarningMessage('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'); } if (hasCustomLabelAndNoAriaLabel) { needleWarningMessage(customLabelAndNoAriaLabelWarningMessage); } }, [label, ariaLabel, hasCustomLabelAndNoAriaLabel]); const informationIconClasses = classNames({ 'ndl-information-icon-small': size === 'small' || size === 'medium', 'ndl-information-icon-large': size === 'large', }); return (_jsxs("div", { className: containerWrappingClasses, children: [_jsxs("label", { className: labelWrappingClasses, children: [_jsx("div", { className: "ndl-text-area-wrapper", children: _jsx("textarea", Object.assign({ disabled: isDisabled, ref: ref, "aria-label": ariaLabel, readOnly: isReadOnly, value: value, placeholder: placeholder }, htmlAttributes)) }), !hasEmptyLabelValue && (_jsxs("div", { className: "ndl-text-area-wrapper", children: [_jsx("span", { className: "ndl-text-area-label-text", children: label }), informationIconText && (_jsxs(Tooltip, Object.assign({ type: "simple" }, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.tooltipRoot, { children: [_jsx(Tooltip.Trigger, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.tooltipTrigger, { children: _jsx("div", { className: informationIconClasses, "data-testid": "ndl-information-icon", children: _jsx(InformationCircleIconOutline, {}) }) })), _jsx(Tooltip.Content, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.tooltipContent, { children: informationIconText }))] }))), isOptional && (_jsx("span", { className: "ndl-text-area-optional", children: "Optional" }))] }))] }), helpText && !errorText && (_jsx("div", { className: "ndl-text-area-msg", children: helpText })), errorText && (_jsxs("div", { className: "ndl-text-area-msg", children: [_jsx("div", { className: "ndl-error-icon", children: _jsx(ExclamationCircleIconSolid, {}) }), _jsx("div", { className: "ndl-error-text", children: errorText })] }))] })); }); //# sourceMappingURL=TextArea.js.map