UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

44 lines (43 loc) 1.37 kB
"use client"; import _extends from "@babel/runtime/helpers/esm/extends"; import React, { useContext, useMemo } from 'react'; import StringValue from "../String/index.js"; import { useValueProps } from "../../hooks/index.js"; import useDataValue from "../../hooks/useDataValue.js"; import Context from "../../DataContext/Context.js"; import { convertJsxToString } from "../../../../shared/component-helper.js"; function Selection(props) { const { fieldInternalsRef } = useContext(Context) || {}; const { path, dataPath, value, ...rest } = useValueProps(props); const { getValueByPath } = useDataValue(); const valueToDisplay = useMemo(() => { const fieldProp = fieldInternalsRef?.current?.[path]?.props; if (path || dataPath) { let list = getValueByPath(dataPath)?.map?.(props => ({ props })); if (!list) { list = fieldProp?.children; } const title = list?.find?.(child => child.props.value === value)?.props?.title; return title ? convertJsxToString(title) : value; } return value; }, [dataPath, fieldInternalsRef, getValueByPath, path, value]); return React.createElement(StringValue, _extends({ value: valueToDisplay, path: path }, rest)); } Selection._supportsSpacingProps = true; export default Selection; //# sourceMappingURL=Selection.js.map