UNPKG

@navinc/base-react-components

Version:
117 lines (115 loc) 4.65 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Copy = exports.getFromVariableSize = exports.getVariableSize = exports.getFromSize = exports.getSize = exports.sizeVariants = exports.defaultSize = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const styled_components_1 = __importDefault(require("styled-components")); const prop_types_1 = __importDefault(require("prop-types")); const is_rebrand_1 = __importDefault(require("./is-rebrand")); exports.defaultSize = 'md'; exports.sizeVariants = { xxs: { fontSize: '10px', lineHeight: '14px', }, xs: { fontSize: '12px', lineHeight: '18px', }, sm: { fontSize: '14px', lineHeight: '20px', }, md: { fontSize: '16px', lineHeight: '24px', }, lg: { fontSize: '18px', lineHeight: '27px', }, }; const boldVariants = { regular: { fontWeight: 400, }, semiBold: { fontWeight: 600, }, bold: { fontWeight: 800, }, }; const sizes = Object.keys(exports.sizeVariants); const getSize = ({ size = exports.defaultSize }) => exports.sizeVariants[size] || exports.sizeVariants.md; exports.getSize = getSize; const getBoldVariant = (props) => { const { bold, $bold, theme, boldType } = props; const isBold = bold || $bold; if (isBold) { return (0, is_rebrand_1.default)(theme) ? boldVariants.bold : { fontWeight: 'bold' }; } return boldVariants[boldType]; }; const getFromSize = (prop, fallback = '') => ({ size }) => { var _a; return (_a = (0, exports.getSize)({ size })[prop]) !== null && _a !== void 0 ? _a : fallback; }; exports.getFromSize = getFromSize; const getVariableSize = ({ size = exports.defaultSize, shouldScaleFont, }) => { // protection against invalid size values size = exports.sizeVariants[size] ? size : exports.defaultSize; // get the next size up. // if there is no larger size, stay the same size return shouldScaleFont ? exports.sizeVariants[sizes[sizes.indexOf(size) + 1] || size] : exports.sizeVariants[size] || exports.sizeVariants.md; }; exports.getVariableSize = getVariableSize; const getFromVariableSize = (prop, fallback = '') => ({ size, shouldScaleFont }) => { var _a; return (_a = (0, exports.getVariableSize)({ size, shouldScaleFont })[prop]) !== null && _a !== void 0 ? _a : fallback; }; exports.getFromVariableSize = getFromVariableSize; const setColor = (light, theme) => { if ((0, is_rebrand_1.default)(theme)) return light ? theme.navNeutral400 : theme.navNeutralDark; return light ? theme.neutral400 : theme.neutral500; }; exports.Copy = (0, styled_components_1.default)((_a) => { var { bold: _bold, shouldScaleFont: _shouldScaleFont, boldType: _boldType, light: _light } = _a, props = __rest(_a, ["bold", "shouldScaleFont", "boldType", "light"]); return ((0, jsx_runtime_1.jsx)("p", Object.assign({}, props))); }).withConfig({ displayName: "brc-sc-Copy", componentId: "brc-sc-2lj35g" }) ` display: block; margin: 0; padding: 0; color: ${({ light, theme }) => setColor(light, theme)}; font-family: ${({ theme }) => theme.fontPrimary}; font-size: ${(0, exports.getFromSize)('fontSize')}; ${({ bold, theme, boldType }) => getBoldVariant({ bold, theme, boldType })}; line-height: ${(0, exports.getFromSize)('lineHeight')}; strong { font-family: ${({ theme }) => theme.fontPrimary}; } @media (${({ theme }) => theme.forLargerThanPhone}) { font-size: ${(0, exports.getFromVariableSize)('fontSize')}; line-height: ${(0, exports.getFromVariableSize)('lineHeight')}; } `; exports.Copy.displayName = 'Copy'; exports.Copy.propTypes = { bold: prop_types_1.default.bool, light: prop_types_1.default.bool, size: prop_types_1.default.oneOf(sizes), shouldScaleFont: prop_types_1.default.bool, }; exports.Copy.defaultProps = { size: exports.defaultSize, }; exports.default = exports.Copy; //# sourceMappingURL=copy.js.map