Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color section to styleguide #2030

Merged
merged 15 commits into from
Jan 16, 2020
8 changes: 8 additions & 0 deletions packages/venia-styleguide/src/components/Palette/Hue.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.root {
display: grid;
gap: 1.5rem;
grid-template-columns: repeat(auto-fill, 12rem);
justify-content: center;
max-width: 52.5rem;
min-width: 12rem;
}
16 changes: 16 additions & 0 deletions packages/venia-styleguide/src/components/Palette/Hue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';

import Tone from './Tone';
import classes from './Hue.css';

const Hue = props => {
const { hue, tones } = props;

const toneElements = Array.from(tones, ([tone, value]) => (
<Tone key={tone} hue={hue} tone={tone} value={value} />
));

return <div className={classes.root}>{toneElements}</div>;
};

export default Hue;
9 changes: 9 additions & 0 deletions packages/venia-styleguide/src/components/Palette/Palette.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.root {
background-color: rgb(var(--venia-global-color-gray-100));
border-radius: 4px;
display: grid;
gap: 4.5rem;
justify-content: center;
margin-bottom: 5rem;
padding: 3rem 1.5rem;
}
17 changes: 17 additions & 0 deletions packages/venia-styleguide/src/components/Palette/Palette.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

import Hue from './Hue';
import classes from './Palette.css';

const Palette = props => {
const { colors } = props;
const { hues } = colors;

const hueElements = Array.from(hues, ([hue, tones]) => (
<Hue key={hue} hue={hue} tones={tones} />
));

return <figure className={classes.root}>{hueElements}</figure>;
};

export default Palette;
31 changes: 31 additions & 0 deletions packages/venia-styleguide/src/components/Palette/Tone.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.root {
composes: detail from '../../styles/typography.css';
align-content: start;
background-color: rgb(var(--tone));
border: 1px solid rgb(var(--venia-global-color-gray-300));
border-radius: 4px;
display: grid;
font-weight: var(--venia-global-text-fontWeight-bold);
height: 6.75rem;
padding: 1rem;
text-transform: uppercase;
width: 12rem;
}

.root--balance-light {
composes: root;
}

.root--balance-dark {
composes: root;
color: white;
}

.label {
font-size: var(--venia-typography-detail-S-fontSize);
letter-spacing: 0.5px;
}

.value {
font-size: var(--venia-typography-detail-L-fontSize);
}
44 changes: 44 additions & 0 deletions packages/venia-styleguide/src/components/Palette/Tone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useMemo } from 'react';

import finalizeClasses from '../../util/finalizeClasses';
import classes from './Tone.css';

const getHex = channel => parseInt(channel).toString(16);

const getSRGB = channel => {
const factor = channel / 255;

return factor <= 0.03928
? factor / 12.92
: Math.pow((factor + 0.055) / 1.055, 2.4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you drop a comment about these numbers?

};

const getLightness = channels => {
const [r, g, b] = channels.map(getSRGB);

return r * 0.2126 + g * 0.7152 + b * 0.0722;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you drop a comment about these numbers?

};

const WHITE = getLightness([255, 255, 255]);

const Tone = props => {
const { hue, tone, value } = props;
const style = { '--tone': value };

const channels = useMemo(() => value.split(' '), [value]);
const lightness = getLightness(channels);
const ratio = WHITE / (lightness + 0.05);
const balance = ratio < 3 ? 'light' : 'dark';

const finalClasses = finalizeClasses(classes, { balance });
const hex = channels.map(channel => getHex(channel)).join('');

return (
<div className={finalClasses.get('root')} style={style}>
<span className={classes.label}>{`${hue} ${tone}`}</span>
<span className={classes.value}>{`#${hex}`}</span>
</div>
);
};

export default Tone;
1 change: 1 addition & 0 deletions packages/venia-styleguide/src/components/Palette/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Palette';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.root {
border: none;
height: 1rem;
height: 2rem;
margin: 1rem;
}
30 changes: 30 additions & 0 deletions packages/venia-styleguide/src/pages/color/Color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Article from "../../components/Article"
import Palette from "../../components/Palette"
import Section from "../../components/Section"
import TableOfContents from "../../components/TableOfContents"

import Grays from "./sections/Grays"
import data from "./colors.yml"

export const colors = data

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce
quis euismod nisi. Morbi metus mauris, volutpat ac aliquet eget,
laoreet vel tortor. Pellentesque commodo tellus nibh, vitae
varius lectus pharetra in. Aliquam quis nisi ligula. Proin sit
amet mauris ac lacus efficitur varius eget in urna. Ut sagittis
feugiat ex et dictum. Nam ut tempor urna, at dapibus erat.
Aenean ac dui a tellus venenatis accumsan.

***

<Palette colors={colors} />
<Section title="Table of contents">
<TableOfContents />
</Section>
<Section title="Grays">
<Grays />
</Section>

export const title = "Color"
export default Article
30 changes: 30 additions & 0 deletions packages/venia-styleguide/src/pages/color/colors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

hues: !!pairs
- gray: !!pairs
- 50: "255 255 255"
- 75: "250 250 250"
- 100: "245 245 245"
- 200: "235 235 235"
- 300: "224 224 224"
- 400: "204 204 204"
- 500: "163 163 163"
- 600: "122 122 122"
- 700: "82 82 82"
- 800: "61 61 61"
- 900: "31 31 31"
- red: !!pairs
- 400: "197 27 72"
- 500: "188 16 62"
- 600: "176 7 52"
- 700: "163 0 44"
- sea: !!pairs
- 400: 224 246 242
- 500: 215 244 239
- 600: 206 243 236
- 700: 197 242 234
- teal: !!pairs
- 400: "22 155 162"
- 500: "13 143 150"
- 600: "6 131 137"
- 700: "0 115 120"
6 changes: 1 addition & 5 deletions packages/venia-styleguide/src/pages/color/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import React from 'react';

const Page = () => <span>Color</span>;

export default Page;
export { default } from './Color';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### Generating the grays

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis euismod nisi. Morbi metus mauris, volutpat ac aliquet eget, laoreet vel tortor. Pellentesque commodo tellus nibh, vitae varius lectus pharetra in.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### Using the gray system

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis euismod nisi. Morbi metus mauris, volutpat ac aliquet eget, laoreet vel tortor. Pellentesque commodo tellus nibh, vitae varius lectus pharetra in.
14 changes: 14 additions & 0 deletions packages/venia-styleguide/src/pages/color/sections/Grays/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Columns from "../../../../components/Columns"
import Methodology from "./Methodology"
import Usage from "./Usage"

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis euismod nisi. Morbi metus mauris, volutpat ac aliquet eget, laoreet vel tortor. Pellentesque commodo tellus nibh, vitae varius lectus pharetra in.

***

<Columns>
<Usage />
</Columns>
<Columns>
<Methodology />
</Columns>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Article from "../../components/Article"
import Paragraph from "../../components/Paragraph"
import Section from "../../components/Section"
import TableOfContents from "../../components/TableOfContents"

Expand Down
6 changes: 3 additions & 3 deletions packages/venia-styleguide/src/styles/reset.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
}

:global a {
color: rgb(var(--venia-brand-color-1-400));
color: rgb(var(--venia-brand-color-1-700));
cursor: pointer;
outline: none;
text-decoration: none;
}

:global body {
background-color: white;
color: rgb(75 75 75);
background-color: rgb(var(--venia-global-color-gray-50));
color: rgb(var(--venia-global-color-gray-900));
font-family: var(--venia-global-text-fontFamily-sansSerif);
line-height: var(--venia-global-text-lineHeight-100);
-moz-osx-font-smoothing: grayscale;
Expand Down
26 changes: 25 additions & 1 deletion packages/venia-styleguide/src/styles/tokens.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
/* global tokens */
:global :root {
/* color */
--venia-global-color-teal-400: 0 115 120;
--venia-global-color-gray-50: 255 255 255; /* ffffff 100% 1.09 */
--venia-global-color-gray-75: 250 250 250; /* fafafa 98% 1.04 */
--venia-global-color-gray-100: 245 245 245; /* f5f5f5 96% 1.00 */
--venia-global-color-gray-200: 235 235 235; /* ebebeb 92% 1.09 */
--venia-global-color-gray-300: 224 224 224; /* e0e0e0 88% 1.21 */
--venia-global-color-gray-400: 204 204 204; /* cccccc 80% 1.47 */
--venia-global-color-gray-500: 163 163 163; /* a3a3a3 64% 2.31 */
--venia-global-color-gray-600: 122 122 122; /* 7a7a7a 48% 3.93 */
--venia-global-color-gray-700: 82 82 82; /* 525252 32% 7.16 */
--venia-global-color-gray-800: 61 61 61; /* 3d3d3d 24% 9.96 */
--venia-global-color-gray-900: 31 31 31; /* 1f1f1f 12% 15.11 */
--venia-global-color-red-400: 197 27 72; /* c51b48 44% 5.55 */
--venia-global-color-red-500: 188 16 62; /* bc103e 40% 6.13 */
--venia-global-color-red-600: 176 7 52; /* b00734 36% 6.87 */
--venia-global-color-red-700: 163 0 44; /* a3002c 32% 7.75 */
--venia-global-color-sea-400: 224 246 242; /* e0f6f2 92% 1.07 */
--venia-global-color-sea-500: 215 244 239; /* d7f4ef 90% 1.11 */
--venia-global-color-sea-600: 206 243 236; /* cef3ec 88% 1.13 */
--venia-global-color-sea-700: 197 242 234; /* c5f2ea 86% 1.16 */
--venia-global-color-teal-400: 22 155 162; /* 169ba2 36% 3.22 */
--venia-global-color-teal-500: 13 143 150; /* 0d8f96 32% 3.73 */
--venia-global-color-teal-600: 6 131 137; /* 068389 28% 4.35 */
--venia-global-color-teal-700: 0 115 120; /* 007378 24% 5.40 */

/* font family */
--venia-global-text-fontFamily-sansSerif: 'Muli', sans-serif;
/* font size */
Expand Down Expand Up @@ -35,6 +58,7 @@
:global :root {
/* colors */
--venia-brand-color-1-400: var(--venia-global-color-teal-400);
--venia-brand-color-1-700: var(--venia-global-color-teal-700);
/* typography */
/* heading */
--venia-typography-heading-XL-fontSize: var(
Expand Down