UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

51 lines (50 loc) 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useIterateItemNo = useIterateItemNo; var _react = require("react"); var _index = require("../hooks/index.js"); var _index2 = require("../../hooks/index.js"); var _componentHelper = require("../../../../shared/component-helper.js"); var _ItemNo = require("./ItemNo.js"); var _jsxRuntime = require("react/jsx-runtime"); function useIterateItemNo({ label: labelProp, labelSuffix = undefined, required = undefined }) { const { index: iterateIndex } = (0, _index.useItem)() || {}; const { optionalLabelSuffix } = (0, _index2.useTranslation)().Field; const labelSuffixText = (0, _react.useMemo)(() => { if (typeof labelSuffix !== 'boolean' && (required === false || typeof labelSuffix !== 'undefined')) { return labelSuffix !== null && labelSuffix !== void 0 ? labelSuffix : optionalLabelSuffix; } return ''; }, [required, labelSuffix, optionalLabelSuffix]); return (0, _react.useMemo)(() => { let content = labelProp; if (iterateIndex !== undefined) { content = (0, _ItemNo.replaceItemNo)(labelProp, iterateIndex); } if (labelSuffixText) { if ((0, _componentHelper.convertJsxToString)(content).includes(optionalLabelSuffix)) { return content; } if (typeof content === 'string') { return content + ' ' + labelSuffixText; } if ((0, _react.isValidElement)(content)) { return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [content, ' ', labelSuffixText] }); } } return content; }, [iterateIndex, labelProp, labelSuffixText, optionalLabelSuffix]); } //# sourceMappingURL=useIterateItemNo.js.map