@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
97 lines (96 loc) • 2.45 kB
JavaScript
"use client";
import React from 'react';
import clsx from 'clsx';
import { extendPropsWithContext, validateDOMAttributes } from "../../shared/component-helper.js";
import Context from "../../shared/Context.js";
import { createSpacing, isInline } from "./SpacingUtils.js";
import { skeletonDOMAttributes, createSkeletonClass } from "../skeleton/SkeletonHelper.js";
import withComponentMarkers from "../../shared/helpers/withComponentMarkers.js";
import { jsx as _jsx } from "react/jsx-runtime";
const defaultProps = {};
function SpaceInstance(localProps) {
const context = React.useContext(Context);
const props = context.space ? extendPropsWithContext(localProps, defaultProps, {
space: context.space
}, {
skeleton: context === null || context === void 0 ? void 0 : context.skeleton
}) : localProps;
const {
element = 'div',
inline,
noCollapse,
top,
right,
bottom,
left,
style,
space,
innerSpace,
stretch,
skeleton,
ref,
className,
children,
...attributes
} = props;
const spacing = createSpacing({
top,
right,
bottom,
left,
space
});
const spacingInnerStyle = createSpacing(props).style;
const params = {
className: clsx('dnb-space', createSkeletonClass(null, skeleton), ...spacing.className, className, stretch && 'dnb-space--stretch', inline && 'dnb-space--inline'),
...attributes
};
const styleObj = {
...style,
...spacingInnerStyle
};
skeletonDOMAttributes(params, skeleton);
return _jsx(SpaceElement, {
element: element,
noCollapse: noCollapse,
ref: ref,
style: styleObj,
...params,
children: children
});
}
function Space(props) {
return _jsx(SpaceInstance, {
...props
});
}
withComponentMarkers(Space, {
_supportsSpacingProps: true
});
export default Space;
function SpaceElement({
element,
noCollapse,
children,
ref,
...props
}) {
const ElementDynamic = element;
if (typeof element === 'string') {
validateDOMAttributes({}, props);
}
props['ref'] = ref;
const component = _jsx(ElementDynamic, {
...props,
children: children
});
if (noCollapse) {
const R = ElementDynamic === 'span' || isInline(element) ? 'span' : 'div';
return _jsx(R, {
className: 'dnb-space--no-collapse' + (isInline(element) ? " dnb-space--inline" : ""),
children: component
});
}
return component;
}
//# sourceMappingURL=Space.js.map