-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy path_color.scss
More file actions
152 lines (131 loc) · 5.01 KB
/
Copy path_color.scss
File metadata and controls
152 lines (131 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Foundation for Sites
// https://get.foundation
// Licensed under MIT Open Source
@use "sass:color";
@use "sass:list";
@import 'math';
$contrast-warnings: true !default;
/// Patch to fix issue #12080
$primary-color: null !default;
$secondary-color: null !default;
$warning-color: null !default;
$alert-color: null !default;
$success-color: null !default;
////
/// @group functions
////
/// Checks the luminance of `$color`.
///
/// @param {Color} $color - Color to check the luminance of.
///
/// @returns {Number} The luminance of `$color`.
@function color-luminance($color) {
// Adapted from: https://github.com/LeaVerou/contrast-ratio/blob/gh-pages/color.js
// Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
$red : round(color.channel($color, "red", $space: rgb));
$green : round(color.channel($color, "green", $space: rgb));
$blue : round(color.channel($color, "blue", $space: rgb));
$rgba: $red, $green, $blue;
$rgba2: ();
@for $i from 1 through 3 {
$rgb: list.nth($rgba, $i);
$rgb: divide($rgb, 255);
$rgb: if($rgb < 0.03928, divide($rgb, 12.92), pow(divide($rgb + 0.055, 1.055), 2.4));
$rgba2: append($rgba2, $rgb);
}
@return 0.2126 * list.nth($rgba2, 1) + 0.7152 * list.nth($rgba2, 2) + 0.0722 * list.nth($rgba2, 3);
}
/// Checks the contrast ratio of two colors.
///
/// @param {Color} $color1 - First color to compare.
/// @param {Color} $color2 - Second color to compare.
///
/// @returns {Number} The contrast ratio of the compared colors.
@function color-contrast($color1, $color2) {
// Adapted from: https://github.com/LeaVerou/contrast-ratio/blob/gh-pages/color.js
// Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
$luminance1: color-luminance($color1) + 0.05;
$luminance2: color-luminance($color2) + 0.05;
$ratio: divide($luminance1, $luminance2);
@if $luminance2 > $luminance1 {
$ratio: divide(1, $ratio);
}
$ratio: round($ratio * 10) * 0.1;
@return $ratio;
}
/// Checks the luminance of `$base`, and returns the color from `$colors` (list of colors) that has the most contrast.
///
/// @param {Color} $base - Color to check luminance.
/// @param {List} $colors [($white, $black)] - Colors to compare.
/// @param {Number} $tolerance [$global-color-pick-contrast-tolerance] - Contrast tolerance.
///
/// @returns {Color} the color from `$colors` (list of colors) that has the most contrast.
@function color-pick-contrast($base, $colors: ($white, $black), $tolerance: $global-color-pick-contrast-tolerance) {
$contrast: color-contrast($base, list.nth($colors, 1));
$best: list.nth($colors, 1);
@for $i from 2 through length($colors) {
$current-contrast: color-contrast($base, list.nth($colors, $i));
@if ($current-contrast - $contrast > $tolerance) {
$contrast: color-contrast($base, list.nth($colors, $i));
$best: list.nth($colors, $i);
}
}
@if ($contrast-warnings and $contrast < 3) {
@warn 'Contrast ratio of #{$best} on #{$base} is pretty bad, just #{$contrast}';
}
@return $best;
}
/// Scales a color to be darker if it's light, or lighter if it's dark. Use this function to tint a color appropriate to its lightness.
///
/// @param {Color} $color - Color to scale.
/// @param {Percentage} $scale [5%] - Amount to scale up or down.
/// @param {Percentage} $threshold [40%] - Threshold of lightness to check against.
///
/// @returns {Color} A scaled color.
@function smart-scale($color, $scale: 5%, $threshold: 40%) {
@if color.channel($color, "lightness", $space: hsl) > $threshold {
$scale: -$scale;
}
@return scale-color($color, $lightness: $scale);
}
/// Get color from foundation-palette
///
/// @param {key} color key from foundation-palette
///
/// @returns {Color} color from foundation-palette
@function get-color($key) {
@if map-has-key($foundation-palette, $key) {
@return map-get($foundation-palette, $key);
}
@else {
@error 'given $key is not available in $foundation-palette';
}
}
/// Transfers the colors in the `$foundation-palette` map into variables, such as `$primary-color` and `$secondary-color`. Call this mixin below the Global section of your settings file to properly migrate your codebase.
@mixin add-foundation-colors() {
@if map-has-key($foundation-palette, primary) {
$primary-color: map-get($foundation-palette, primary) !global;
} @else {
$primary-color: #1779ba !global;
}
@if map-has-key($foundation-palette, secondary) {
$secondary-color: map-get($foundation-palette, secondary) !global;
} @else {
$secondary-color: #767676 !global;
}
@if map-has-key($foundation-palette, success) {
$success-color: map-get($foundation-palette, success) !global;
} @else {
$success-color: #3adb76 !global;
}
@if map-has-key($foundation-palette, warning) {
$warning-color: map-get($foundation-palette, warning) !global;
} @else {
$warning-color: #ffae00 !global;
}
@if map-has-key($foundation-palette, alert) {
$alert-color: map-get($foundation-palette, alert) !global;
} @else {
$alert-color: #cc4b37 !global;
}
}