@navinc/base-react-components
Version:
Nav's Pattern Library
82 lines (80 loc) • 2.98 kB
JavaScript
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 sizes = Object.keys(sizeVariants);
export const getSize = ({ size = defaultSize }) => sizeVariants[size] || sizeVariants.md;
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; };
export const Copy = styled((_a) => {
var { bold, shouldScaleFont, light } = _a, props = __rest(_a, ["bold", "shouldScaleFont", "light"]);
return _jsx("p", Object.assign({}, props), void 0);
}) `
display: block;
margin: 0;
padding: 0;
color: ${({ light, theme }) => (light ? theme.neutral400 : theme.neutral500)};
font-family: postgrotesk, Roboto, Helvetica, sans-serif;
font-size: ${getFromSize('fontSize')};
font-weight: ${({ bold }) => (bold ? 'bold' : 'normal')};
line-height: ${getFromSize('lineHeight')};
strong {
font-family: postgrotesk, Roboto, Helvetica, sans-serif;
}
@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,
};
export default Copy;
//# sourceMappingURL=copy.js.map