Skip to content

Commit 8f75064

Browse files
committed
💄 Add responsive utility classes
1 parent 58f3223 commit 8f75064

File tree

3 files changed

+755
-4
lines changed

3 files changed

+755
-4
lines changed

src/pages/css/utilities.astro

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import Layout from '@static/Layout.astro'
44
55
import Card from '@components/Card/Card.astro'
66
7+
const breakpoints: any = {
8+
'none': 3,
9+
'xs': 4,
10+
'sm': 4,
11+
'md': 6,
12+
'lg': 8
13+
}
14+
715
const spacings = [
816
'xxs',
917
'xs',
@@ -126,4 +134,22 @@ const wraps = [
126134
</Card>
127135
))}
128136
</div>
137+
138+
<h3>Grid</h3>
139+
{Object.keys(breakpoints).map(key => (
140+
<Fragment>
141+
{Array.from({ length: breakpoints[key] - 1 }, (_, i) => i + 2).map(i => (
142+
<div class:list={[
143+
'grid my',
144+
key === 'none' ? `col-${i}` : `${key}-${i}`
145+
]}>
146+
{Array(i).fill(0).map(_ => (
147+
<Card>
148+
<Box>{key}-{i}</Box>
149+
</Card>
150+
))}
151+
</div>
152+
))}
153+
</Fragment>
154+
))}
129155
</Layout>

src/scss/global/utility.scss

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ $alignments: (
4848
$class: string.slice($key, 2, -1) + $firstLetter;
4949
}
5050

51-
&.#{$class} { gap: $value; }
51+
&.#{$class} { gap: $value; }
52+
53+
@each $key, $v in $breakpoints {
54+
@include media($key) {
55+
&.#{$key}-#{$class} { gap: $value; }
56+
}
57+
}
5258
}
5359
}
5460

@@ -69,7 +75,27 @@ $alignments: (
6975
align-items: center;
7076
}
7177

72-
// Flex wraps
78+
@each $key, $value in $breakpoints {
79+
@include media($key) {
80+
@each $alignmentKey, $alignmentValue in $alignments {
81+
.#{$key}-#{$alignmentKey} {
82+
@if (string.index($alignmentKey, 'items')) {
83+
align-items: $alignmentValue;
84+
} @else {
85+
justify-content: $alignmentValue;
86+
}
87+
}
88+
}
89+
90+
.flex.#{$key}-center,
91+
.grid.#{$key}-center {
92+
justify-content: center;
93+
align-items: center;
94+
}
95+
}
96+
}
97+
98+
// Flex directions & wraps
7399
.flex {
74100
@include layout(flex, default);
75101

@@ -86,6 +112,24 @@ $alignments: (
86112
}
87113
}
88114

115+
@each $key, $value in $breakpoints {
116+
@include media($key) {
117+
.flex {
118+
@each $direction in $flexDirectionValues {
119+
&.#{$key}-#{$direction} {
120+
flex-direction: $direction;
121+
}
122+
}
123+
124+
@each $wrap in $flexWrapValues {
125+
&.#{$key}-#{$wrap} {
126+
flex-wrap: $wrap;
127+
}
128+
}
129+
}
130+
}
131+
}
132+
89133
// Grid columns
90134
.grid {
91135
@include layout(grid, default);

0 commit comments

Comments
 (0)