Skip to content

Commit 23bc6b2

Browse files
thibaudcolaslb-
authored andcommitted
Upgrade to latest Sass and stylelint configuration, with needed refactorings
- Tweak stylesheets for compatibility with latest stylelint configuration - Move stylelint config to JS for ease of copying rules with main config - Enforce scss/no-global-function-names by refactoring code with sass-migrator - Run Sass code through sass-migrator - Change stylelint configuration and code to enforce font-family-no-missing-generic-family-keyword - Manually switch to math.div where migrator used * 0.5
1 parent 7d7a03f commit 23bc6b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+226
-183
lines changed

.stylelintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
venv
3+
build

.stylelintrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
extends: '@wagtail/stylelint-config-wagtail',
3+
rules: {
4+
// Would be valuable for strict BEM components but is too hard to enforce with legacy code.
5+
'no-descending-specificity': null,
6+
},
7+
};

.stylelintrc.yaml

-6
This file was deleted.

client/scss/components/_button.scss

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "sass:color";
12
// Core button style
23
// Note that these styles include methods to render buttons the same x-browser, described here:
34
// http: //cbjdigital.com/blog/2010/08/bulletproof_css_input_button_heights
@@ -214,6 +215,7 @@
214215
}
215216
}
216217

218+
// stylelint-disable-next-line no-duplicate-selectors
217219
&:hover {
218220
background-color: $color-button-hover;
219221
color: $color-white;
@@ -302,12 +304,6 @@
302304
border: 0;
303305
}
304306

305-
&.button--icon {
306-
.icon {
307-
@include svg-icon(1.5em);
308-
}
309-
}
310-
311307
&.button-strokeonhover {
312308
border: 1px solid transparent;
313309

@@ -597,7 +593,7 @@ button {
597593
background-color: $color-white;
598594
padding: 1em 10em 1em 1.5em; // 10em padding leaves room for controls
599595
margin-bottom: 1em;
600-
border: 1px solid lighten($color-grey-4, 3%); // really trying to avoid creating more greys, but this one is better than grey 4 or 5
596+
border: 1px solid color.adjust($color-grey-4, $lightness: 3%); // really trying to avoid creating more greys, but this one is better than grey 4 or 5
601597
}
602598

603599
&.moving {

client/scss/components/_chooser.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ overridden here? hmm.
3636
// TODO: [icon-font] remove when the Wagtail icon font is removed
3737
&:before {
3838
vertical-align: middle;
39-
font-family: wagtail;
39+
font-family: $font-wagtail-icons;
4040
content: '';
4141
// position: relative
4242
display: inline-block;

client/scss/components/_dropdown.legacy.scss

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@
329329
}
330330

331331
// Transitions
332+
// stylelint-disable-next-line no-duplicate-selectors
332333
.dropdown ul {
333334
@include transition(opacity 0.2s linear);
334335
}

client/scss/components/_footer.scss

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "sass:math";
2+
13
.footer {
24
$border-curvature: 3px;
35
@include transition(bottom 0.5s ease 1s);
@@ -82,7 +84,7 @@
8284
.meta {
8385
float: right;
8486
text-align: right;
85-
padding: 7px $grid-gutter-width / 2;
87+
padding: 7px math.div($grid-gutter-width, 2);
8688
font-size: 0.85em;
8789

8890
p {

client/scss/components/_forms.scss

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
@use "sass:map";
2+
@use "sass:math";
3+
// stylelint-disable scss/comment-no-empty
14
// These are the generic stylings for forms of any type.
25
// If you're styling something specific to the page editing interface,
36
// it probably ought to go in layouts/page-editor.scss
@@ -92,8 +95,8 @@ select::-ms-expand {
9295
top: 1px;
9396
bottom: 0;
9497
width: 1.5em;
95-
font-family: wagtail;
96-
content: map-get($icons, 'arrow-down');
98+
font-family: $font-wagtail-icons;
99+
content: map.get($icons, 'arrow-down');
97100
border: 1px solid $color-input-border;
98101
border-width: 0 0 0 1px;
99102
text-align: center;
@@ -134,9 +137,9 @@ select::-ms-expand {
134137
}
135138

136139
&::before {
137-
font-family: wagtail;
140+
font-family: $font-wagtail-icons;
138141
vertical-align: -10%;
139-
content: map-get($icons, 'cross');
142+
content: map.get($icons, 'cross');
140143
}
141144
}
142145

@@ -191,7 +194,7 @@ label.required:after {
191194

192195
&:before,
193196
&:after {
194-
font-family: wagtail;
197+
font-family: $font-wagtail-icons;
195198
position: absolute;
196199
top: 0.5em;
197200
line-height: 100%;
@@ -246,19 +249,19 @@ label.required:after {
246249
.date_field,
247250
.date_time_field {
248251
.input:before {
249-
content: map-get($icons, 'date');
252+
content: map.get($icons, 'date');
250253
}
251254
}
252255

253256
.time_field {
254257
.input:before {
255-
content: map-get($icons, 'time');
258+
content: map.get($icons, 'time');
256259
}
257260
}
258261

259262
.url_field {
260263
.input:before {
261-
content: map-get($icons, 'link');
264+
content: map.get($icons, 'link');
262265
}
263266
}
264267

@@ -345,7 +348,7 @@ li.inline .field {
345348
// solve gutter issues of inline fields
346349
ul.inline li:first-child,
347350
li.inline:first-child {
348-
margin-left: -$grid-gutter-width / 2;
351+
margin-left: math.div(-$grid-gutter-width, 2);
349352
}
350353

351354
// search-bars
@@ -380,6 +383,7 @@ li.inline:first-child {
380383
}
381384

382385
// Transitions
386+
// stylelint-disable-next-line no-duplicate-selectors
383387
.help {
384388
@include transition(opacity 0.2s ease);
385389
}

client/scss/components/_header.scss

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "sass:math";
2+
13
header {
24
padding-top: 1em;
35
padding-bottom: 1em;
@@ -67,7 +69,7 @@ header {
6769
.breadcrumb {
6870
margin-left: -$desktop-nice-padding;
6971
margin-right: -$desktop-nice-padding;
70-
padding-left: $desktop-nice-padding / 2;
72+
padding-left: math.div($desktop-nice-padding, 2);
7173
}
7274
}
7375
}
@@ -77,7 +79,7 @@ header {
7779

7880
.breadcrumb {
7981
margin-bottom: 1rem;
80-
padding-left: $desktop-nice-padding / 2; // rather than padding-left: revert;
82+
padding-left: math.div($desktop-nice-padding, 2); // rather than padding-left: revert;
8183
}
8284
}
8385

client/scss/components/_help-block.scss

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "sass:color";
2+
@use "sass:map";
13
// Help text formatters
24
.help-block {
35
padding: 1em;
@@ -26,38 +28,38 @@
2628
position: relative;
2729

2830
&:before {
29-
font-family: wagtail;
31+
font-family: $font-wagtail-icons;
3032
position: absolute;
3133
left: 1em;
3234
top: 0.7em;
33-
content: map-get($icons, 'help');
35+
content: map.get($icons, 'help');
3436
font-size: 1.4em;
3537
}
3638
}
3739

3840
.help-info {
39-
background-color: lighten($color-blue, 30%);
41+
background-color: color.adjust($color-blue, $lightness: 30%);
4042

4143
&:before {
4244
color: $color-blue;
4345
}
4446
}
4547

4648
.help-warning {
47-
background-color: lighten($color-orange, 30%);
49+
background-color: color.adjust($color-orange, $lightness: 30%);
4850

4951
&:before {
5052
color: $color-orange;
51-
content: map-get($icons, 'warning');
53+
content: map.get($icons, 'warning');
5254
}
5355
}
5456

5557
.help-critical {
56-
background-color: lighten($color-red, 40%);
58+
background-color: color.adjust($color-red, $lightness: 40%);
5759

5860
&:before {
5961
color: $color-red;
60-
content: map-get($icons, 'warning');
62+
content: map.get($icons, 'warning');
6163
}
6264
}
6365

client/scss/components/_icons.scss

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "sass:string";
12
// The wagtail font isn't available in WOFF2, so a @font-face is set here without a mixin.
23
@font-face {
34
font-family: 'wagtail';
@@ -29,12 +30,14 @@
2930
@include icon(); // from _mixins.scss
3031
}
3132

33+
// stylelint-disable-next-line no-duplicate-selectors
3234
.icon:after,
3335
.hallotoolbar [class^='icon-']:after,
3436
.hallotoolbar [class^='icon-']:after {
3537
text-align: right;
3638
}
3739

40+
// stylelint-disable-next-line no-duplicate-selectors
3841
.hallotoolbar [class^='icon-'],
3942
.hallotoolbar [class*=' icon-']:before,
4043
.hallotoolbar [class*=' icon-']:before,
@@ -50,13 +53,13 @@
5053

5154
@each $icon, $content in $icons {
5255
.icon-#{$icon}:before {
53-
content: quote(#{$content});
56+
content: string.quote(#{$content});
5457
}
5558
}
5659

5760
@each $icon, $content in $icons-after {
5861
.icon-#{$icon}:after {
59-
content: quote(#{$content});
62+
content: string.quote(#{$content});
6063
}
6164
}
6265

@@ -155,6 +158,7 @@ svg.icon-spinner { // TODO: leave only class when iconfont styles are removed
155158
}
156159
}
157160

161+
// stylelint-disable-next-line no-duplicate-selectors
158162
.icon {
159163
&.initial {
160164
@include svg-icon(1em);

client/scss/components/_indicator.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "sass:math";
12
// =============================================================================
23
// Indicator light
34
// =============================================================================
@@ -42,7 +43,7 @@ $c-indicator-margin: 0.25rem;
4243

4344
&:before {
4445
content: '';
45-
width: $c-indicator-size / 2;
46+
width: math.div($c-indicator-size, 2);
4647
height: $c-indicator-size;
4748
position: absolute;
4849
top: 0;

client/scss/components/_listing.scss

+3-3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ ul.listing {
253253
}
254254
}
255255

256+
// stylelint-disable-next-line no-duplicate-selectors
256257
.button-secondary {
257258
background-color: $color-white;
258259
}
@@ -450,6 +451,7 @@ ul.listing {
450451
word-wrap: break-word;
451452
}
452453

454+
// stylelint-disable-next-line no-duplicate-selectors
453455
ul.listing {
454456
border-top: 1px dashed $color-input-border;
455457
margin-bottom: 2em;
@@ -534,9 +536,6 @@ table.listing {
534536

535537
ul {
536538
@include unlist();
537-
}
538-
539-
ul {
540539
margin-top: -1.7em;
541540
}
542541

@@ -739,6 +738,7 @@ table.listing {
739738
}
740739
}
741740

741+
// stylelint-disable no-duplicate-selectors
742742

743743
// Transitions
744744
.listing {

client/scss/components/_loading-mask.scss

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "sass:map";
12
// Loading mask: overlays a certain area with a loading spinner and a faded out cover to prevent interaction
23
.loading-mask {
34
&.loading {
@@ -26,9 +27,9 @@
2627
left: 50%;
2728
top: 50%;
2829
margin: -15px 0 0 -15px;
29-
font-family: wagtail;
30+
font-family: $font-wagtail-icons;
3031
animation: spin-wag 0.5s infinite linear;
31-
content: map-get($icons, 'spinner');
32+
content: map.get($icons, 'spinner');
3233
z-index: 2;
3334
color: $color-teal;
3435
}

client/scss/components/_main-nav.scss

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "sass:map";
2+
13
.nav-wrapper {
24
position: relative;
35
margin-left: -$menu-width;
@@ -257,10 +259,10 @@
257259
}
258260

259261
&:before {
260-
font-family: wagtail;
262+
font-family: $font-wagtail-icons;
261263
font-weight: 200;
262264
text-transform: none;
263-
content: map-get($icons, 'search');
265+
content: map.get($icons, 'search');
264266
display: block;
265267
height: 100%;
266268
line-height: 3.3em;
@@ -508,6 +510,7 @@ body.explorer-open {
508510
z-index: 5;
509511
}
510512

513+
// stylelint-disable-next-line no-duplicate-selectors
511514
.nav-wrapper {
512515
z-index: 2;
513516
}
@@ -520,6 +523,7 @@ body.explorer-open {
520523
// .content-wrapper {
521524
// z-index: 3;
522525
// }
526+
// stylelint-disable-next-line no-duplicate-selectors
523527
.nav-submenu {
524528
z-index: 6;
525529
}

client/scss/components/_messages.scss

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Messages are specific to Django's 'Messaging' system which adds messages into the session,
22
// for display on the next page visited. These appear as an animated banner at the top of the page.
3-
//
43
// For inline help text, see typography.scss
54
.messages {
65
position: relative;

0 commit comments

Comments
 (0)