Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
refactor(theme): dedupe shadowing color code (#1353)
Browse files Browse the repository at this point in the history
* dedupe code for shaded colors

* add shadeScheme by default

* refactor using defaultShadeScheme
  • Loading branch information
NatalyMac authored Aug 13, 2019
1 parent 1d2576f commit c361f4b
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 140 deletions.
14 changes: 3 additions & 11 deletions src/themes/aller/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { darken, lighten } from 'polished';
import { shadeColors } from '../../utils/shade-colors';

import { cssReset } from '../../utils/css-reset';

Expand All @@ -13,16 +13,8 @@ const colorsToShade= {
black: '#222222',
darkness: '#272727',
};
// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.2, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});

const combinedShadedColors = shadeColors(colorsToShade);

const colors = {

Expand Down
16 changes: 8 additions & 8 deletions src/themes/dagbladet-dark/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import merge from 'deepmerge';
import { darken, lighten } from 'polished';
import dagbladet from '../dagbladet';

const darkness = '#1c1d25';
import { shadeColors } from '../../utils/shade-colors';

const colors = {
type: '#ffffff',
darkness,
darknessDark: darken(0.2, darkness),
darknessLight: lighten(0.15, darkness),
darknessLighter: lighten(0.3, darkness),
const colorsToShade = { darkness: '#1c1d25' };

const shadedColors = shadeColors(colorsToShade);

const colorsBase = {
type: '#ffffff',
skinColors: {
background: 'darkness',
type: 'type',
Expand All @@ -28,6 +26,8 @@ const colors = {
},
};

const colors = Object.assign(shadedColors, colorsBase);

const darkOverrides = {
name: 'Dagbladet Dark',
colors,
Expand Down
17 changes: 7 additions & 10 deletions src/themes/dagbladet/colors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { darken, lighten } from 'polished';
import { shadeColors, defaultShadeScheme } from '../../utils/shade-colors';

const colorsToShade= {
primary: '#d60000',
Expand All @@ -15,16 +15,13 @@ const colorsToShade= {
brown: '#9a663f',
};

// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.05, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));
const shadeScheme = {
dark: 0.05,
};

const shades = Object.assign({}, defaultShadeScheme, shadeScheme);

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade, shades);

const colors = {
grayTint: '#C0C0C0',
Expand Down
12 changes: 2 additions & 10 deletions src/themes/default-theme/colors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { darken, lighten } from 'polished';
import { shadeColors } from '../../utils/shade-colors';

const colorsToShade= {
primary: 'teal',
Expand All @@ -18,16 +18,8 @@ const colorsToShade= {
darkness: '#222222',
grayTint: '#c0c0c0',
};
// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.2, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade);

const skinColors = {
splashBackground: 'primary',
Expand Down
17 changes: 7 additions & 10 deletions src/themes/dinside/colors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { darken, lighten } from 'polished';
import { shadeColors, defaultShadeScheme } from '../../utils/shade-colors';

const colorsToShade= {
primary: '#BE4125',
Expand All @@ -13,16 +13,13 @@ const colorsToShade= {
floralWhite: '#fbf8f3',
};

// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.1, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));
const shadeScheme = {
dark: 0.1,
};

const shades = Object.assign({}, defaultShadeScheme, shadeScheme);

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade, shades);

const colors = {
...combinedShadedColors,
Expand Down
16 changes: 8 additions & 8 deletions src/themes/elbil24-dark/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import merge from 'deepmerge';
import { darken, lighten } from 'polished';
import elbil24 from '../elbil24';

const darkness = '#212325';
import { shadeColors } from '../../utils/shade-colors';

const colors = {
type: '#ffffff',
darkness,
darknessDark: darken(0.2, darkness),
darknessLight: lighten(0.15, darkness),
darknessLighter: lighten(0.3, darkness),
const colorsToShade = { darkness: '#212325' };

const shadedColors = shadeColors(colorsToShade);

const colorsBase = {
type: '#ffffff',
skinColors: {
background: 'darkness',
type: 'type',
Expand All @@ -27,6 +25,8 @@ const colors = {
},
};

const colors = Object.assign(shadedColors, colorsBase);

const darkOverrides = {
name: 'Elbil24 Dark',
colors,
Expand Down
17 changes: 7 additions & 10 deletions src/themes/elbil24/colors.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { darken, lighten } from 'polished';
import { shadeColors, defaultShadeScheme } from '../../utils/shade-colors';

const colorsToShade= {
primary: '#d23729',
secondary: '#000',
lightGrey: '#ecece8',
};

// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.1, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));
const shadeScheme = {
dark: 0.1,
};

const shades = Object.assign({}, defaultShadeScheme, shadeScheme);

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade, shades);

const colors = {
...combinedShadedColors,
Expand Down
17 changes: 7 additions & 10 deletions src/themes/kk/colors.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { darken, lighten } from 'polished';
import { shadeColors, defaultShadeScheme } from '../../utils/shade-colors';

const colorsToShade= {
primary: 'black',
secondary: '#999',
pink: 'hotpink',
};

// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.1, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));
const shadeScheme = {
dark: 0.1,
};

const shades = Object.assign({}, defaultShadeScheme, shadeScheme);

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade, shades);

const colors = {
...combinedShadedColors,
Expand Down
13 changes: 2 additions & 11 deletions src/themes/light-theme/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { darken, lighten } from 'polished';
import { shadeColors } from '../../utils/shade-colors';

import { cssReset } from '../../utils/css-reset';

Expand Down Expand Up @@ -32,16 +32,7 @@ const colorsToShade = {
sand: '#444',
};

// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.2, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade);

const skinColors = {
splashBackground: 'primary',
Expand Down
13 changes: 2 additions & 11 deletions src/themes/mat/colors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { darken, lighten } from 'polished';
import { shadeColors } from '../../utils/shade-colors';

const colorsToShade= {
primary: '#ff790a',
Expand All @@ -11,16 +11,7 @@ const colorsToShade= {
sand: '#f8f8f1',
};

// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.2, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade);

const skinColors = {
type: 'darkness',
Expand Down
14 changes: 3 additions & 11 deletions src/themes/seher/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { darken, lighten } from 'polished';
import { shadeColors } from '../../utils/shade-colors';

import { cssReset } from '../../utils/css-reset';

Expand All @@ -14,16 +14,8 @@ const colorsToShade= {
black: '#222222',
darkness: '#272727',
};
// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.2, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});

const combinedShadedColors = shadeColors(colorsToShade);

const colors = {
grayTint: '#C0C0C0',
Expand Down
12 changes: 2 additions & 10 deletions src/themes/start/colors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { darken, lighten } from 'polished';
import { shadeColors } from '../../utils/shade-colors';

const colorsToShade = {
primary: '#7a9a26',
Expand All @@ -7,15 +7,7 @@ const colorsToShade = {
pageBackground: '#f9f9f9',
};

// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.2, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));
const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade);

const skinColors = {
type: 'darkness',
Expand Down
17 changes: 7 additions & 10 deletions src/themes/topp/colors.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { darken, lighten } from 'polished';
import { shadeColors, defaultShadeScheme } from '../../utils/shade-colors';

const colorsToShade= {
primary: '#ff1c56',
secondary: '#0000ff',
};

// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.1, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));
const shadeScheme = {
dark: 0.1,
};

const shades = Object.assign({}, defaultShadeScheme, shadeScheme);

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade, shades);

const colors = {
...combinedShadedColors,
Expand Down
17 changes: 7 additions & 10 deletions src/themes/vi/colors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { darken, lighten } from 'polished';
import { shadeColors, defaultShadeScheme } from '../../utils/shade-colors';

const colorsToShade= {
primary: '#064163',
Expand All @@ -13,16 +13,13 @@ const colorsToShade= {
darkness: '#333333',
};

// Creates 4 shades of each color in colorsToShade
// For example: primary becomes primary, primaryDark, primaryLight and primaryLighter
const shadedColors = Object.keys(colorsToShade).map(color => ({
[`${color}`]: colorsToShade[color],
[`${color}Dark`]: darken(0.1, colorsToShade[color]),
[`${color}Light`]: lighten(0.15, colorsToShade[color]),
[`${color}Lighter`]: lighten(0.3, colorsToShade[color]),
}));
const shadeScheme = {
dark: 0.1,
};

const shades = Object.assign({}, defaultShadeScheme, shadeScheme);

const combinedShadedColors = shadedColors.reduce((acc, cur) => Object.assign(acc, cur), {});
const combinedShadedColors = shadeColors(colorsToShade, shades);

const colors = {
...combinedShadedColors,
Expand Down
Loading

0 comments on commit c361f4b

Please sign in to comment.