Skip to content

Commit a9bb524

Browse files
Merge #447
447: Migrate to dart-sass, update divisions r=bidoubiwa a=ColinFrick Migrate from node-sass to (dart-) sass. Replace divisions with multiplications or `math.div` Closes #344 Co-authored-by: colin.frick <[email protected]> Co-authored-by: Colin Frick <[email protected]>
2 parents 579e882 + 4e93384 commit a9bb524

File tree

5 files changed

+76
-611
lines changed

5 files changed

+76
-611
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"eslint-plugin-prettier": "^3.3.0",
5555
"jest": "^26.6.3",
5656
"jsdom": "^17.0.0",
57-
"node-sass": "^6.0.1",
57+
"sass": "^1.43.2",
5858
"postcss-cli": "^7.1.2",
5959
"prettier": "^2.0.5",
6060
"pretty-bytes-cli": "^2.0.0",

scripts/build-css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mkdir -p "$DIST_DIR"
1414

1515
# ./dist/cdn/docs-searchbar.css
1616
echo "$LICENSE" > "$DIST_FILE";
17-
node-sass --output-style expanded ./src/styles/main.scss \
17+
sass --style expanded ./src/styles/main.scss \
1818
| postcss --use autoprefixer -o "$DIST_FILE"
1919

2020
# copy styles

src/styles/_dropdown.scss

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Detect lightness
2+
@use "sass:math";
3+
24
@function detectLightness($color) {
35
@if (lightness($color) > 60) {
46
@return mix($color, #000, 90%);
@@ -177,7 +179,7 @@
177179
.dsb-suggestions {
178180
position: relative;
179181
z-index: 1000;
180-
margin-top: $padding/2;
182+
margin-top: $padding*0.5;
181183
& a:hover {
182184
text-decoration: none;
183185
}
@@ -205,7 +207,7 @@
205207
background: $background-color;
206208
border-radius: $border-radius + px;
207209
overflow: auto;
208-
padding: 0 $padding/2 $padding/2;
210+
padding: 0 $padding*0.5 $padding*0.5;
209211
}
210212

211213
// Inner-grid setup
@@ -218,7 +220,7 @@
218220
.docs-searchbar-suggestion {
219221
display: block;
220222
position: relative;
221-
padding: 0 $padding/2;
223+
padding: 0 $padding*0.5;
222224
background: $background-color;
223225
color: $title-color;
224226
overflow: hidden;
@@ -262,7 +264,7 @@
262264
display: block;
263265
width: 70%;
264266
position: relative;
265-
padding: $padding/3 0 $padding/3 $padding/1.5;
267+
padding: math.div($padding, 3) 0 math.div($padding, 3) math.div($padding, 1.5);
266268
cursor: pointer;
267269

268270
&:before {
@@ -281,8 +283,8 @@
281283
position: relative;
282284
border-bottom: 1px solid #ddd;
283285
display: none;
284-
margin-top: $padding/2;
285-
padding: $padding/4 0;
286+
margin-top: $padding*0.5;
287+
padding: $padding*0.25 0;
286288
font-size: $header-size;
287289
color: $header-color;
288290
@if $dark-mode {
@@ -294,15 +296,15 @@
294296
width: 100%;
295297
display: flex;
296298
align-items: flex-start;
297-
padding: $padding/2 0 0 0;
299+
padding: $padding*0.5 0 0 0;
298300
}
299301

300302
&--subcategory-column {
301303
width: 30%;
302304
padding-left: 0;
303305
text-align: right;
304306
position: relative;
305-
padding: $padding/3 $padding/1.5;
307+
padding: math.div($padding, 3) math.div($padding, 1.5);
306308
color: $subtitle-color;
307309
font-size: $subtitle-size;
308310
word-wrap: break-word;
@@ -324,7 +326,7 @@
324326
}
325327

326328
&--title {
327-
margin-bottom: $padding/4;
329+
margin-bottom: $padding*0.25;
328330
color: $title-color;
329331
font-size: $title-size;
330332
font-weight: bold;
@@ -339,7 +341,7 @@
339341

340342
&--no-results {
341343
width: 100%;
342-
padding: $padding/2 0;
344+
padding: $padding*0.5 0;
343345
text-align: center;
344346
font-size: 1.2em;
345347

@@ -415,7 +417,7 @@
415417
.suggestion-layout-simple {
416418
&.docs-searchbar-suggestion {
417419
border-bottom: solid 1px #eee;
418-
padding: $padding/2;
420+
padding: $padding*0.5;
419421
margin: 0;
420422
@if $dark-mode {
421423
border-bottom: solid 1px lighten($border-color, 10%);
@@ -495,10 +497,10 @@
495497
}
496498

497499
&--text {
498-
margin: $padding/4 0 0;
500+
margin: $padding*0.25 0 0;
499501
display: desc($include-desc);
500502
line-height: 1.4em;
501-
padding: $padding/3 $padding/2;
503+
padding: math.div($padding, 3) $padding*0.5;
502504
background: $suggestion-background-color;
503505
font-size: $text-size;
504506
opacity: 0.8;
@@ -520,7 +522,7 @@
520522
width: 180px;
521523
height: 20px;
522524
z-index: 2000;
523-
margin-top: $padding/1.5;
525+
margin-top: math.div($padding, 1.5);
524526
color: $text-color;
525527
margin-left: auto;
526528
}

src/styles/_searchbox.scss

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
@use "sass:math";
2+
13
@function even-px($value) {
24
@if type-of($value) == 'number' {
35
@if (unitless($value)) {
46
$value: $value * 1px;
57
} @else if unit($value) == 'em' {
6-
$value: ($value / 1em * 16px);
8+
$value: (math.div($value, 1em) * 16px);
79
} @else if unit($value) == 'pts' {
810
$value: $value * 1.3333 * 1px;
911
} @else if unit($value) == '%' {
10-
$value: $value * 16 / 100% * 1px;
12+
$value: math.div($value * 16, 100%) * 1px;
1113
}
1214
$value: round($value);
13-
@if ($value % 2 != 0) {
15+
@if ($value % 2 != 0px) {
1416
$value: $value + 1;
1517
}
1618
@return $value;
@@ -23,20 +25,20 @@
2325
$input-height: $font-size * 2.4,
2426
$border-width: 1px,
2527
$text-color: #555,
26-
$border-radius: $input-height / 2,
28+
$border-radius: $input-height * 0.5,
2729
$input-border-color: #ccc,
2830
$input-focus-border-color: #1ec9ea,
2931
$input-background: #f8f8f8,
3032
$input-focus-background: #fff,
3133
$placeholder-color: #aaa,
3234
$icon: 'sbx-icon-search-1',
33-
$icon-size: $input-height / 1.6,
35+
$icon-size: math.div($input-height, 1.6),
3436
$icon-position: left,
3537
$icon-color: #888,
3638
$icon-background: $input-focus-border-color,
3739
$icon-background-opacity: 0.1,
3840
$icon-clear: 'sbx-icon-clear-1',
39-
$icon-clear-size: $font-size / 1.1,
41+
$icon-clear-size: math.div($font-size, 1.1),
4042
$dark-mode: false
4143
) {
4244
.searchbox {
@@ -78,7 +80,7 @@
7880
) + if($icon-background-opacity == 0, 0, even-px($font-size));
7981
padding-left: if(
8082
$icon-position == 'right',
81-
even-px($font-size / 2) + even-px($border-radius / 2),
83+
even-px($font-size * 0.5) + even-px($border-radius * 0.5),
8284
even-px($input-height) +
8385
if($icon-background-opacity == 0, 0, even-px($font-size * 1.2))
8486
);
@@ -133,7 +135,7 @@
133135
background-color: rgba($icon-background, $icon-background-opacity);
134136
padding: 0;
135137
width: even-px($input-height) +
136-
if($icon-background-opacity == 0, 0, even-px($font-size / 2));
138+
if($icon-background-opacity == 0, 0, even-px($font-size * 0.5));
137139
height: 100%;
138140
vertical-align: middle;
139141
text-align: center;
@@ -176,12 +178,12 @@
176178
&__reset {
177179
display: block;
178180
position: absolute;
179-
top: (even-px($input-height) - even-px($icon-clear-size)) / 2 - 4px;
181+
top: (even-px($input-height) - even-px($icon-clear-size)) * 0.5 - 4px;
180182
right: if(
181183
$icon-position == 'right',
182184
even-px($input-height) +
183185
if($icon-background-opacity == 0, 0, even-px($font-size)),
184-
(even-px($input-height) - even-px($icon-clear-size)) / 2 - 4px
186+
(even-px($input-height) - even-px($icon-clear-size)) * 0.5 - 4px
185187
);
186188
margin: 0;
187189
border: 0;

0 commit comments

Comments
 (0)