@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
63 lines (62 loc) • 2.04 kB
JavaScript
"use client";
import React, { useContext } from 'react';
import clsx from 'clsx';
import { applySpacing } from "../space/SpacingUtils.js";
import { getHeadingLineHeightSize } from "../../elements/typography/Typography.js";
import { validateDOMAttributes, warn } from "../../shared/component-helper.js";
import StatRootContext from "./StatRootContext.js";
import useStatSkeleton from "./useStatSkeleton.js";
import Provider from "../../shared/Provider.js";
import { jsx as _jsx } from "react/jsx-runtime";
function Label(props) {
const {
inRoot,
skeleton: rootSkeleton
} = useContext(StatRootContext);
const {
children,
element: elementProp,
className = null,
srOnly = false,
fontSize = 'basis',
fontWeight = 'regular',
variant = 'plain',
skeleton = null,
style = null,
...rest
} = props;
const Element = elementProp !== null && elementProp !== void 0 ? elementProp : inRoot ? 'dt' : 'span';
const {
hasSkeleton,
skeletonClass,
applySkeletonAttributes
} = useStatSkeleton(skeleton);
const childSkeleton = skeleton !== null && skeleton !== undefined ? hasSkeleton : rootSkeleton;
const resolvedLineHeight = getHeadingLineHeightSize(fontSize);
if (!inRoot) {
warn('Stat.Label should be used inside Stat.Root');
}
const attributes = validateDOMAttributes(props, applySpacing(props, {
...rest,
style,
className: clsx(`dnb-stat dnb-stat__label dnb-stat__label--${variant} dnb-t__size--${fontSize} dnb-t__line-height--${resolvedLineHeight} dnb-t__weight--${fontWeight}`, skeletonClass, className, srOnly && 'dnb-sr-only')
}));
applySkeletonAttributes(attributes);
return _jsx(StatRootContext, {
value: {
inRoot,
skeleton: childSkeleton
},
children: _jsx(Provider, {
skeleton: hasSkeleton,
children: _jsx(Element, {
...attributes,
children: children
})
})
});
}
Label._supportsSpacingProps = true;
Label._statRole = 'label';
export default Label;
//# sourceMappingURL=Label.js.map