UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

48 lines (47 loc) 2.05 kB
"use client"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import _extends from "@babel/runtime/helpers/esm/extends"; const _excluded = ["className", "internalClass", "as", "innerRef", "skeleton", "skeletonMethod"]; import React from 'react'; import classnames from 'classnames'; import Context from '../shared/Context'; import { validateDOMAttributes, extendPropsWithContext } from '../shared/component-helper'; import { createSpacingClasses } from '../components/space/SpacingHelper'; import { createSkeletonClass, skeletonDOMAttributes } from '../components/skeleton/SkeletonHelper'; export const defaultProps = { skeletonMethod: 'font' }; const Element = React.forwardRef((props, ref) => { return React.createElement(ElementInstance, _extends({ innerRef: ref }, props)); }); function ElementInstance(localProps) { const context = React.useContext(Context); const props = extendPropsWithContext(localProps, defaultProps, { skeleton: context === null || context === void 0 ? void 0 : context.skeleton }); const { className, internalClass, as, innerRef, skeleton, skeletonMethod } = props, rest = _objectWithoutProperties(props, _excluded); const Tag = as; const attributes = rest; const tagClass = internalClass === false ? '' : (internalClass === true ? undefined : internalClass) || (typeof Tag === 'string' ? `dnb-${Tag}` : ''); const internalClassName = classnames(className, createSkeletonClass(skeletonMethod, skeleton, context), createSpacingClasses(attributes, typeof Tag === 'string' ? `dnb-${Tag}` : null), !new RegExp(`${tagClass}(\\s|$)`).test(String(className)) && tagClass); validateDOMAttributes(null, attributes); skeletonDOMAttributes(attributes, skeleton, context); if (typeof Tag !== 'function' && innerRef) { attributes.ref = innerRef; } return React.createElement(Tag, _extends({ className: internalClassName }, attributes)); } export default Element; //# sourceMappingURL=Element.js.map