-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement global and normalization CSS styles
This commit implements global and normalization CSS styles using "styled-components" `css` API. They extend "modern-normalize" and define, next to the browser normalization, styles for the available global themes. In order to use fonts in "Nord Docs" style & themes (implemented in GH-54) the basic properties and values have been added and integrated into these base styles. To inject global styles, styled-components v4 `createglobalstyle` (1) API has been used to create a `<GlobalStyle>` component that injects theme styles and "styled-modern-normalize" (2) globally. References: (1) https://www.styled-components.com/docs/api#createglobalstyle (2): https://github.com/arcticicestudio/styled-modern-normalize Associated epics: GH-51, GH-2 GH-53
- Loading branch information
1 parent
0a468ab
commit 66db7eb
Showing
5 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,42 @@ | |
|
||
import React, { Fragment } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { createGlobalStyle } from "styled-components"; | ||
import modernNormalize from "styled-modern-normalize"; | ||
|
||
import { global, normalize } from "styles/theme"; | ||
|
||
/* eslint-disable import/extensions */ | ||
import "inter-ui"; | ||
import "typeface-rubik"; | ||
import "typeface-source-code-pro"; | ||
/* eslint-enable import/extensions */ | ||
|
||
/** | ||
* A React component that injects global CSS inline styles in page headers. | ||
* | ||
* @see https://www.styled-components.com/docs/api#createglobalstyle | ||
* @since 0.2.0 | ||
*/ | ||
const GlobalStyle = createGlobalStyle` | ||
${modernNormalize}; | ||
${global}; | ||
${normalize}; | ||
`; | ||
|
||
/** | ||
* The root container. | ||
* The root container with injected global CSS styles. | ||
* | ||
* @author Arctic Ice Studio <[email protected]> | ||
* @author Sven Greb <[email protected]> | ||
* @since 0.1.0 | ||
*/ | ||
const Root = ({ children }) => <Fragment>{children}</Fragment>; | ||
const Root = ({ children }) => ( | ||
<Fragment> | ||
<GlobalStyle /> | ||
<Fragment>{children}</Fragment> | ||
</Fragment> | ||
); | ||
|
||
Root.propTypes = { | ||
children: PropTypes.node.isRequired | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]> | ||
* Copyright (C) 2018-present Sven Greb <[email protected]> | ||
* | ||
* Project: Nord Docs | ||
* Repository: https://github.com/arcticicestudio/nord-docs | ||
* License: MIT | ||
*/ | ||
|
||
/** | ||
* @file Global CSS styles. | ||
* @author Arctic Ice Studio <[email protected]> | ||
* @author Sven Greb <[email protected]> | ||
* @since 0.2.0 | ||
*/ | ||
|
||
import { css } from "styled-components"; | ||
|
||
import typography from "./typography"; | ||
|
||
const global = css` | ||
html { | ||
font-size: ${typography.sizes.root}px; | ||
} | ||
body { | ||
font-family: ${typography.typefaces.main}; | ||
font-size: ${typography.sizes.msBase}rem; | ||
font-weight: ${typography.sizes.weight}; | ||
line-height: ${typography.sizes.lineHeight}; | ||
scroll-behavior: smooth; | ||
} | ||
`; | ||
|
||
export default global; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]> | ||
* Copyright (C) 2018-present Sven Greb <[email protected]> | ||
* | ||
* Project: Nord Docs | ||
* Repository: https://github.com/arcticicestudio/nord-docs | ||
* License: MIT | ||
*/ | ||
|
||
/** | ||
* @file Custom normalizations for browser default CSS styles. | ||
* @author Arctic Ice Studio <[email protected]> | ||
* @author Sven Greb <[email protected]> | ||
* @since 0.2.0 | ||
*/ | ||
|
||
import { css } from "styled-components"; | ||
|
||
const normalize = css` | ||
nav ol, | ||
nav ul { | ||
/* Don't decorate list items. */ | ||
list-style: none; | ||
} | ||
textarea { | ||
/* Only allow veritcal resizing to prevent layout shifting. */ | ||
resize: vertical; | ||
} | ||
`; | ||
|
||
export default normalize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
* @file Typefaces and font styles. | ||
* @author Arctic Ice Studio <[email protected]> | ||
* @author Sven Greb <[email protected]> | ||
* @see https://material.io/design/typography/understanding-typography.html | ||
* @since 0.2.0 | ||
*/ | ||
|
||
|
@@ -28,9 +29,9 @@ | |
*/ | ||
const typefaces = { | ||
main: "Rubik", | ||
monospace: "Source Code Pro", | ||
straight: "Inter UI", | ||
straightVariable: "Inter UI var", | ||
monospace: "Source Code Pro" | ||
straightVariable: "Inter UI var" | ||
}; | ||
|
||
/** | ||
|
@@ -43,8 +44,10 @@ const typefaces = { | |
* @type {object} | ||
*/ | ||
const sizes = { | ||
lineHeight: 1.5, | ||
msBase: 1, | ||
msBaseUnit: "em", | ||
msBaseUnit: "rem", | ||
msName: "majorSecond", | ||
msRatio: 1.125, | ||
root: 16, | ||
rootUnit: "px", | ||
|