@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
71 lines (70 loc) • 5.02 kB
JavaScript
/**
*
* 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/>.
*/
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextArea = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const defaultImports_1 = require("../_common/defaultImports");
const messages_1 = require("../_common/messages");
const utils_1 = require("../_common/utils");
const icons_1 = require("../icons");
const tooltip_1 = require("../tooltip");
/**
*
*
* TextArea Component
*
*
*/
exports.TextArea = (0, react_1.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 = (0, defaultImports_1.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 = (0, defaultImports_1.classNames)('ndl-text-area-label', {
'ndl-fluid': isFluid,
'ndl-text-area-no-label': hasEmptyLabelValue,
});
const isCustomLabel = label && typeof label !== 'string';
const hasCustomLabelAndNoAriaLabel = isCustomLabel && !ariaLabel;
(0, react_1.useMemo)(() => {
if (!label && !ariaLabel) {
(0, utils_1.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) {
(0, utils_1.needleWarningMessage)(messages_1.customLabelAndNoAriaLabelWarningMessage);
}
}, [label, ariaLabel, hasCustomLabelAndNoAriaLabel]);
const informationIconClasses = (0, defaultImports_1.classNames)({
'ndl-information-icon-small': size === 'small' || size === 'medium',
'ndl-information-icon-large': size === 'large',
});
return ((0, jsx_runtime_1.jsxs)("div", { className: containerWrappingClasses, children: [(0, jsx_runtime_1.jsxs)("label", { className: labelWrappingClasses, children: [(0, jsx_runtime_1.jsx)("div", { className: "ndl-text-area-wrapper", children: (0, jsx_runtime_1.jsx)("textarea", Object.assign({ disabled: isDisabled, ref: ref, "aria-label": ariaLabel, readOnly: isReadOnly, value: value, placeholder: placeholder }, htmlAttributes)) }), !hasEmptyLabelValue && ((0, jsx_runtime_1.jsxs)("div", { className: "ndl-text-area-wrapper", children: [(0, jsx_runtime_1.jsx)("span", { className: "ndl-text-area-label-text", children: label }), informationIconText && ((0, jsx_runtime_1.jsxs)(tooltip_1.Tooltip, Object.assign({ type: "simple" }, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.tooltipRoot, { children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Trigger, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.tooltipTrigger, { children: (0, jsx_runtime_1.jsx)("div", { className: informationIconClasses, "data-testid": "ndl-information-icon", children: (0, jsx_runtime_1.jsx)(icons_1.InformationCircleIconOutline, {}) }) })), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Content, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.tooltipContent, { children: informationIconText }))] }))), isOptional && ((0, jsx_runtime_1.jsx)("span", { className: "ndl-text-area-optional", children: "Optional" }))] }))] }), helpText && !errorText && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-text-area-msg", children: helpText })), errorText && ((0, jsx_runtime_1.jsxs)("div", { className: "ndl-text-area-msg", children: [(0, jsx_runtime_1.jsx)("div", { className: "ndl-error-icon", children: (0, jsx_runtime_1.jsx)(icons_1.ExclamationCircleIconSolid, {}) }), (0, jsx_runtime_1.jsx)("div", { className: "ndl-error-text", children: errorText })] }))] }));
});
//# sourceMappingURL=TextArea.js.map