Skip to content

Commit

Permalink
add color docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mgs95 committed Jul 21, 2020
1 parent f7c88a0 commit 3c1aafa
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 1 deletion.
53 changes: 52 additions & 1 deletion docs/colors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,55 @@ name: Colors
menu: Design
---

# Color guidelines
import Colors from '../src/docz-components/Colors/Colors';
import FontColor from '../src/docz-components/FontColor/FontColor';

# Colors


## Usage

We are using SCSS to set colors. There is a function (`palette`) that extract the desired color. To use the function you need to import
```_colors.scss``` and call `palette` function with the name of the color and the range.

> range can be omitted when range is 500 (default)
Same applies with font colors, in this case the function is called ```font-color``` and does not require a range.


#### Example:

``` scss
// ComponentName.module.scss

@import '../../styles/colors';

.selector {
background-color: palette(base, 700);
border-color: palette(alert); // you can imit the range for default color (500)

color: font-color(regular); // range not required in font colors
}
```

## Color palettes

<div style={{ display: 'flex', justifyContent: 'space-between', margin: '0 50px', flexWrap: 'wrap' }}>
<Colors color="base" />
<Colors color="lowlight" />
<Colors color="feedback" />
<Colors color="highlight" />
<Colors color="success" />
<Colors color="alert" />
<Colors color="error" />
</div>

## Font colors

<FontColor color="light" />
<FontColor color="highlight" />
<FontColor color="lowlight" />
<FontColor color="disabled" />
<FontColor color="regular" />
<FontColor color="grey" />
<FontColor color="dark" />
59 changes: 59 additions & 0 deletions src/docz-components/Colors/Colors.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@import '../../styles/variables';
@import '../../styles/colors';

$colors: base, error, highlight, lowlight, success, feedback, alert;
$ranges: 100, 200, 300, 400, 500, 600, 700, 800, 900;

@function set-text-color($color) {
@if (lightness($color) > 50) {
@return font-color(dark);
} @else {
@return font-color(light);
}
}

@each $color in $colors {
@each $range in $ranges {
.#{$color}#{$range} {
$act-color: palette($color, $range);

background-color: $act-color;
color: set-text-color($act-color);

code::after {
content: '#{$act-color}';
}

font-weight: 400;
@if $range == 500 {
font-weight: 600;
}
}
}
}

.wrapper {
width: 300px;
position: relative;
}

.title {
width: 100%;
text-align: center;
text-transform: capitalize;
margin-bottom: $grid-unit;
}

.container {
font-size: 15px;
margin-bottom: 4 * $grid-unit;
}

.color {
height: 5 * $grid-unit;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 $grid-unit;
}
47 changes: 47 additions & 0 deletions src/docz-components/Colors/Colors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import cx from 'classnames'
import styles from './Colors.module.scss'

type ColorNames =
| 'base'
| 'error'
| 'highlight'
| 'lowlight'
| 'success'
| 'feedback'
| 'alert'

type ColorProps = {
color: ColorNames
range: number
}
function Color({ color, range }: ColorProps) {
return (
<div className={cx(styles.color, styles[`${color}${range}`])}>
<span>{range === 500 ? color : `${color}-${range}`}</span>
<code />
</div>
)
}

type Props = {
color: ColorNames
}
function Colors({ color }: Props) {
const ranges = Array(9)
.fill(0)
.map((_, i) => i * 100 + 100)

return (
<div className={styles.wrapper}>
<div className={styles.title}>{color}</div>
<div className={styles.container}>
{ranges.map((range) => (
<Color color={color} range={range} />
))}
</div>
</div>
)
}

export default Colors
36 changes: 36 additions & 0 deletions src/docz-components/FontColor/FontColor.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@import '../../styles/variables';
@import '../../styles/colors';

$colors: light, highlight, lowlight, regular, grey, dark, disabled;

@function set-bg-color($color) {
@if (lightness($color) > 20) {
@return palette(base, 900);
} @else {
@return palette(base, 200);
}
}

@each $color in $colors {
.#{$color} {
$act-color: font-color($color);

color: $act-color;
background-color: set-bg-color($act-color);

code::after {
content: '#{$act-color}';
}

font-weight: 400;
}
}

.fontColor {
height: 5 * $grid-unit;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 $grid-unit;
}
26 changes: 26 additions & 0 deletions src/docz-components/FontColor/FontColor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import cx from 'classnames'
import styles from './FontColor.module.scss'

type ColorNames =
| 'light'
| 'highlight'
| 'lowlight'
| 'regular'
| 'grey'
| 'dark'
| 'disabled'

type Props = {
color: ColorNames
}
function FontColor({ color }: Props) {
return (
<div className={cx(styles.fontColor, styles[color])}>
<span>{color}</span>
<code />
</div>
)
}

export default FontColor
2 changes: 2 additions & 0 deletions src/gatsby-theme-docz/theme/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '../../../../src/styles/docz.global.scss'

import * as colors from './dark-theme-colors'

import baseTheme from 'gatsby-theme-docz/src/theme/index'
Expand Down
10 changes: 10 additions & 0 deletions src/styles/docz.global.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import './colors';
@import '~typeface-montserrat/index.css';
@import '~typeface-roboto-mono/index.css';

@import './variables';
@import './mixins';

* {
font-family: $font-family;
}

0 comments on commit 3c1aafa

Please # to comment.