@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
56 lines (55 loc) • 2.71 kB
JavaScript
"use strict";
"use client";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _index = _interopRequireDefault(require("../String/index.js"));
var _index2 = require("../../hooks/index.js");
var _useDataValue = _interopRequireDefault(require("../../hooks/useDataValue.js"));
var _Context = _interopRequireDefault(require("../../DataContext/Context.js"));
var _componentHelper = require("../../../../shared/component-helper.js");
var _withComponentMarkers = _interopRequireDefault(require("../../../../shared/helpers/withComponentMarkers.js"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function Selection(props) {
const {
fieldInternalsRef
} = (0, _react.useContext)(_Context.default) || {};
const {
path,
dataPath,
value,
...rest
} = (0, _index2.useValueProps)(props);
const {
getValueByPath
} = (0, _useDataValue.default)();
const valueToDisplay = (0, _react.useMemo)(() => {
var _fieldInternalsRef$cu;
const fieldProp = fieldInternalsRef === null || fieldInternalsRef === void 0 || (_fieldInternalsRef$cu = fieldInternalsRef.current) === null || _fieldInternalsRef$cu === void 0 || (_fieldInternalsRef$cu = _fieldInternalsRef$cu[path]) === null || _fieldInternalsRef$cu === void 0 ? void 0 : _fieldInternalsRef$cu.props;
if (path || dataPath) {
var _getValueByPath, _getValueByPath$map, _list, _list$find;
let list = (_getValueByPath = getValueByPath(dataPath)) === null || _getValueByPath === void 0 || (_getValueByPath$map = _getValueByPath.map) === null || _getValueByPath$map === void 0 ? void 0 : _getValueByPath$map.call(_getValueByPath, props => ({
props
}));
if (!list) {
list = fieldProp === null || fieldProp === void 0 ? void 0 : fieldProp.children;
}
const title = (_list = list) === null || _list === void 0 || (_list$find = _list.find) === null || _list$find === void 0 || (_list$find = _list$find.call(_list, child => child.props.value === value)) === null || _list$find === void 0 || (_list$find = _list$find.props) === null || _list$find === void 0 ? void 0 : _list$find.title;
return title ? (0, _componentHelper.convertJsxToString)(title) : value;
}
return value;
}, [dataPath, fieldInternalsRef, getValueByPath, path, value]);
return (0, _jsxRuntime.jsx)(_index.default, {
value: valueToDisplay,
path: path,
...rest
});
}
(0, _withComponentMarkers.default)(Selection, {
_supportsSpacingProps: true
});
var _default = exports.default = Selection;
//# sourceMappingURL=Selection.js.map