UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

53 lines (52 loc) 3.43 kB
"use strict"; "use client"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(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"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } 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 _react.default.createElement(_index.default, _extends({ value: valueToDisplay, path: path }, rest)); } Selection._supportsSpacingProps = true; var _default = exports.default = Selection; //# sourceMappingURL=Selection.js.map