Color scheme generator for Sass. Based on http://colorschemedesigner.com/csd-3.5 and color-scheme, but unique in it's output and focus on ease of use.
Install package with NPM and add it to your development dependencies:
npm install --save-dev sass-colorscheme
Import the scss
file from any other Sass file,
and assign a variable to the function's output:
@import "node_modules/sass-colorscheme/colorscheme";
$seed-color: #ffd040;
$colorscheme: colorscheme($seed: $seed-color, $global: true, $scheme: 'mono');
h1 {
color: $primary; // #ffd040
background: $primary--lightest; // #ffefc0
border: 1px solid $primary--darkest; // #c09000
}
Or, if variables are not global
@import "node_modules/sass-colorscheme/colorscheme";
$seed-color: #ffd040;
$colorscheme: colorscheme($seed: $seed-color, $global: false, $scheme: 'mono');
h1 {
color: map-get($colorscheme, 'primary'); // #ffd040
background: map-get($colorscheme, 'primary--lightest'); // #ffefc0
border: 1px solid map-get($colorscheme, 'primary--darkest'); // #c09000
}
Note that the keys used with map-get
are identical to the global variable names, except for the leading $
.
Returns a map of colors (see Output)
Type: color
Color on which to base the color scheme. Can be any hex or named color
value. To use RGB or HSL values, use the built-in rgb()
or hsl()
functions.
Type: boolean
Default: true
(Optional)
Assign color scheme output to global variables. True results in
variables that are set in the global namespace and can be
accessed by any sass
file that imports this script. False
results in no additional global variables. To access the colors,
you must use map-get($colorscheme, '$key')
.
Type: string
Default: mono
(Optional)
The color scheme to generate. Accepted values are
mono
A monochromatic color schemetriad
A color scheme with three main colors. The two secondary colors are adjacent to the complement of the$seed
colorcomplementary
A color scheme based on the seed and it's complementtetrad
A color scheme with four main colors. Two colors are the seed and the complement, plus one value adjacent to the seed and one value adjacent to the complement.analogic
A color scheme with three main colors. The two secondary colors are adjacent to the$seed
color. Can optionally include the complement (see$complement
, below).
Type: number
Default: 0.3
Range: 0 - 1, inclusive
(Optional)
The distance separating the secondary values from the seed and complement.
Notes:
- Only valid for
triad
,tetrad
, andanalogic
. - A larger number increases the amount of separation between colors, where 1 is maximum separation.
- Used with
tetrad
, a distance of 1 will result in 4 evenly spaces hues around the color circle. That is, each hue will be offset from the other by 90 degrees. A distance of 0 will result in the same output as thecomplementary
scheme. - For
triad
andanalogic
, A distance of 1 will result in the same scheme: the seed, plus two colors that are evenly spaced between the seed and it's complement. - For
triad
, a distance of 0 will result in the same scheme ascomplementary
. - For
analogic
, a distance of 0 will result in the same scheme asmono
.
Type: string
Default: none
(Optional)
Variations on the generated color scheme. Accepted values are
pastel
: desaturates by 40% and lightens by 10%dark
: darkens colors by 15%light
: lightens colors by 15%hard
: saturates by 100%pale
: desaturates by 60%none
Type: boolean
Default: false
(Optional)
Include the complement on the analogic
color scheme. Has no effect when
used with other schemes.
The script generates a minimum of 5 colors (when $scheme == 'mono'
),
and a maximum of 20 colors (when $scheme == 'tetrad'
or $scheme == 'analogic' and $complement == true
).
The base color variable names are
$primary
$secondary-a
$secondary-b
$complementary
The color variants are
{base}--lighter
{base}--lightest
{base}--darker
{base}--darkest
The output varies depending on the selected $scheme
:
mono
returns$primary
and all variantscomplementary
returns$primary
and$complementary
and all variantstriad
returns$primary
,$secondary-a
, and$secondary-b
and all variantstetrad
returns all four base colors and all variantsanalogic
with$complement == false
returns$primary
,$secondary-a
, and$secondary-b
and all variantsanalogic
with$complement == true
returns all four base colors and all variants
The package has an example
directory which is designed to make it easy to generate and preview various color schemes.
Both the example
script and the start
script will generate a preview using the default settings.
npm start
# or
npm run example
To pass a custom seed color to the example script, simply pass a command line argument to npm (note that the color must be quoted):
npm start -- '#ff0000'
# or
npm run example -- '#ff0000'
Alternatively, you can modify the default seed color in example/defaults.scss
and simply run npm start
with no arguments.