Skip to content

Commit a48f48a

Browse files
Consolidate multiple 'none' values in box-shadow Sass mixin
1 parent 0a005b3 commit a48f48a

2 files changed

Lines changed: 199 additions & 5 deletions

File tree

scss/mixins/_box-shadow.scss

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
@mixin box-shadow($shadow...) {
22
@if $enable-shadows {
33
$result: ();
4+
$has-single-value: false;
5+
$single-value: null;
46

57
@each $value in $shadow {
68
@if $value != null {
7-
$result: append($result, $value, "comma");
8-
}
9-
@if $value == none and length($shadow) > 1 {
10-
@warn "The keyword 'none' must be used as a single argument.";
9+
@if $value == none or $value == initial or $value == inherit or $value == unset {
10+
$has-single-value: true;
11+
$single-value: $value;
12+
} @else {
13+
$result: append($result, $value, "comma");
14+
}
1115
}
1216
}
1317

14-
@if (length($result) > 0) {
18+
@if $has-single-value {
19+
box-shadow: $single-value;
20+
} @else if (length($result) > 0) {
1521
box-shadow: $result;
1622
}
1723
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
@import "../../functions";
2+
@import "../../variables";
3+
@import "../../mixins";
4+
5+
// Store original value
6+
$original-enable-shadows: $enable-shadows;
7+
8+
// Enable shadows for all tests
9+
$enable-shadows: true !global;
10+
11+
@include describe("box-shadow mixin") {
12+
@include it("handles single none value") {
13+
@include assert() {
14+
@include output() {
15+
.test {
16+
@include box-shadow(none);
17+
}
18+
}
19+
20+
@include expect() {
21+
.test {
22+
box-shadow: none;
23+
}
24+
}
25+
}
26+
}
27+
28+
@include it("handles multiple none values by consolidating them") {
29+
@include assert() {
30+
@include output() {
31+
.test {
32+
@include box-shadow(none, none, none);
33+
}
34+
}
35+
36+
@include expect() {
37+
.test {
38+
box-shadow: none;
39+
}
40+
}
41+
}
42+
}
43+
44+
@include it("handles other single-value keywords (initial, inherit, unset)") {
45+
@include assert() {
46+
@include output() {
47+
.test-initial {
48+
@include box-shadow(initial);
49+
}
50+
.test-inherit {
51+
@include box-shadow(inherit);
52+
}
53+
.test-unset {
54+
@include box-shadow(unset);
55+
}
56+
}
57+
58+
@include expect() {
59+
.test-initial {
60+
box-shadow: initial;
61+
}
62+
.test-inherit {
63+
box-shadow: inherit;
64+
}
65+
.test-unset {
66+
box-shadow: unset;
67+
}
68+
}
69+
}
70+
}
71+
72+
@include it("handles multiple single-value keywords by using the last one") {
73+
@include assert() {
74+
@include output() {
75+
.test {
76+
@include box-shadow(initial, inherit, unset);
77+
}
78+
}
79+
80+
@include expect() {
81+
.test {
82+
box-shadow: unset;
83+
}
84+
}
85+
}
86+
}
87+
88+
@include it("handles regular box-shadow values") {
89+
@include assert() {
90+
@include output() {
91+
.test {
92+
@include box-shadow(0 0 10px rgba(0, 0, 0, .5));
93+
}
94+
}
95+
96+
@include expect() {
97+
.test {
98+
box-shadow: 0 0 10px rgba(0, 0, 0, .5);
99+
}
100+
}
101+
}
102+
}
103+
104+
@include it("handles multiple regular box-shadow values") {
105+
@include assert() {
106+
@include output() {
107+
.test {
108+
@include box-shadow(0 0 10px rgba(0, 0, 0, .5), 0 0 20px rgba(0, 0, 0, .3));
109+
}
110+
}
111+
112+
@include expect() {
113+
.test {
114+
box-shadow: 0 0 10px rgba(0, 0, 0, .5), 0 0 20px rgba(0, 0, 0, .3);
115+
}
116+
}
117+
}
118+
}
119+
120+
@include it("handles null values by ignoring them") {
121+
@include assert() {
122+
@include output() {
123+
.test {
124+
@include box-shadow(null, 0 0 10px rgba(0, 0, 0, .5), null);
125+
}
126+
}
127+
128+
@include expect() {
129+
.test {
130+
box-shadow: 0 0 10px rgba(0, 0, 0, .5);
131+
}
132+
}
133+
}
134+
}
135+
136+
@include it("handles mixed values with keywords and regular shadows") {
137+
@include assert() {
138+
@include output() {
139+
.test {
140+
@include box-shadow(none, 0 0 10px rgba(0, 0, 0, .5));
141+
}
142+
}
143+
144+
@include expect() {
145+
.test {
146+
box-shadow: none;
147+
}
148+
}
149+
}
150+
}
151+
152+
@include it("handles empty input") {
153+
@include assert() {
154+
@include output() {
155+
.test {
156+
@include box-shadow();
157+
}
158+
}
159+
160+
@include expect() {
161+
.test { // stylelint-disable-line block-no-empty
162+
}
163+
}
164+
}
165+
}
166+
167+
@include it("respects $enable-shadows variable") {
168+
$enable-shadows: false !global;
169+
170+
@include assert() {
171+
@include output() {
172+
.test {
173+
@include box-shadow(0 0 10px rgba(0, 0, 0, .5));
174+
}
175+
}
176+
177+
@include expect() {
178+
.test { // stylelint-disable-line block-no-empty
179+
}
180+
}
181+
}
182+
183+
$enable-shadows: true !global;
184+
}
185+
}
186+
187+
// Restore original value
188+
$enable-shadows: $original-enable-shadows !global;

0 commit comments

Comments
 (0)