Skip to content

Commit 6af934c

Browse files
committed
Refactor SCSS structure and enhance modularity
- Transitioned to using `@use` and `@forward` for improved modularity across SCSS files. - Updated color and variable management to utilize the new `sass:map` and `sass:color` modules. - Standardized spacing and padding values using shared variables for consistency. - Improved media query handling with a new mixin structure. - Enhanced readability and maintainability of SCSS code by applying consistent formatting and syntax updates.
1 parent 518ebf8 commit 6af934c

36 files changed

Lines changed: 1264 additions & 1189 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"serve:fonts": "onchange \"src/fonts\" -- run-s build:fonts",
2222
"serve": "run-p sync serve:*",
2323
"build:html": "run-s minify-html",
24-
"build:css": "run-s lint-scss scss",
24+
"build:css": "run-s scss",
2525
"build:js": "run-s lint uglify",
2626
"build:images": "run-s imagemin",
2727
"build:fonts": "rsync -azP --delete src/fonts/ public/fonts/",

public/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scss/_functions.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@use "sass:map";
22
@use "sass:string";
3+
@use "sass:list";
34
@forward "variables";
45
@use "variables" as *;
56

@@ -16,23 +17,23 @@
1617
// Get font size
1718
@function get-font-size($elem) {
1819
@if map.get($font-size, $elem) {
19-
@return nth(map.get($font-scale, map.get($font-size, $elem)), 1);
20+
@return list.nth(map.get($font-scale, map.get($font-size, $elem)), 1);
2021
}
2122
@return null;
2223
}
2324

2425
// Get line height
2526
@function get-line-height($elem) {
2627
@if map.get($font-size, $elem) {
27-
@return nth(map.get($font-scale, map.get($font-size, $elem)), 2);
28+
@return list.nth(map.get($font-scale, map.get($font-size, $elem)), 2);
2829
}
2930
@return null;
3031
}
3132

3233
// Get kerning
3334
@function get-kerning($elem) {
3435
@if map.get($font-size, $elem) {
35-
@return nth(map.get($font-scale, map.get($font-size, $elem)), 3);
36+
@return list.nth(map.get($font-scale, map.get($font-size, $elem)), 3);
3637
}
3738
@return null;
3839
}

src/scss/_variables.scss

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "sass:map"; // Add map module
2+
13
// Core color palette (raw values)
24
$palette-colors: (
35
light: (
@@ -131,6 +133,51 @@ $breakpoints: (
131133
xlarge: 1200px,
132134
);
133135

136+
// Spacing unit
137+
$spacing-unit: 1rem !default; // Approx 16px
138+
139+
// Shared spacing values
140+
$spacing--shared-v: $spacing-unit * 1.5 !default; // 1.5rem / 24px
141+
$spacing--shared-h: $spacing-unit * 1.5 !default; // 1.5rem / 24px
142+
143+
// Figure spacing
144+
$spacing--figure-v: $spacing-unit * 2 !default; // 2rem / 32px
145+
$spacing--figure-h: 0 !default;
146+
$spacing--figcaption-v: $spacing-unit * 0.75 !default; // 0.75rem / 12px
147+
$spacing--figcaption-h: $spacing-unit * 1.5 !default; // 1.5rem / 24px
148+
149+
// Table spacing
150+
$spacing--table-cell-v: $spacing-unit * 0.75 !default; // 0.75rem / 12px
151+
$spacing--table-cell-h: $spacing-unit * 0.75 !default; // 0.75rem / 12px
152+
153+
// Image radius
154+
$img-radius: 4px !default;
155+
156+
// Image larger helper extra width
157+
$image-larger--extra-width: $spacing-unit * 4 !default; // 4rem / 64px
158+
159+
// Container padding
160+
$container--padding__mobile: $spacing-unit * 1.5 !default; // 1.5rem / 24px
161+
$container--padding__desktop: $spacing-unit * 2 !default; // 2rem / 32px
162+
163+
// Container max widths
164+
$container--width: map.get($breakpoints, large) !default; // 992px
165+
$container--width-sm: map.get($breakpoints, medium) !default; // 768px
166+
$container--width-xs: map.get($breakpoints, small) !default; // 480px
167+
168+
// Button/Form variables
169+
$button-form--height: 48px !default;
170+
$button-form--border-width: 2px !default;
171+
$button-form--border-style: solid !default;
172+
$button--padding-h: $spacing-unit * 1.5 !default; // 24px
173+
$button--radius: 4px !default;
174+
$button--transform: none !default;
175+
$button-loading--thickness: 2px !default;
176+
$button-form-sm--height: 40px !default;
177+
$button-sm--padding-h: $spacing-unit * 1.25 !default; // 20px
178+
$button-group-padding: $spacing-unit !default; // 16px
179+
$button--max-size-mobile: 240px !default;
180+
134181
// Scroll reveal animation amounts
135182
$scroll-reveal--transition-duration: 0.6s !default;
136183
$scroll-reveal--transition-timing: ease-in-out !default;

src/scss/core/base/_base.scss

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use "sass:map";
2+
@use "sass:math";
23
@use "../../variables" as *;
34
@use "../../functions" as fn;
45
@use "../../colors" as c;
@@ -15,14 +16,14 @@ html {
1516
}
1617

1718
body {
18-
background: map.get($colors, bg, body);
19+
background: map.get(c.$colors, bg, body);
1920
-moz-osx-font-smoothing: grayscale;
2021
-webkit-font-smoothing: antialiased;
2122
}
2223

2324
hr {
2425
border: 0;
25-
@include divider();
26+
@include mx.divider();
2627
margin-top: $spacing--shared-v;
2728
margin-bottom: $spacing--shared-v;
2829
}
@@ -47,13 +48,13 @@ ol {
4748

4849
li {
4950
&:not(:last-child) {
50-
margin-bottom: $spacing--shared-v / 2;
51+
margin-bottom: math.div($spacing--shared-v, 2);
5152
}
5253
}
5354

5455
li > ul,
5556
li > ol {
56-
margin-top: $spacing--shared-v / 2;
57+
margin-top: math.div($spacing--shared-v, 2);
5758
margin-bottom: 0;
5859
}
5960

@@ -63,7 +64,7 @@ dl {
6364
}
6465

6566
dt {
66-
@include font-weight(strong);
67+
@include mx.font-weight(strong);
6768
}
6869

6970
dd {
@@ -93,7 +94,7 @@ figcaption {
9394

9495
// tables
9596
table {
96-
@include font-size(table);
97+
@include mx.font-size(table);
9798
border-collapse: collapse;
9899
margin-bottom: $spacing--shared-v;
99100
width: 100%;
@@ -104,7 +105,7 @@ tr {
104105
}
105106

106107
th {
107-
@include font-weight(strong);
108+
@include mx.font-weight(strong);
108109
text-align: left;
109110
}
110111

@@ -123,7 +124,7 @@ td {
123124

124125
.invert-color {
125126
hr {
126-
@include divider(false, inverse);
127+
@include mx.divider(false, inverse);
127128
}
128129

129130
tr {

src/scss/core/base/_helpers.scss

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
@use "sass:map";
2+
@use "../../variables" as *;
3+
@use "../../functions" as fn;
4+
@use "../../colors" as c;
5+
@use "../../mixins" as mx;
6+
17
// Hide elements, for screen readers only
28
.screen-reader {
39
position: absolute;
410
width: 1px;
511
height: 1px;
612
padding: 0;
713
overflow: hidden;
8-
clip: rect(0,0,0,0);
14+
clip: rect(0, 0, 0, 0);
915
white-space: nowrap;
1016
border: 0;
1117
}
@@ -22,15 +28,15 @@
2228

2329
// Text alignment
2430
.ta-l {
25-
text-align: left;
31+
text-align: left;
2632
}
2733

2834
.ta-c {
29-
text-align: center;
35+
text-align: center;
3036
}
3137

3238
.ta-r {
33-
text-align: right;
39+
text-align: right;
3440
}
3541

3642
// Font weight
@@ -52,49 +58,48 @@
5258

5359
// Text color
5460
.text-color-high {
55-
color: color(high-contrast);
61+
color: map.get(c.$colors, text, high-contrast);
5662
}
5763

5864
.text-color-mid {
59-
color: color(mid-contrast);
65+
color: map.get(c.$colors, text, mid-contrast);
6066
}
6167

6268
.text-color-low {
63-
color: color(low-contrast);
69+
color: map.get(c.$colors, text, low-contrast);
6470
}
6571

6672
.text-color-primary {
67-
color: color(primary);
73+
color: map.get(c.$colors, text, primary);
6874
}
6975

7076
.text-color-secondary {
71-
color: color(secondary);
77+
color: map.get(c.$colors, text, secondary);
7278
}
7379

7480
.text-color-error {
75-
color: color(error);
81+
color: map.get(c.$colors, text, error);
7682
}
7783

7884
.text-color-warning {
79-
color: color(warning);
85+
color: map.get(c.$colors, text, warning);
8086
}
8187

8288
.text-color-success {
83-
color: color(success);
89+
color: map.get(c.$colors, text, success);
8490
}
8591

8692
.invert-color {
87-
8893
.text-color-high {
89-
color: color(high-contrast-inverse);
94+
color: map.get(c.$colors, text, high-contrast-inverse);
9095
}
9196

9297
.text-color-mid {
93-
color: color(mid-contrast-inverse);
98+
color: map.get(c.$colors, text, mid-contrast-inverse);
9499
}
95100

96101
.text-color-low {
97-
color: color(low-contrast-inverse);
102+
color: map.get(c.$colors, text, low-contrast-inverse);
98103
}
99104
}
100105

@@ -119,13 +124,13 @@
119124
// Helper class for coloured bg
120125
.has-bg-color {
121126
position: relative;
122-
background-color: color-bg(bg-color);
127+
background-color: map.get(c.$colors, bg, bg-color);
123128
z-index: 0;
124129
}
125130

126131
// Helper class for box shadow
127132
.has-shadow {
128-
box-shadow: color-bg(shadow);
133+
box-shadow: map.get(c.$colors, bg, shadow);
129134
}
130135

131136
img.has-shadow {
@@ -134,21 +139,20 @@ img.has-shadow {
134139

135140
// Dividers
136141
.has-top-divider {
137-
@include divider(before);
142+
@include mx.divider(before);
138143
}
139144

140145
.has-bottom-divider {
141-
@include divider(after);
146+
@include mx.divider(after);
142147
}
143148

144149
.invert-color {
145-
146150
.has-top-divider {
147-
@include divider(before, inverse);
151+
@include mx.divider(before, inverse);
148152
}
149153

150154
.has-bottom-divider {
151-
@include divider(after, inverse);
155+
@include mx.divider(after, inverse);
152156
}
153157
}
154158

@@ -184,7 +188,7 @@ img.has-shadow {
184188
left: 0;
185189
width: 100%;
186190
height: 100%;
187-
}
191+
}
188192
}
189193

190194
// Spacing, margin
@@ -502,8 +506,7 @@ img.has-shadow {
502506
padding-top: 64px;
503507
}
504508

505-
@include media( '<=medium' ) {
506-
509+
@include mx.media("<=medium") {
507510
.ta-l-mobile {
508511
text-align: left;
509512
}
@@ -562,11 +565,10 @@ img.has-shadow {
562565

563566
.spacer-64-mobile {
564567
padding-top: 64px;
565-
}
568+
}
566569
}
567570

568-
@include media( '>medium' ) {
569-
571+
@include mx.media(">medium") {
570572
.ta-l-desktop {
571573
text-align: left;
572574
}

src/scss/core/base/_typography.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ h6,
1818
.h6 {
1919
@include mx.font-family(heading);
2020
@include mx.font-weight(heading);
21-
color: map-get(c.$color, heading);
21+
color: map.get(c.$colors, heading);
2222
clear: both;
2323
}
2424

@@ -59,7 +59,7 @@ blockquote {
5959
@include mx.font-weight(bquote);
6060
margin: 1.5em 0;
6161
padding: 0 1em;
62-
border-left: 3px solid map-get(c.$border-color, divider);
62+
border-left: 3px solid map.get(c.$colors, border, divider);
6363

6464
&:first-child {
6565
margin-top: 0;
@@ -83,7 +83,7 @@ var {
8383
@include mx.font-size(code);
8484
padding: 0.2em 0.4em;
8585
margin: 0;
86-
background: map.get(c.$bg-color, code);
86+
background: map.get(c.$colors, bg, code);
8787
border-radius: 3px;
8888
}
8989

0 commit comments

Comments
 (0)