UNPKG

@navinc/base-react-components

Version:
104 lines (102 loc) 3.68 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 styled from 'styled-components'; import propTypes from 'prop-types'; export const defaultSize = 'md'; export const 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(sizeVariants); export const getSize = ({ size = defaultSize }) => sizeVariants[size] || sizeVariants.md; const getBoldVariant = (props) => { const { bold, $bold, boldType } = props; const isBold = bold || $bold; if (isBold) { return boldVariants.bold; } return boldVariants[boldType]; }; export const getFromSize = (prop, fallback = '') => ({ size }) => { var _a; return (_a = getSize({ size })[prop]) !== null && _a !== void 0 ? _a : fallback; }; export const getVariableSize = ({ size = defaultSize, shouldScaleFont, }) => { // protection against invalid size values size = sizeVariants[size] ? size : defaultSize; // get the next size up. // if there is no larger size, stay the same size return shouldScaleFont ? sizeVariants[sizes[sizes.indexOf(size) + 1] || size] : sizeVariants[size] || sizeVariants.md; }; export const getFromVariableSize = (prop, fallback = '') => ({ size, shouldScaleFont }) => { var _a; return (_a = getVariableSize({ size, shouldScaleFont })[prop]) !== null && _a !== void 0 ? _a : fallback; }; const setColor = (light, theme) => (light ? theme.navNeutral400 : theme.navNeutralDark); /** * @deprecated Use `CopyVariant as Copy` instead. This component will be removed in a future release. CopyVariant replaces Header, Copy, and Text. */ export const Copy = styled((_a) => { var { bold: _bold, shouldScaleFont: _shouldScaleFont, boldType: _boldType, light: _light } = _a, props = __rest(_a, ["bold", "shouldScaleFont", "boldType", "light"]); return (_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: ${getFromSize('fontSize')}; ${({ bold, boldType }) => getBoldVariant({ bold, boldType })}; line-height: ${getFromSize('lineHeight')}; strong { font-family: ${({ theme }) => theme.fontPrimary}; } @media (${({ theme }) => theme.forLargerThanPhone}) { font-size: ${getFromVariableSize('fontSize')}; line-height: ${getFromVariableSize('lineHeight')}; } `; Copy.displayName = 'Copy'; Copy.propTypes = { bold: propTypes.bool, light: propTypes.bool, size: propTypes.oneOf(sizes), shouldScaleFont: propTypes.bool, }; Copy.defaultProps = { size: defaultSize, }; //# sourceMappingURL=copy.js.map