UNPKG

@navinc/base-react-components

Version:
88 lines 3.25 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.Text = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const styled_components_1 = __importDefault(require("styled-components")); const utils_1 = require("@navinc/utils"); const is_rebrand_1 = __importDefault(require("./is-rebrand")); const sizeVariants = { small: { fontSize: '12px', lineHeight: '18px', }, medium: { fontSize: '14px', lineHeight: '20px', }, regular: { fontSize: '16px', lineHeight: '24px', }, large: { fontSize: '18px', lineHeight: '28px', }, }; const boldVariants = { regular: { fontWeight: 400, }, semiBold: { fontWeight: 600, }, bold: { fontWeight: 800, }, }; 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 setColor = (light, theme) => { if ((0, is_rebrand_1.default)(theme)) return theme.navNeutralDark; return light ? theme.neutral400 : theme.neutral500; }; const getSize = (theme, { size = 'regular' }) => { var _a; if ((0, is_rebrand_1.default)(theme)) { return (_a = sizeVariants[size]) !== null && _a !== void 0 ? _a : sizeVariants.regular; } return { fontSize: 'inherit', lineHeight: 'inherit' }; }; /* Adding a $ to props makes them a transient prop see https://styled-components.com/docs/api#transient-props */ exports.Text = (0, styled_components_1.default)((_a) => { var { bold, light: _light, size: _size, boldType: _boldType } = _a, props = __rest(_a, ["bold", "light", "size", "boldType"]); (0, react_1.useEffect)(() => (0, utils_1.deprecationWarning)(bold, `The \`bold\` prop on Base React Component Text component is deprecated and support will be removed in a future version. Please use \`$bold\` instead.`), [bold]); return (0, jsx_runtime_1.jsx)("span", Object.assign({}, props)); }).withConfig({ displayName: "brc-sc-Text", componentId: "brc-sc-emkmup" }) ` color: ${({ light, theme }) => setColor(light, theme)}; font-family: ${({ theme }) => theme.fontPrimary}; ${({ theme, size }) => getSize(theme, { size })}; ${({ bold, $bold, theme, boldType }) => getBoldVariant({ bold, $bold, theme, boldType })}; `; exports.Text.displayName = 'Text'; exports.default = exports.Text; //# sourceMappingURL=text.js.map