UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

55 lines (54 loc) 1.8 kB
"use client"; import React, { useContext } from 'react'; import DataContext from "../DataContext/Context.js"; import Section from "../../../components/Section.js"; import { FormLabel } from "../../../components/index.js"; import withComponentMarkers from "../../../shared/helpers/withComponentMarkers.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; function Log({ placeholder, label, data: logData, ...props }) { const { internalDataRef } = useContext(DataContext); const data = internalDataRef === null || internalDataRef === void 0 ? void 0 : internalDataRef.current; return _jsxs(Section, { element: "output", backgroundColor: "sand-yellow", style: { maxWidth: '80vw' }, innerSpace: true, ...props, children: [label && _jsx(FormLabel, { bottom: true, children: _jsx("b", { children: label }) }), _jsxs("pre", { children: [placeholder && Object.keys((logData !== null && logData !== void 0 ? logData : data) || {}).length === 0 ? placeholder : JSON.stringify(replaceUndefinedValues(logData !== null && logData !== void 0 ? logData : data), null, 2), ' '] })] }); } function replaceUndefinedValues(value, replaceWith = 'undefined') { if (typeof value === 'undefined') { return replaceWith; } else if (Array.isArray(value)) { return value.map(item => replaceUndefinedValues(item, replaceWith)); } else if (value && typeof value === 'object' && value !== replaceWith) { return { ...value, ...Object.fromEntries(Object.entries(value).map(([k, v]) => [k, replaceUndefinedValues(v, replaceWith)])) }; } else { return value; } } withComponentMarkers(Log, { _supportsSpacingProps: true }); export default Log; //# sourceMappingURL=Log.js.map