UNPKG

@material-ui/core

Version:

React components that implement Google's Material Design.

120 lines (102 loc) 4.7 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 _utils = require("@material-ui/utils"); function round(value) { return Math.round(value * 1e5) / 1e5; } var warnedOnce = false; function roundWithDeprecationWarning(value) { if (process.env.NODE_ENV !== 'production') { if (!warnedOnce) { console.warn(['Material-UI: The `theme.typography.round` helper is deprecated.', 'Head to https://mui.com/r/migration-v4/#theme for a migration path.'].join('\n')); warnedOnce = true; } } return round(value); } 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$fontWeightBold = _ref.fontWeightBold, fontWeightBold = _ref$fontWeightBold === void 0 ? 700 : _ref$fontWeightBold, _ref$htmlFontSize = _ref.htmlFontSize, htmlFontSize = _ref$htmlFontSize === void 0 ? 16 : _ref$htmlFontSize, allVariants = _ref.allVariants, pxToRem2 = _ref.pxToRem, other = (0, _objectWithoutProperties2.default)(_ref, ["fontFamily", "fontSize", "fontWeightLight", "fontWeightRegular", "fontWeightMedium", "fontWeightBold", "htmlFontSize", "allVariants", "pxToRem"]); if (process.env.NODE_ENV !== 'production') { if (typeof fontSize !== 'number') { console.error('Material-UI: `fontSize` is required to be a number.'); } if (typeof htmlFontSize !== 'number') { console.error('Material-UI: `htmlFontSize` is required to be a number.'); } } var coef = fontSize / 14; var pxToRem = pxToRem2 || function (size) { return "".concat(size / htmlFontSize * coef, "rem"); }; var buildVariant = function buildVariant(fontWeight, size, lineHeight, letterSpacing, casing) { return (0, _extends2.default)({ fontFamily: fontFamily, fontWeight: fontWeight, fontSize: pxToRem(size), // Unitless following https://meyerweb.com/eric/thoughts/2006/02/08/unitless-line-heights/ lineHeight: lineHeight }, fontFamily === defaultFontFamily ? { letterSpacing: "".concat(round(letterSpacing / size), "em") } : {}, casing, allVariants); }; var variants = { h1: buildVariant(fontWeightLight, 96, 1.167, -1.5), h2: buildVariant(fontWeightLight, 60, 1.2, -0.5), h3: buildVariant(fontWeightRegular, 48, 1.167, 0), h4: buildVariant(fontWeightRegular, 34, 1.235, 0.25), h5: buildVariant(fontWeightRegular, 24, 1.334, 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), body1: buildVariant(fontWeightRegular, 16, 1.5, 0.15), body2: buildVariant(fontWeightRegular, 14, 1.43, 0.15), button: buildVariant(fontWeightMedium, 14, 1.75, 0.4, caseAllCaps), caption: buildVariant(fontWeightRegular, 12, 1.66, 0.4), overline: buildVariant(fontWeightRegular, 12, 2.66, 1, caseAllCaps) }; return (0, _utils.deepmerge)((0, _extends2.default)({ htmlFontSize: htmlFontSize, pxToRem: pxToRem, round: roundWithDeprecationWarning, // TODO v5: remove fontFamily: fontFamily, fontSize: fontSize, fontWeightLight: fontWeightLight, fontWeightRegular: fontWeightRegular, fontWeightMedium: fontWeightMedium, fontWeightBold: fontWeightBold }, variants), other, { clone: false // No need to clone deep }); }