UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

66 lines (65 loc) 1.9 kB
"use client"; import _extends from "@babel/runtime-corejs3/helpers/esm/extends"; import React, { createContext, useContext } from 'react'; import classnames from 'classnames'; import E from "../Element.js"; export const TypographyContext = createContext({ proseMaxWidth: undefined }); const Typography = ({ element = 'p', className, size, lineHeight, align, family, weight, decoration, slant, proseMaxWidth: proseMaxWidthProp, ...props }) => { 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 React.createElement(E, _extends({ as: element }, props, { style: { ...props.style, ...style }, className: classnames(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}`) })); }; const Provider = ({ children, proseMaxWidth }) => { return React.createElement(TypographyContext.Provider, { value: { proseMaxWidth } }, children); }; 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