@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
103 lines (102 loc) • 4.47 kB
JavaScript
;
"use client";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SectionParams = SectionParams;
exports.default = Section;
var _react = _interopRequireDefault(require("react"));
var _clsx = _interopRequireDefault(require("clsx"));
var _Context = _interopRequireDefault(require("../../shared/Context.js"));
var _componentHelper = require("../../shared/component-helper.js");
var _Space = _interopRequireDefault(require("../space/Space.js"));
var _Theme = _interopRequireDefault(require("../../shared/Theme.js"));
var _helpers = require("../../shared/helpers.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 }; }
const defaultProps = {
element: 'section'
};
function SectionInstance(localProps) {
return (0, _jsxRuntime.jsx)(_Space.default, {
...SectionParams(localProps)
});
}
function Section(props) {
return (0, _jsxRuntime.jsx)(SectionInstance, {
...props
});
}
function SectionParams(localProps) {
var _localProps$surface, _context$theme, _ref;
const context = _react.default.useContext(_Context.default);
const props = (0, _componentHelper.extendPropsWithContext)(localProps, defaultProps, context.Section, {
surface: (_localProps$surface = localProps === null || localProps === void 0 ? void 0 : localProps.surface) !== null && _localProps$surface !== void 0 ? _localProps$surface : context === null || context === void 0 || (_context$theme = context.theme) === null || _context$theme === void 0 ? void 0 : _context$theme.surface
});
const {
variant,
breakout = !props.outset,
outset,
roundedCorner,
textColor,
backgroundColor,
dropShadow,
outline,
outlineWidth = typeof props.outline === 'undefined' && typeof props.outlineWidth === 'undefined' ? 'none' : props.outlineWidth,
surface,
ref: refProp,
className,
children,
...attributes
} = props;
const internalRef = _react.default.useRef(undefined);
const elementRef = refProp || internalRef;
return Object.freeze({
...attributes,
className: (0, _clsx.default)(`dnb-section dnb-section--${(_ref = variant !== null && variant !== void 0 ? variant : surface) !== null && _ref !== void 0 ? _ref : 'default'}`, className, surface && `dnb-section--surface-${surface}`),
style: {
...computeStyle(breakout, 'breakout', value => `var(--breakout--${value ? 'on' : 'off'})`),
...computeStyle(outset, 'outset', value => value ? '1' : '0'),
...computeStyle(roundedCorner, 'rounded-corner', value => typeof value === 'boolean' ? value && 'var(--rounded-corner--value)' : value.map(v => v ? 'var(--rounded-corner--value)' : '0').join(' ')),
...computeStyle(textColor, 'text-color', value => (0, _helpers.getColor)(value)),
...computeStyle(backgroundColor, 'background-color', value => (0, _helpers.getColor)(value)),
...computeStyle(dropShadow, 'drop-shadow', value => value && 'var(--shadow-default)'),
...computeStyle(outline, 'outline-color', value => typeof value === 'boolean' ? value && 'var(--outline-color--value)' : (0, _helpers.getColor)(value)),
...computeStyle(outlineWidth, 'outline-width', value => typeof value === 'number' ? `${value}px` : value),
...(attributes === null || attributes === void 0 ? void 0 : attributes.style)
},
ref: elementRef,
children: surface ? (0, _jsxRuntime.jsx)(_Theme.default.Context, {
surface: surface,
children: children
}) : children
});
}
function computeStyle(property, name, valueCallback) {
let media = property;
if (media !== null && (Array.isArray(media) || typeof media !== 'object')) {
media = {
small: property,
medium: property,
large: property
};
}
const result = {};
for (const size in media) {
var _media;
if (typeof ((_media = media) === null || _media === void 0 ? void 0 : _media[size]) !== 'undefined') {
var _media2;
const value = valueCallback((_media2 = media) === null || _media2 === void 0 ? void 0 : _media2[size]);
if (typeof value === 'string') {
result[`--${name}--${size}`] = value;
}
}
}
return result;
}
Section._name = 'Section';
(0, _withComponentMarkers.default)(Section, {
_supportsSpacingProps: true
});
//# sourceMappingURL=Section.js.map