@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
48 lines (47 loc) • 1.52 kB
JavaScript
"use client";
import _extends from "@babel/runtime/helpers/esm/extends";
import React, { useContext, useMemo } from 'react';
import classnames from 'classnames';
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";
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) {
const data = fieldInternalsRef?.current?.[path + '/arraySelectionData']?.props;
valueToUse = data?.map?.(({
title
}) => convertJsxToString(title)) || value;
}
if (typeof valueToUse === 'undefined') {
return undefined;
}
return React.createElement(ListFormat, {
value: valueToUse,
format: format,
variant: variant,
listType: listType
});
}, [value, path, format, variant, listType, fieldInternalsRef]);
return React.createElement(ValueBlock, _extends({
className: classnames('dnb-forms-value-array-selection', className)
}, rest), list);
}
ArraySelection._supportsSpacingProps = true;
export default ArraySelection;
//# sourceMappingURL=ArraySelection.js.map