Skip to content

Commit 981c984

Browse files
committed
Put some SCSS magic numbers into constants
1 parent 0be0d49 commit 981c984

7 files changed

Lines changed: 52 additions & 15 deletions

File tree

src/components/about/hero.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import avatarPng from "@assets/avatar.png";
1515
display: grid;
1616
grid-template-areas: "avatar" "title" "subtitle";
1717
gap: v-size(2);
18-
margin-bottom: v-size(16);
18+
margin-bottom: v-const("section_spacing.medium");
1919
text-align: center;
2020
}
2121
picture {
@@ -35,7 +35,7 @@ import avatarPng from "@assets/avatar.png";
3535
section {
3636
grid-template-areas: "avatar title" "avatar subtitle";
3737
column-gap: v-size(10);
38-
margin-bottom: v-size(20);
38+
margin-bottom: v-const("section_spacing.large");
3939
text-align: left;
4040
}
4141
h1 {

src/components/about/section.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const { title, description } = Astro.props;
1010

1111
<style lang="scss">
1212
section {
13-
margin-bottom: v-size(16);
13+
margin-bottom: v-const("section_spacing.medium");
1414
}
1515

1616
@include m-large {
1717
section {
1818
display: flex;
1919
gap: v-size(5);
20-
margin-bottom: v-size(20);
20+
margin-bottom: v-const("section_spacing.large");
2121
}
2222
h2 {
2323
flex: 1 0 40%;

src/components/post-item.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ const { title, link, dateCreated, dateUpdated } = Astro.props;
2121

2222
<style lang="scss">
2323
li {
24-
margin-bottom: v-size(5);
24+
margin-bottom: v-const("section_spacing.xsmall");
2525
}
2626
li:last-child {
27-
margin-bottom: v-size(15);
27+
margin-bottom: v-const("section_spacing.medium");
2828
}
2929
p:last-child {
3030
font-style: italic;
3131
}
3232

3333
@include m-medium {
3434
li:last-child {
35-
margin-bottom: v-size(20);
35+
margin-bottom: v-const("section_spacing.large");
3636
}
3737
}
3838
</style>

src/components/projects/item-card.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ if ((image.width / image.height).toFixed(2) !== "1.78") {
2727
li {
2828
display: grid;
2929
row-gap: v-size(2);
30-
margin-bottom: v-size(10);
30+
margin-bottom: v-const("section_spacing.small");
3131
text-align: center;
3232
}
3333
li:where(:last-child) {
34-
margin-bottom: v-size(16);
34+
margin-bottom: v-const("section_spacing.medium");
3535
}
3636
li:not(:last-child)::after {
3737
content: "";
@@ -51,7 +51,7 @@ if ((image.width / image.height).toFixed(2) !== "1.78") {
5151
grid-template-columns: 1fr 1fr;
5252
grid-template-rows: auto auto 1fr;
5353
column-gap: v-size(5);
54-
margin-bottom: v-size(20);
54+
margin-bottom: v-const("section_spacing.large");
5555
text-align: left;
5656
}
5757
li::after {

src/styles/header.scss

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Variables
2+
3+
$initialLogoMenuWidth: v-size(14);
4+
15
// No JS layout
26

37
@include no-js {
@@ -6,7 +10,7 @@
610
gap: v-size(2);
711
justify-items: center;
812
width: 100%;
9-
margin: v-size(2) auto v-size(10);
13+
margin: v-size(2) auto v-const("section_spacing.small");
1014
}
1115
.nav-list {
1216
display: flex;
@@ -47,8 +51,8 @@
4751
display: grid;
4852
gap: v-size(5);
4953
justify-items: center;
50-
height: v-size(14);
51-
margin-bottom: v-size(10);
54+
height: $initialLogoMenuWidth;
55+
margin-bottom: v-const("section_spacing.small");
5256
overflow: hidden;
5357
}
5458
.logo {
@@ -132,7 +136,7 @@
132136

133137
.logo-svg,
134138
.menu-svg {
135-
width: v-size(14);
139+
width: $initialLogoMenuWidth;
136140
}
137141
.logo-svg {
138142
--svg-stroke-width: 6;
@@ -164,7 +168,7 @@
164168
}
165169
}
166170

167-
// Mode groups
171+
// Mode groups opacity
168172

169173
.mode-moon {
170174
opacity: 1;

src/styles/partials/_lib.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@use "sass:map";
2+
@use "sass:string";
3+
4+
@function deep-get($map, $key) {
5+
$value: $map;
6+
7+
@each $part in string.split($key, ".") {
8+
$value: map.get($value, $part);
9+
10+
@if $value == null {
11+
@error "Unknown key '#{$part}'";
12+
}
13+
}
14+
15+
@return $value;
16+
}

src/styles/partials/_variables.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@use "sass:list";
22
@use "sass:map";
33

4+
@use "lib";
5+
46
// Colors
57

68
@use "json:colors" as *;
@@ -46,3 +48,18 @@ $_units: (
4648
@function size($size, $unit: "rem") {
4749
@return list.nth($_sizes, $size) + map.get($_units, $unit);
4850
}
51+
52+
// Constants
53+
54+
$_consts: (
55+
"section_spacing": (
56+
"xsmall": size(5),
57+
"small": size(10),
58+
"medium": size(15),
59+
"large": size(20)
60+
)
61+
);
62+
63+
@function const($const) {
64+
@return lib.deep-get($_consts, $const);
65+
}

0 commit comments

Comments
 (0)