UNPKG

@navinc/base-react-components

Version:
82 lines 2.83 kB
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; }; import { jsx as _jsx } from "react/jsx-runtime"; import { useEffect } from 'react'; import styled from 'styled-components'; import { deprecationWarning } from '@navinc/utils'; import isRebrand from './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 isRebrand(theme) ? boldVariants.bold : { fontWeight: 'bold' }; } return boldVariants[boldType]; }; const setColor = (light, theme) => { if (isRebrand(theme)) return theme.navNeutralDark; return light ? theme.neutral400 : theme.neutral500; }; const getSize = (theme, { size = 'regular' }) => { var _a; if (isRebrand(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 */ export const Text = styled((_a) => { var { bold, light: _light, size: _size, boldType: _boldType } = _a, props = __rest(_a, ["bold", "light", "size", "boldType"]); useEffect(() => 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 _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 })}; `; Text.displayName = 'Text'; export default Text; //# sourceMappingURL=text.js.map