-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement base styled sectioning component
This commit implements a base HTML component that represents a `<section>` (1) with multiple base style variants. References: (1) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section Associated epic: GH-63 GH-78
- Loading branch information
1 parent
c4e1aa8
commit b930e9f
Showing
7 changed files
with
182 additions
and
7 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
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,46 @@ | ||
/* | ||
* Copyright (C) 2018-present Arctic Ice Studio <development@arcticicestudio.com> | ||
* Copyright (C) 2018-present Sven Greb <development@svengreb.de> | ||
* | ||
* 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 `<section>` with multiple base style variants. | ||
* | ||
* @author Arctic Ice Studio <development@arcticicestudio.com> | ||
* @author Sven Greb <development@svengreb.de> | ||
* @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; |
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,10 @@ | ||
/* | ||
* Copyright (C) 2018-present Arctic Ice Studio <development@arcticicestudio.com> | ||
* Copyright (C) 2018-present Sven Greb <development@svengreb.de> | ||
* | ||
* Project: Nord Docs | ||
* Repository: https://github.com/arcticicestudio/nord-docs | ||
* License: MIT | ||
*/ | ||
|
||
export { default } from "./Section"; |
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,34 @@ | ||
/* | ||
* Copyright (C) 2018-present Arctic Ice Studio <development@arcticicestudio.com> | ||
* Copyright (C) 2018-present Sven Greb <development@svengreb.de> | ||
* | ||
* Project: Nord Docs | ||
* Repository: https://github.com/arcticicestudio/nord-docs | ||
* License: MIT | ||
*/ | ||
|
||
/** | ||
* @file Provides shared container component styles. | ||
* @author Arctic Ice Studio <development@arcticicestudio.com> | ||
* @author Sven Greb <development@svengreb.de> | ||
* @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 }; |
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,26 @@ | ||
/* | ||
* Copyright (C) 2018-present Arctic Ice Studio <development@arcticicestudio.com> | ||
* Copyright (C) 2018-present Sven Greb <development@svengreb.de> | ||
* | ||
* 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( | ||
<Fragment> | ||
<Section>Section Base Background</Section> | ||
<Section variant="primary">Section Primary Background</Section> | ||
<Section variant="secondary">Section Secondary Background</Section> | ||
</Fragment> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
test/components/containers/core/Section/__snapshots__/Section.test.jsx.snap
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,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; | ||
} | ||
<div> | ||
<section | ||
class="c0" | ||
> | ||
Section Base Background | ||
</section> | ||
<section | ||
class="c1" | ||
> | ||
Section Primary Background | ||
</section> | ||
<section | ||
class="c2" | ||
> | ||
Section Secondary Background | ||
</section> | ||
</div> | ||
`; |