Skip to content

Commit d880d60

Browse files
refactor(color/palette): change palette creation to handle multiple colors in variant and update examples.
1 parent bd5ec62 commit d880d60

File tree

4 files changed

+96
-38
lines changed

4 files changed

+96
-38
lines changed

color/palette/_index.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
@forward 'palette.color-add.function';
2+
@forward 'palette.color-remove.function';
13
@forward 'palette.create.function';
24
@forward 'palette.create.mixin';
35
@forward 'palette.get.function';
46
@forward 'palette.remove.function';
7+
@forward 'palette.variant-add.function';

color/palette/_palette.create.function.scss

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
@use '../../map';
55
@use '../../meta';
66
@use '../../variant';
7+
@use '../functions/name';
78

89
// Functions.
9-
@use '../functions/color.name-nest.function' as *;
1010
@use '../functions/color.name.function' as *;
11+
@use 'palette.color-add.function' as *;
1112

1213
// Add.
1314
function.$functions: map.set(function.$functions, color, name, meta.get-function(name));
@@ -16,45 +17,65 @@ function.$functions: map.set(function.$functions, color, name, meta.get-function
1617
// NOTE: consider adding bracketed adjust
1718
// The `palette.create()` function.
1819
// @arbitrary `$values...`
20+
// @returns
1921
@function create($values...) {
2022
$palette: ();
21-
@each $name-color in $values {
22-
@each $name, $color in $name-color {
23-
$nested: variant.indicator-index($name, '+');
24-
$name: if($nested, variant.indicator-remove($name, '+'), $name);
25-
@if type-of($color) == map {
26-
$palette: map.deep-merge($palette, ($name: $color));
27-
} @else {
28-
// Palette name.
29-
$i: 1;
30-
@each $name in if(list.separator($name) == space, ($name,), $name) {
31-
// Color.
32-
$j: 1;
33-
@each $color in if(list.separator($color) == space, ($color,), $color) {
34-
@if list.has-list($color) and list.separator($color) == space {
35-
$color: name-nest(if($nested, $name, null), $color...);
36-
} @else {
37-
$color: name-nest(if($nested, $name, null), ($color,));
38-
}
39-
40-
$variant: variant.create($color);
41-
42-
// TODO: Check.
43-
@each $class, $color in $variant {
44-
@if list.index($class, color) and list.length($class) > 1 {
45-
$variant: map.key-replace($variant, $class, list.remove-value($class, color));
46-
}
47-
}
48-
49-
$palette: map.deep-merge($palette, ($name: $variant));
50-
}
51-
52-
$j: $j + 1;
23+
$variant-colors: ();
24+
25+
// FEATURE: Get additional colors.
26+
$i: 1;
27+
@each $variant in $values {
28+
@each $name, $colors in $variant {
29+
$j: 1;
30+
@each $color in $colors {
31+
@if list.has-list($color) and list.length($color) > 1 {
32+
$variant-color: name.retrieve(list.nth($color, 1));
33+
$variant-colors: map.deep-merge(
34+
$variant-colors,
35+
($name: (map.get($variant-color, name): list.range($color, 2)))
36+
);
37+
$color: list.nth($color, 1);
38+
$colors: list.set-nth($colors, $j, $color);
5339
}
5440

41+
$j: $j + 1;
42+
}
43+
44+
$variant: map.deep-merge($variant, ($name: $colors));
45+
}
46+
47+
$values: list.set-nth($values, $i, $variant);
48+
$i: $i + 1;
49+
}
50+
51+
// Nest values.
52+
$variant: variant.nest($values...);
53+
54+
// FEATURE: Add variant.
55+
@each $name, $color in $variant {
56+
@if type-of($color) == list {
57+
$i: 1;
58+
@each $c in $color {
59+
$color: list.set-nth($color, $i, name.add-indicator($c));
5560
$i: $i + 1;
5661
}
62+
63+
$palette: map.set($palette, $name, variant.create($color, $type: color));
64+
}
65+
}
66+
67+
// FEATURE: Add additional colors to variant.
68+
@each $name, $variant in $variant-colors {
69+
@each $name in if(list.separator($name) == space, ($name,), $name) {
70+
$name: variant.indicator-remove($name, '+');
71+
@each $class, $colors in $variant {
72+
$palette: color-add($palette, $name, $class, auto, $colors...);
73+
}
5774
}
5875
}
5976
@return $palette;
6077
}
78+
79+
// Examples.
80+
// @debug create(((+accent, primary): (color, ((basic dark) 3% 0.5) (light, 10%) (dark, 5%), light, dark)));
81+

color/palette/_palette.create.mixin.spec.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Functions.
2+
@use 'palette.create.function' as palette;
23
@use 'palette.create.mixin' as *;
34
@use 'palette.get.function' as *;
45

@@ -162,3 +163,10 @@
162163
// lightness and alpha adjust
163164
// @debug create((control: ((disabled, 15%), (error, 15% 0.5), info, success, warning))); // (control: ("disabled": (disabled color, 15%), "error": (error color, 15% 0.5), "info": info color, "success": success color, "warning": warning color))
164165
// @debug create((footer large: outline (disabled, error, info, success, warning)));
166+
167+
168+
// TODO: Check.
169+
// @debug palette.create((primary: (
170+
// ((link, visited, hover): secondary (color, dark, light), active: primary (color, dark, light)),
171+
// primary (color, dark, light),
172+
// )));

color/palette/_palette.spec.scss

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
// Functions.
2-
@use 'palette.create.function' as *;
3-
@use 'palette.get.function' as *;
4-
@use 'palette.remove.function' as *;
5-
@use 'palette.set.function' as *;
2+
@use '../palette';
63

74
// Examples.
8-
// $palette: create((primary: (primary, primary dark, secondary, accent)), (core: (disabled, active, error, highlight dark)));
5+
$-palette: (
6+
accent: (
7+
accent color: (accent basic color, 3%),
8+
accent color dark: (accent basic color, 5%),
9+
accent color light: (accent basic color, 5%),
10+
),
11+
12+
primary: (
13+
primary color: (primary basic color, 3%),
14+
primary color dark: (primary basic color, 5%),
15+
primary color light: (primary basic color, 15%),
16+
),
17+
);
918

1019
// get
1120
// @debug get($palette, core); // ("disabled": disabled color, "active": active color, "error": error color, highlight dark: highlight color dark)
@@ -18,3 +27,20 @@
1827
// remove
1928
// $palette: remove($palette, (core: (highlight dark, error), primary: (primary dark,)));
2029
// @debug get($palette, core);
30+
31+
// FEATURE: palette.create()
32+
// $palette: palette.create((+accent: (basic 3% 0.5, dark)));
33+
// $palette: palette.create((+accent: (color, (basic 3% 0.5), light, dark)));
34+
// $palette: palette.create(((+accent, primary): (color, ((basic dark) 3% 0.5) (light, 10%) (dark, 5%), light, dark)));
35+
36+
// @debug palette.color-add($palette, accent, basic dark, auto, (secondary dark, 5%));
37+
// @debug $palette;
38+
39+
// FEATURE: other
40+
// @debug color-add($-palette, accent, dark, auto, (secondary color light, 5%));
41+
// $colors: palette.color-add($-palette, primary, dark, comma, (secondary color light, 5%), (accent color, 15%));
42+
43+
// @debug $colors;
44+
// @debug palette.color-remove($colors, primary, dark, space, accent, secondary);
45+
46+
// $palette: create((primary: (primary, primary dark, secondary, accent)), (core: (disabled, active, error, highlight dark)));

0 commit comments

Comments
 (0)