UNPKG

@material-ui/core

Version:

React components that implement Google's Material Design.

194 lines (178 loc) 7.72 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = createTypography; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _deepmerge = _interopRequireDefault(require("deepmerge")); var _warning = _interopRequireDefault(require("warning")); var _utils = require("@material-ui/utils"); // < 1kb payload overhead when lodash/merge is > 3kb. function round(value) { return Math.round(value * 1e5) / 1e5; } var caseAllCaps = { textTransform: 'uppercase' }; var defaultFontFamily = '"Roboto", "Helvetica", "Arial", sans-serif'; /** * @see @link{https://material.io/design/typography/the-type-system.html} * @see @link{https://material.io/design/typography/understanding-typography.html} */ function createTypography(palette, typography) { var _ref = typeof typography === 'function' ? typography(palette) : typography, _ref$fontFamily = _ref.fontFamily, fontFamily = _ref$fontFamily === void 0 ? defaultFontFamily : _ref$fontFamily, _ref$fontSize = _ref.fontSize, fontSize = _ref$fontSize === void 0 ? 14 : _ref$fontSize, _ref$fontWeightLight = _ref.fontWeightLight, fontWeightLight = _ref$fontWeightLight === void 0 ? 300 : _ref$fontWeightLight, _ref$fontWeightRegula = _ref.fontWeightRegular, fontWeightRegular = _ref$fontWeightRegula === void 0 ? 400 : _ref$fontWeightRegula, _ref$fontWeightMedium = _ref.fontWeightMedium, fontWeightMedium = _ref$fontWeightMedium === void 0 ? 500 : _ref$fontWeightMedium, _ref$htmlFontSize = _ref.htmlFontSize, htmlFontSize = _ref$htmlFontSize === void 0 ? 16 : _ref$htmlFontSize, _ref$useNextVariants = _ref.useNextVariants, useNextVariants = _ref$useNextVariants === void 0 ? Boolean(_utils.ponyfillGlobal.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__) : _ref$useNextVariants, _ref$suppressWarning = _ref.suppressWarning, suppressWarning = _ref$suppressWarning === void 0 ? false : _ref$suppressWarning, allVariants = _ref.allVariants, other = (0, _objectWithoutProperties2.default)(_ref, ["fontFamily", "fontSize", "fontWeightLight", "fontWeightRegular", "fontWeightMedium", "htmlFontSize", "useNextVariants", "suppressWarning", "allVariants"]); process.env.NODE_ENV !== "production" ? (0, _warning.default)(useNextVariants || suppressWarning, 'Material-UI: you are using the deprecated typography variants ' + 'that will be removed in the next major release.' + '\nPlease read the migration guide under https://material-ui.com/style/typography#migration-to-typography-v2') : void 0; var coef = fontSize / 14; var pxToRem = function pxToRem(size) { return "".concat(size / htmlFontSize * coef, "rem"); }; var buildVariant = function buildVariant(fontWeight, size, lineHeight, letterSpacing, casing) { return (0, _extends2.default)({ color: palette.text.primary, fontFamily: fontFamily, fontWeight: fontWeight, fontSize: pxToRem(size), // Unitless following http://meyerweb.com/eric/thoughts/2006/02/08/unitless-line-heights/ lineHeight: lineHeight }, fontFamily === defaultFontFamily ? { letterSpacing: "".concat(round(letterSpacing / size), "em") } : {}, casing, allVariants); }; var nextVariants = { h1: buildVariant(fontWeightLight, 96, 1, -1.5), h2: buildVariant(fontWeightLight, 60, 1, -0.5), h3: buildVariant(fontWeightRegular, 48, 1.04, 0), h4: buildVariant(fontWeightRegular, 34, 1.17, 0.25), h5: buildVariant(fontWeightRegular, 24, 1.33, 0), h6: buildVariant(fontWeightMedium, 20, 1.6, 0.15), subtitle1: buildVariant(fontWeightRegular, 16, 1.75, 0.15), subtitle2: buildVariant(fontWeightMedium, 14, 1.57, 0.1), body1Next: buildVariant(fontWeightRegular, 16, 1.5, 0.15), body2Next: buildVariant(fontWeightRegular, 14, 1.5, 0.15), buttonNext: buildVariant(fontWeightMedium, 14, 1.5, 0.4, caseAllCaps), captionNext: buildVariant(fontWeightRegular, 12, 1.66, 0.4), overline: buildVariant(fontWeightRegular, 12, 2.66, 1, caseAllCaps) }; // To remove in v4 var oldVariants = { display4: (0, _extends2.default)({ fontSize: pxToRem(112), fontWeight: fontWeightLight, fontFamily: fontFamily, letterSpacing: '-.04em', lineHeight: "".concat(round(128 / 112), "em"), marginLeft: '-.04em', color: palette.text.secondary }, allVariants), display3: (0, _extends2.default)({ fontSize: pxToRem(56), fontWeight: fontWeightRegular, fontFamily: fontFamily, letterSpacing: '-.02em', lineHeight: "".concat(round(73 / 56), "em"), marginLeft: '-.02em', color: palette.text.secondary }, allVariants), display2: (0, _extends2.default)({ fontSize: pxToRem(45), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(51 / 45), "em"), marginLeft: '-.02em', color: palette.text.secondary }, allVariants), display1: (0, _extends2.default)({ fontSize: pxToRem(34), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(41 / 34), "em"), color: palette.text.secondary }, allVariants), headline: (0, _extends2.default)({ fontSize: pxToRem(24), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(32.5 / 24), "em"), color: palette.text.primary }, allVariants), title: (0, _extends2.default)({ fontSize: pxToRem(21), fontWeight: fontWeightMedium, fontFamily: fontFamily, lineHeight: "".concat(round(24.5 / 21), "em"), color: palette.text.primary }, allVariants), subheading: (0, _extends2.default)({ fontSize: pxToRem(16), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(24 / 16), "em"), color: palette.text.primary }, allVariants), body2: (0, _extends2.default)({ fontSize: pxToRem(14), fontWeight: fontWeightMedium, fontFamily: fontFamily, lineHeight: "".concat(round(24 / 14), "em"), color: palette.text.primary }, allVariants), body1: (0, _extends2.default)({ fontSize: pxToRem(14), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(20.5 / 14), "em"), color: palette.text.primary }, allVariants), caption: (0, _extends2.default)({ fontSize: pxToRem(12), fontWeight: fontWeightRegular, fontFamily: fontFamily, lineHeight: "".concat(round(16.5 / 12), "em"), color: palette.text.secondary }, allVariants), button: (0, _extends2.default)({ fontSize: pxToRem(14), textTransform: 'uppercase', fontWeight: fontWeightMedium, fontFamily: fontFamily, color: palette.text.primary }, allVariants) }; return (0, _deepmerge.default)((0, _extends2.default)({ pxToRem: pxToRem, round: round, fontFamily: fontFamily, fontSize: fontSize, fontWeightLight: fontWeightLight, fontWeightRegular: fontWeightRegular, fontWeightMedium: fontWeightMedium }, oldVariants, nextVariants, useNextVariants ? { body1: nextVariants.body1Next, body2: nextVariants.body2Next, button: nextVariants.buttonNext, caption: nextVariants.captionNext } : {}, { useNextVariants: useNextVariants }), other, { clone: false // No need to clone deep }); }