@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
98 lines (97 loc) • 2.48 kB
JavaScript
"use client";
import { useContext } from 'react';
import clsx from 'clsx';
import { extendPropsWithContext, validateDOMAttributes } from "../../shared/component-helper.js";
import Context from "../../shared/Context.js";
import { useSpacing, isInline } from "./SpacingUtils.js";
import { skeletonDOMAttributes, createSkeletonClass } from "../skeleton/SkeletonHelper.js";
import withComponentMarkers from "../../shared/helpers/withComponentMarkers.js";
import SpaceResponsive from "./SpaceResponsive.js";
import { jsx as _jsx } from "react/jsx-runtime";
const defaultProps = {};
function SpaceInstance(localProps) {
const context = useContext(Context);
const props = context.space ? extendPropsWithContext(localProps, defaultProps, {
space: context.space
}, {
skeleton: context?.skeleton
}) : localProps;
const {
element = 'div',
inline,
noCollapse,
top,
right,
bottom,
left,
style,
space,
innerSpace,
stretch,
skeleton,
ref,
className,
children,
...attributes
} = props;
const params = useSpacing({
top,
right,
bottom,
left,
space,
innerSpace
}, {
style,
className: clsx('dnb-space', createSkeletonClass(null, skeleton), stretch && 'dnb-space--stretch', inline && 'dnb-space--inline'),
...attributes
});
params.className = clsx(params.className, className);
skeletonDOMAttributes(params, skeleton);
return _jsx(SpaceElement, {
element: element,
noCollapse: noCollapse,
ref: ref,
...params,
children: children
});
}
function Space(props) {
return _jsx(SpaceInstance, {
...props
});
}
Space.ResponsiveContext = SpaceResponsive;
withComponentMarkers(Space, {
_supportsSpacingProps: true
});
withComponentMarkers(Space.ResponsiveContext, {
_supportsSpacingProps: 'passthrough'
});
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