Skip to content

Commit b724cda

Browse files
authored
Merge pull request #4 from mirisuzanne/more-colors
Allow arbitrary color names
2 parents 723421a + 67dca3a commit b724cda

File tree

17 files changed

+323
-134
lines changed

17 files changed

+323
-134
lines changed

.sassdocrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ groups:
1212
config: Global Settings
1313
fallbacks: Fallback Colors & Modes
1414
modes: Dynamic Modes
15+
themes: Creating Themes
1516
'Sass (optional)':
1617
palettes: Color Palettes
1718
tools: Additional Tools

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# Changelog
22

3+
## 0.1.0-beta.11 - 2019/12/31
4+
5+
This release adds support for arbitrary color names,
6+
allowing you to define more complex and customized cascading themes.
7+
8+
- BREAKING: Replaced individual `$*-hue` settings with a combined `$hues` map
9+
of (`string`) color name keys with (`number` | `null`) hue values.
10+
This allows the tool to generate any number of colors.
11+
The default `('prime', 'accent', 'neutral')` shorthand
12+
creates identical default settings to previous releases.
13+
Acceptable shorthands:
14+
- a single `number` | `null` value will be assigned a key: `prime`
15+
- a `string` | `list` (of strings) will generate keys with `null` values
16+
- BREAKING: Added a `$colors` list argument (first) in both the
17+
`colors()` and `gradient()` mixins --
18+
set to the list of `$hues` map-keys by default
19+
- BREAKING: Since `accent` colors are no longer hard-coded,
20+
the built-in themes have replaced `--ccs-accent--theme` settings
21+
with more generic `--ccs-theme--1` and `--ccs-theme--2` --
22+
which can be assigned to other color names as needed.
23+
- NEW: Any color with `neutral` in the name
24+
will use the neutral saturation,
25+
rather than the default saturation
26+
327
## 0.1.0-beta.10 - 2019/12/5
428

529
- BUGFIX: Source & cascade order was causing HTML modes to fail

README.md

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,15 @@ Import using the new module import syntax:
6363
Both imports generate
6464
core configuration options
6565
as CSS custom properties
66-
(set by Sass when applicable):
66+
(set by Sass when applicable) eg:
6767

6868
```scss
6969
[data-ccs='root'] {
70-
--ccs-prime--config: #{$prime-hue or 330};
71-
--ccs-accent--config: #{$accent-hue or null};
72-
--ccs-lightness--config: #{$lightness or null};
73-
--ccs-saturation--config: #{$saturation or null};
74-
--ccs-contrast--config: #{$contrast or null};
75-
--ccs-fade-background--config: #{$fade-background};
76-
}
77-
```
78-
79-
This also configures a light/dark-mode toggle,
80-
and fallback values for both modes:
81-
82-
```scss
83-
// fallback values, in case variables are not supported
84-
[data-ccs='root'] {
85-
background-color: $fallback-light;
86-
color: $fallback-dark;
87-
88-
@media (prefers-color-scheme: dark) {
89-
background-color: $fallback-dark;
90-
color: $fallback-light;
91-
}
70+
--ccs-prime--config: 330;
71+
--ccs-lightness--config: 50%;
72+
--ccs-saturation--config: 50%;
73+
--ccs-contrast--config: 50%;
74+
--ccs-fade-background--config: 0.9;
9275
}
9376
```
9477

@@ -107,35 +90,61 @@ so we've created a
10790
which can be applied anywhere
10891
new colors are needed.
10992

110-
This attribute provides your base colors as custom properties:
111-
112-
- `--ccs-prime`, `--ccs-accent`:
113-
Prime and accent hues, with base lightness and saturation
114-
- `--ccs-neutral`:
115-
The neutral hue gets base lightness
116-
and full-contrast saturation
117-
- `--ccs-<prime | accent | neutral >--fg-full` :
118-
All three hues get a full-contrast foreground
119-
- `--ccs-<prime | accent | neutral >--bg-full` :
120-
All three hues get a full-contrast background
93+
We configure the default `color` and `background-color` settings:
94+
95+
```scss
96+
[data-ccs-colors] {
97+
background-color: var(--ccs-background, var(--ccs--bg-full));
98+
color: var(--ccs-color, var(--ccs--fg-full));
99+
}
100+
```
101+
102+
Along with fallback values for light/dark modes,
103+
in case CSS custom properties are not supported:
104+
105+
```scss
106+
[data-ccs-colors],
107+
[data-ccs-colors='light'] {
108+
background-color: $fallback-light;
109+
color: $fallback-dark;
110+
}
111+
112+
[data-ccs-colors='invert'],
113+
[data-ccs-colors='dark'] {
114+
background-color: $fallback-dark;
115+
color: $fallback-light;
116+
}
117+
```
118+
119+
You can override the default colors and backgrounds
120+
by defining `--ccs-color` and `--ccs-background`:
121+
122+
```scss
123+
[data-ccs-colors] {
124+
--ccs-background: var(--ccs-neutral--bg-full);
125+
--ccs-color: var(--ccs-neutral--fg-full);
126+
}
127+
```
128+
129+
This attribute generates all your colors as custom properties:
130+
131+
- `--ccs-prime`, `--ccs-*`:
132+
Colors generated from the given `$hues`, `$saturation`, and `$lightness` --
133+
along with any `neutral` colors,
134+
which will use their own customizable (low) `$saturation`
135+
- `--ccs-*--fg-full` :
136+
All color hues get a full-contrast foreground
137+
- `--ccs-*--bg-full` :
138+
All color hues get a full-contrast background
121139
- `--ccs--bg-full` white or black, depending on light/dark mode
122140
- `--ccs--fg-full` white or black, depending on light/dark mode
123141

124142
We also provide the color attributes needed
125143
to generate a larger palette:
126144

127-
- `--ccs-h--prime`:
128-
the calculated primary hue,
129-
based on user-settings, theme-settings, and global configuration
130-
- `--ccs-h--accent`:
131-
the calculated accent hue,
132-
based on theme-settings, and global configuration
133-
(there is currently no direct user input for accent hue)
134-
- `--ccs-h--neutral`:
135-
the calculated neutral hue,
136-
based on theme-settings and global configuration;
137-
generally either `--ccs-h--prime` (the default)
138-
or `--ccs-h--accent`
145+
- `--ccs-h--*`:
146+
the calculated hue for each color,
147+
afterresolving user-settings, theme-settings, and global configuration
139148
- `--ccs-contrast`:
140149
the calculated contrast range
141150
based on theme, user, and global settings
@@ -202,14 +211,14 @@ using the `[data-ccs-theme]` attribute:
202211
### Sass Configuration
203212

204213
In most cases,
205-
you'll want to define the `$prime-hue`,
214+
you'll want to define the `prime` hue,
206215
and possibly a few other options --
207216
and then trigger a build from the module itself.
208217
Here's the code from one of my sites:
209218

210219
```scss
211220
@use "../../node_modules/cascading-color-systems/" as ccs with (
212-
$prime-hue: 0,
221+
$hues: 120, // shorthand for setting the prime hue only
213222
$saturation: 70%,
214223
$contrast: 48%,
215224
$steps: 6,

css/ccs.css

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/ccs.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ <h2 data-ccs-colors="invert">accent</h2>
100100
<div style="--show: var(--accent-gradient), var(--accent-gradient--fade)"></div>
101101
</section>
102102

103+
<section class="palette" role="presentation">
104+
<h2 data-ccs-colors="invert">special</h2>
105+
<div style="--show: var(--special-gradient), var(--special-gradient--fade)"></div>
106+
</section>
107+
103108
<section class="palette" role="presentation">
104109
<h2 data-ccs-colors="invert">neutral</h2>
105110
<div style="--show: var(--neutral-gradient), var(--neutral-gradient--fade)"></div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cascading-color-systems",
3-
"version": "0.1.0-beta.10",
3+
"version": "0.1.0-beta.11",
44
"description": "generate dynamic color palettes with custom properties",
55
"main": "dist.js",
66
"module": "index.js",

sass/config/_colors.scss

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,45 @@
1515
///
1616
/// @group config
1717

18-
// Prime Hue
19-
// ---------
20-
/// The color-wheel hue that will act as our default
21-
/// for generating all color palettes.
22-
/// Hue values should be set without `deg` units.
23-
///
24-
/// - Sass: `$prime-hue: 330;`
25-
/// - CSS: `--ccs-prime--config: 330;`
26-
///
27-
/// @type number | null
18+
// Hues
19+
// ----
20+
/// The colors to generate, and optional default hues for each color.
21+
/// To set both color-names and hues, provide an explicit map.
22+
/// - If you provide a songle hue value,
23+
/// we'll assign it to the required `prime` key.
24+
/// - If you provide a list of color names, we
25+
/// we'll assign them all default `null` hue values.
26+
///
27+
/// Two color names are given special treatment:
28+
/// - `prime` is required, a defaults to `330` if undefined
29+
/// - `neutral` colors (including `neutral` anywhere in a color-name)
30+
/// will use the `$neutral-saturation` or most-desaturated value
31+
/// @type map | list | string | number | null
2832
/// @group config
29-
$prime-hue: null !default;
33+
$hues: (
34+
'prime',
35+
'accent',
36+
'neutral',
37+
) !default;
3038

31-
// Accent Hue
32-
// ----------
33-
/// The color-wheel hue that will act as our default
34-
/// for generating accent colors.
35-
/// Leave unset, or use Sass `null` value to generate all palettes from the prime hue.
36-
/// Hue values should be set without `deg` units.
37-
///
38-
/// - Sass: `$accent-hue: 120;`
39-
/// - CSS: `--ccs-accent--config: 120;`
40-
///
41-
/// @type number | null
42-
/// @group config
43-
$accent-hue: null !default;
39+
// Convert $hues to a map, or error on invalid hues
40+
@if (type-of($hues) != 'map') {
41+
@if (type-of($hues) == 'list') or (type-of($hues) == 'string') {
42+
$hues-list: $hues;
43+
$hues: ();
44+
45+
@each $color in $hues-list {
46+
$hues: map-merge($hues, ($color: null));
47+
}
48+
} @else if (type-of($hues) == 'number') or (not $hues) {
49+
$hues: ('prime': $hues);
50+
}
51+
}
52+
53+
// Require a prime hue
54+
@if not (map-has-key($hues, 'prime')) {
55+
@error 'Please provide a `prime` hue';
56+
}
4457

4558
// Lightness
4659
// ---------
@@ -96,17 +109,6 @@ $contrast: null !default;
96109
/// @group config
97110
$fade-background: null !default;
98111

99-
// Neutral Hue
100-
// -----------
101-
/// By default, neutral colors are created from the prime hue.
102-
///
103-
/// - Sass: `$neutral-hue: 330;`
104-
/// - CSS: `--ccs-neutral--config: 330;`
105-
///
106-
/// @type percentage | null
107-
/// @group config
108-
$neutral-hue: null !default;
109-
110112
// Neutral Saturation
111113
// ------------------
112114
/// By default, neutral saturation is set to
@@ -127,13 +129,13 @@ $neutral-saturation: null !default;
127129
/// for browsers that don't support
128130
/// CSS custom properties.
129131
/// The default value is based on
130-
/// `$prime-hue`, `$saturation`, `$lightness`,
132+
/// `map-get($hues, 'prime')`, `$saturation`, `$lightness`,
131133
/// and maximum `$contrast`.
132134
///
133135
/// @type color
134136
/// @group config
135137
$fallback-dark: hsl(
136-
$prime-hue or 330,
138+
map-get($hues, 'prime') or 330,
137139
($saturation or 50%) - ($contrast or 45%),
138140
($lightness or 50%) - ($contrast or 45%)
139141
) !default;
@@ -144,13 +146,13 @@ $fallback-dark: hsl(
144146
/// for browsers that don't support
145147
/// CSS custom properties.
146148
/// The default value is based on
147-
/// `$prime-hue`, `$saturation`, `$lightness`,
149+
/// `map-get($hues, 'prime')`, `$saturation`, `$lightness`,
148150
/// and maximum `$contrast`.
149151
///
150152
/// @type color
151153
/// @group config
152154
$fallback-light: hsl(
153-
$prime-hue or 330,
155+
map-get($hues, 'prime') or 330,
154156
($saturation or 50%) - ($contrast or 45%),
155157
($lightness or 50%) + ($contrast or 45%)
156158
) !default;

0 commit comments

Comments
 (0)