@cimpress/react-components
Version:
React components to support the MCP styleguide
288 lines (248 loc) • 7.19 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GlobalStyles = void 0;
/* eslint-disable react/jsx-no-useless-fragment */
const react_1 = __importStar(require("react"));
const css_1 = require("@emotion/css");
const cvar_1 = __importDefault(require("./theme/cvar"));
const CIM_UI_STYLE_ROOT = '[data-cim-style-root]';
function createCompatibleSelector(...selectors) {
return selectors
.map(selector => `${selector}:where(:not(${CIM_UI_STYLE_ROOT}):not(${CIM_UI_STYLE_ROOT} ${selector}))`)
.join(', ');
}
const globalStyles = (0, css_1.css) `
${createCompatibleSelector('*')} {
margin: 0;
padding: 0;
font-size: 1em;
font-family: inherit;
}
${createCompatibleSelector('body')} {
font: ${(0, cvar_1.default)('text-paragraph-default')};
color: ${(0, cvar_1.default)('color-text-default')};
}
${createCompatibleSelector('h1', 'h2', 'h3', 'h4', 'h5', 'h6', '.h1', '.h2', '.h3', '.h4', '.h5', '.h6', '.h7')} {
margin-top: 1em;
margin-bottom: 0.5em;
}
${createCompatibleSelector('h1', '.h1')} {
font: ${(0, cvar_1.default)('text-h1')};
}
${createCompatibleSelector('h2', '.h2')} {
font: ${(0, cvar_1.default)('text-h2')};
}
${createCompatibleSelector('h3', '.h3')} {
font: ${(0, cvar_1.default)('text-h3')};
}
${createCompatibleSelector('h4', '.h4')} {
font: ${(0, cvar_1.default)('text-h4')};
}
${createCompatibleSelector('h5', '.h5')} {
font: ${(0, cvar_1.default)('text-h5')};
}
${createCompatibleSelector('h6', '.h6')} {
font: ${(0, cvar_1.default)('text-h6')};
text-transform: uppercase;
}
${createCompatibleSelector('.h7')} {
font: ${(0, cvar_1.default)('text-h7')};
color: ${(0, cvar_1.default)('color-text-label')};
text-transform: uppercase;
}
${createCompatibleSelector('a')} {
color: ${(0, cvar_1.default)('color-text-interactive')};
text-decoration: none;
&:hover {
color: ${(0, cvar_1.default)('color-text-hover')};
text-decoration: underline;
}
&:active {
color: ${(0, cvar_1.default)('color-text-selected')};
text-decoration: underline;
}
}
${createCompatibleSelector('code', 'kbd', 'pre', 'samp')} {
font-family: ${(0, cvar_1.default)('font-monospace')};
}
${createCompatibleSelector('code')} {
padding: 2px 4px;
font-size: 90%;
border-radius: 2px;
}
${createCompatibleSelector('pre')} {
display: block;
padding: ${(0, cvar_1.default)('spacing-8')}px;
margin: 0 0 9px;
font-size: 13px;
line-height: 1.286;
word-break: break-all;
word-wrap: break-word;
border: 1px solid;
border-radius: 2px;
}
${createCompatibleSelector('pre code')} {
padding: 0;
font-size: inherit;
color: inherit;
white-space: pre-wrap;
background-color: transparent;
border-radius: 0;
}
`;
// Modified version of modern-normalize v1.1.0 (https://github.com/sindresorhus/modern-normalize)
// CSS comments were removed to save on bundle size
// Removed some rules to avoid repetition in `globalStyles`
const modernNormalizeStyles = (0, css_1.css) `
*,
::before,
::after {
box-sizing: border-box;
}
html {
line-height: 1.15;
-webkit-text-size-adjust: 100%;
-moz-tab-size: 4;
tab-size: 4;
}
${createCompatibleSelector('body')} {
margin: 0;
}
${createCompatibleSelector('hr')} {
height: 0;
color: inherit;
}
${createCompatibleSelector('abbr[title]')} {
text-decoration: underline dotted;
}
b,
strong {
font-weight: bolder;
}
code,
kbd,
samp,
pre {
font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
font-size: 1em;
}
${createCompatibleSelector('small')} {
font-size: 85%;
}
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
${createCompatibleSelector('table')} {
text-indent: 0;
border-color: inherit;
}
button,
input,
optgroup,
select,
textarea {
font-family: inherit;
font-size: 100%;
line-height: 1.15;
margin: 0;
}
${createCompatibleSelector('button', 'select')} {
text-transform: none;
}
${createCompatibleSelector('button', "[type='button']", "[type='reset']", "[type='submit']")} {
-webkit-appearance: button;
cursor: pointer;
}
::-moz-focus-inner {
border-style: none;
padding: 0;
}
:-moz-focusring {
outline: 1px dotted ButtonText;
}
:-moz-ui-invalid {
box-shadow: none;
}
legend {
padding: 0;
}
progress {
vertical-align: baseline;
}
::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
height: auto;
}
[type='search'] {
-webkit-appearance: textfield;
outline-offset: -2px;
}
::-webkit-search-decoration {
-webkit-appearance: none;
}
::-webkit-file-upload-button {
-webkit-appearance: button;
font: inherit;
}
summary {
display: list-item;
}
`;
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
(0, css_1.injectGlobal) `
${modernNormalizeStyles};
${globalStyles};
`;
// TODO: migrate to Emotion v11 which uses the `<Global />` component for global styles
const GlobalStyles = () => {
// Inject Google Fonts stylesheet
(0, react_1.useLayoutEffect)(() => {
const existingLink = document.querySelector('link[data-ccl-font="true"]');
if (existingLink)
return;
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap';
link.dataset.cclFont = 'true';
document.head.appendChild(link);
}, []);
return react_1.default.createElement(react_1.default.Fragment, null);
};
exports.GlobalStyles = GlobalStyles;
//# sourceMappingURL=GlobalStyles.js.map