@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
72 lines (71 loc) • 2.08 kB
JavaScript
"use client";
import React, { createContext, useContext } from 'react';
import clsx from 'clsx';
import E from "../Element.js";
import withComponentMarkers from "../../shared/helpers/withComponentMarkers.js";
import Context from "../../shared/Context.js";
import { jsx as _jsx } from "react/jsx-runtime";
export const TypographyContext = createContext({
proseMaxWidth: undefined
});
const Typography = ({
element = 'p',
className,
size,
lineHeight,
align,
family,
weight,
decoration,
slant,
proseMaxWidth: proseMaxWidthProp,
...props
}) => {
const context = useContext(Context);
const {
proseMaxWidth: proseMaxWidthContext
} = useContext(TypographyContext);
const proseMaxWidth = proseMaxWidthProp !== null && proseMaxWidthProp !== void 0 ? proseMaxWidthProp : proseMaxWidthContext;
const style = proseMaxWidth ? {
maxWidth: `${proseMaxWidth === true ? 60 : proseMaxWidth}ch`
} : undefined;
return _jsx(E, {
as: element,
...props,
style: {
...props.style,
...style
},
className: clsx(className, (lineHeight || size) && `dnb-t__line-height--${lineHeight || size}`, size && `dnb-t__size--${size}`, align && `dnb-t__align--${align}`, family && `dnb-t__family--${family}`, weight && `dnb-t__weight--${weight}`, decoration && `dnb-t__decoration--${decoration}`, slant && `dnb-t__slant--${slant}`, context?.theme?.surface === 'dark' && 'dnb-t--surface-dark')
});
};
const Provider = ({
children,
proseMaxWidth
}) => {
return _jsx(TypographyContext, {
value: {
proseMaxWidth
},
children: children
});
};
withComponentMarkers(Typography, {
_supportsSpacingProps: true
});
Typography.Provider = Provider;
export default Typography;
export { Provider };
const HEADING_LINE_HEIGHT_MAP = {
'x-small': 'x-small',
small: 'small',
basis: 'basis',
medium: 'basis',
large: 'medium',
'x-large': 'large',
'xx-large': 'xx-large'
};
export function getHeadingLineHeightSize(fontSize) {
return HEADING_LINE_HEIGHT_MAP[fontSize] || 'basis';
}
//# sourceMappingURL=Typography.js.map