@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
54 lines (53 loc) • 2 kB
JavaScript
"use client";
import React, { useContext, useMemo } from 'react';
import clsx from 'clsx';
import { useValueProps } from "../../hooks/index.js";
import ValueBlock from "../../ValueBlock/index.js";
import { convertJsxToString } from "../../../../shared/component-helper.js";
import Context from "../../DataContext/Context.js";
import ListFormat from "../../../../components/list-format/index.js";
import withComponentMarkers from "../../../../shared/helpers/withComponentMarkers.js";
import { jsx as _jsx } from "react/jsx-runtime";
function ArraySelection(props) {
const {
fieldInternalsRef
} = useContext(Context) || {};
const {
path,
value,
format,
className,
variant = 'text',
listType,
...rest
} = useValueProps(props);
const list = useMemo(() => {
let valueToUse = value;
if (path) {
var _fieldInternalsRef$cu, _data$map;
const data = fieldInternalsRef === null || fieldInternalsRef === void 0 || (_fieldInternalsRef$cu = fieldInternalsRef.current) === null || _fieldInternalsRef$cu === void 0 || (_fieldInternalsRef$cu = _fieldInternalsRef$cu[path + '/arraySelectionData']) === null || _fieldInternalsRef$cu === void 0 ? void 0 : _fieldInternalsRef$cu.props;
valueToUse = (data === null || data === void 0 || (_data$map = data.map) === null || _data$map === void 0 ? void 0 : _data$map.call(data, ({
title
}) => convertJsxToString(title))) || value;
}
if (typeof valueToUse === 'undefined') {
return undefined;
}
return _jsx(ListFormat, {
value: valueToUse,
format: format,
variant: variant,
listType: listType
});
}, [value, path, format, variant, listType, fieldInternalsRef]);
return _jsx(ValueBlock, {
className: clsx('dnb-forms-value-array-selection', className),
...rest,
children: list
});
}
withComponentMarkers(ArraySelection, {
_supportsSpacingProps: true
});
export default ArraySelection;
//# sourceMappingURL=ArraySelection.js.map