diff --git a/src/components/containers/core/Page/Page.jsx b/src/components/containers/core/Page/Page.jsx index 2c6b49e3..f05ebc38 100644 --- a/src/components/containers/core/Page/Page.jsx +++ b/src/components/containers/core/Page/Page.jsx @@ -9,20 +9,20 @@ import styled from "styled-components"; -import { colors, motion, themedMode, MODE_BRIGHT_SNOW_FLURRY, MODE_DARK_NIGHT_FROST } from "styles/theme"; +import { motion } from "styles/theme"; -const backgroundColor = themedMode({ - [MODE_BRIGHT_SNOW_FLURRY]: colors.background.base[MODE_BRIGHT_SNOW_FLURRY], - [MODE_DARK_NIGHT_FROST]: colors.background.base[MODE_DARK_NIGHT_FROST] -}); +import { baseBackgroundColor } from "../shared/styles"; /** * A basic wrapper component for page content. * + * @author Arctic Ice Studio + * @author Sven Greb + * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/main * @since 0.3.0 */ const Page = styled.main` - background-color: ${backgroundColor}; + background-color: ${baseBackgroundColor}; transition: background-color ${motion.speed.duration.transition.base.themeModeSwitch}ms ease-in-out; `; diff --git a/src/components/containers/core/Section/Section.jsx b/src/components/containers/core/Section/Section.jsx new file mode 100644 index 00000000..b23ee217 --- /dev/null +++ b/src/components/containers/core/Section/Section.jsx @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018-present Arctic Ice Studio + * Copyright (C) 2018-present Sven Greb + * + * Project: Nord Docs + * Repository: https://github.com/arcticicestudio/nord-docs + * License: MIT + */ + +import PropTypes from "prop-types"; +import styled from "styled-components"; + +import { motion } from "styles/theme"; + +import { baseBackgroundColor, primaryBackgroundColor, secondaryBackgroundColor } from "../shared/styles"; + +const variants = { + base: baseBackgroundColor, + primary: primaryBackgroundColor, + secondary: secondaryBackgroundColor +}; + +/** + * A base HTML component that represents a `
` with multiple base style variants. + * + * @author Arctic Ice Studio + * @author Sven Greb + * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section + * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_HTML_sections_and_outlines + * @since 0.3.0 + */ +const Section = styled.section` + position: relative; + background-color: ${({ variant }) => variants[variant]}; + transition: background-color ${motion.speed.duration.transition.base.themeModeSwitch}ms ease-in-out; +`; + +Section.propTypes = { + variant: PropTypes.oneOf(Object.keys(variants)) +}; + +Section.defaultProps = { + variant: "base" +}; + +export default Section; diff --git a/src/components/containers/core/Section/index.js b/src/components/containers/core/Section/index.js new file mode 100644 index 00000000..8319e216 --- /dev/null +++ b/src/components/containers/core/Section/index.js @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2018-present Arctic Ice Studio + * Copyright (C) 2018-present Sven Greb + * + * Project: Nord Docs + * Repository: https://github.com/arcticicestudio/nord-docs + * License: MIT + */ + +export { default } from "./Section"; diff --git a/src/components/containers/core/shared/styles.js b/src/components/containers/core/shared/styles.js new file mode 100644 index 00000000..e510f20f --- /dev/null +++ b/src/components/containers/core/shared/styles.js @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2018-present Arctic Ice Studio + * Copyright (C) 2018-present Sven Greb + * + * Project: Nord Docs + * Repository: https://github.com/arcticicestudio/nord-docs + * License: MIT + */ + +/** + * @file Provides shared container component styles. + * @author Arctic Ice Studio + * @author Sven Greb + * @since 0.3.0 + */ + +import { colors, themedMode, MODE_BRIGHT_SNOW_FLURRY, MODE_DARK_NIGHT_FROST } from "styles/theme"; + +const baseBackgroundColor = themedMode({ + [MODE_BRIGHT_SNOW_FLURRY]: colors.background.base[MODE_BRIGHT_SNOW_FLURRY], + [MODE_DARK_NIGHT_FROST]: colors.background.base[MODE_DARK_NIGHT_FROST] +}); + +const primaryBackgroundColor = themedMode({ + [MODE_BRIGHT_SNOW_FLURRY]: colors.background.sectioning.primary[MODE_BRIGHT_SNOW_FLURRY], + [MODE_DARK_NIGHT_FROST]: colors.background.sectioning.primary[MODE_DARK_NIGHT_FROST] +}); + +const secondaryBackgroundColor = themedMode({ + [MODE_BRIGHT_SNOW_FLURRY]: colors.background.sectioning.secondary[MODE_BRIGHT_SNOW_FLURRY], + [MODE_DARK_NIGHT_FROST]: colors.background.sectioning.secondary[MODE_DARK_NIGHT_FROST] +}); + +export { baseBackgroundColor, primaryBackgroundColor, secondaryBackgroundColor }; diff --git a/src/styles/theme/colors/background.js b/src/styles/theme/colors/background.js index fba9c349..9ce65e4c 100644 --- a/src/styles/theme/colors/background.js +++ b/src/styles/theme/colors/background.js @@ -6,6 +6,7 @@ * Repository: https://github.com/arcticicestudio/nord-docs * License: MIT */ +import { darken, lighten } from "polished"; import nord from "./nord"; import { MODE_BRIGHT_SNOW_FLURRY, MODE_DARK_NIGHT_FROST } from "../constants"; @@ -15,6 +16,16 @@ const base = { [MODE_DARK_NIGHT_FROST]: nord.nord0 }; +const sectioningPrimary = { + [MODE_BRIGHT_SNOW_FLURRY]: lighten(0.045, nord.nord6), + [MODE_DARK_NIGHT_FROST]: nord.nord1 +}; + +const sectioningSecondary = { + [MODE_BRIGHT_SNOW_FLURRY]: lighten(0.06, nord.nord5), + [MODE_DARK_NIGHT_FROST]: darken(0.025, nord.nord0) +}; + /** * Provides theme background colors. * @@ -22,6 +33,12 @@ const base = { * @author Sven Greb * @since 0.2.0 */ -const background = { base }; +const background = { + base, + sectioning: { + primary: sectioningPrimary, + secondary: sectioningSecondary + } +}; export default background; diff --git a/test/components/containers/core/Section/Section.test.jsx b/test/components/containers/core/Section/Section.test.jsx new file mode 100644 index 00000000..2ca094ee --- /dev/null +++ b/test/components/containers/core/Section/Section.test.jsx @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2018-present Arctic Ice Studio + * Copyright (C) 2018-present Sven Greb + * + * Project: Nord Docs + * Repository: https://github.com/arcticicestudio/nord-docs + * License: MIT + */ + +import React, { Fragment } from "react"; + +import Section from "containers/core/Section"; +import { renderWithTheme } from "nord-docs-test-utils"; + +describe("theme styles", () => { + test("matches the snapshot", () => { + const { container } = renderWithTheme( + +
Section Base Background
+
Section Primary Background
+
Section Secondary Background
+
+ ); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/test/components/containers/core/Section/__snapshots__/Section.test.jsx.snap b/test/components/containers/core/Section/__snapshots__/Section.test.jsx.snap new file mode 100644 index 00000000..e51ee8b6 --- /dev/null +++ b/test/components/containers/core/Section/__snapshots__/Section.test.jsx.snap @@ -0,0 +1,42 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`theme styles matches the snapshot 1`] = ` +.c0 { + position: relative; + background-color: #fff; + -webkit-transition: background-color 400ms ease-in-out; + transition: background-color 400ms ease-in-out; +} + +.c1 { + position: relative; + background-color: #fbfbfc; + -webkit-transition: background-color 400ms ease-in-out; + transition: background-color 400ms ease-in-out; +} + +.c2 { + position: relative; + background-color: #f8f9fb; + -webkit-transition: background-color 400ms ease-in-out; + transition: background-color 400ms ease-in-out; +} + +
+
+ Section Base Background +
+
+ Section Primary Background +
+
+ Section Secondary Background +
+
+`;