Skip to content

Commit a0073ec

Browse files
authored
Add Block Size Utilities (#2203)
In a recent WordPress change I had use for a `u-block-size-full` util but it didn't exist. This adds both "full" and "auto" size utils for the block direction.
1 parent 2cd3251 commit a0073ec

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

.changeset/thin-schools-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudfour/patterns": minor
3+
---
4+
5+
Add Block Size Utilities: Adds "full" and "auto" size utility classes for the `block` direction.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="demo-u-size-block">
2+
<div style="height:150px;">
3+
<div class="u-size-block-full u-pad-n1 u-rounded t-dark t-alternate u-text-center">
4+
full (in a 150px tall container)
5+
</div>
6+
</div>
7+
<div style="height:150px;">
8+
<div class="u-size-block-auto u-pad-n1 u-rounded t-dark t-alternate u-text-center">
9+
auto (in a 150px tall container)
10+
</div>
11+
</div>
12+
</div>

src/utilities/size/demo/styles.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
}
99
}
1010

11+
.demo-u-size-block {
12+
display: flex;
13+
flex-direction: column;
14+
gap: 1em;
15+
}
16+
1117
.demo-u-size-responsive {
1218
display: flex;
1319
gap: 1em;

src/utilities/size/size.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,21 @@
2121
}
2222
}
2323

24+
// Set the block size styles in a mixin. The suffix will let us easily append
25+
// breakpoint suffixes.
26+
@mixin _block-size-utilities($suffix: '') {
27+
.u-size-block-full#{$suffix} {
28+
block-size: 100% !important;
29+
}
30+
31+
.u-size-block-auto#{$suffix} {
32+
block-size: auto !important;
33+
}
34+
}
35+
2436
// Include the default versions (no media queries)
2537
@include _inline-size-utilities;
38+
@include _block-size-utilities;
2639

2740
// Include responsive versions. This would be simpler if we could use the
2841
// `breakpoint-classes` mixin instead, but in this case we want all of the
@@ -31,4 +44,5 @@
3144
@include media-query.breakpoint-loop using ($key) {
3245
$suffix: \@#{$key};
3346
@include _inline-size-utilities($suffix);
47+
@include _block-size-utilities($suffix);
3448
}

src/utilities/size/size.stories.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Canvas, Meta, Story } from '@storybook/addon-docs';
22
import inlineSizeDemo from './demo/inline-size.twig';
3+
import blockSizeDemo from './demo/block-size.twig';
34
import responsiveDemo from './demo/responsive.twig';
45
import './demo/styles.scss';
56

@@ -34,6 +35,17 @@ Utilities beginning with `u-size-inline-` specify the `inline-size` of an elemen
3435
<Story name="Inline size (Width)">{() => inlineSizeDemo()}</Story>
3536
</Canvas>
3637

38+
## Block size
39+
40+
Utilities beginning with `u-size-block-` specify the `block-size` of an element:
41+
42+
- `u-size-block-full` sets the `block-size` to `100%` of the container.
43+
- `u-size-block-auto` sets the `block-size` to the natural value for the element.
44+
45+
<Canvas>
46+
<Story name="Block size (Height)">{() => blockSizeDemo()}</Story>
47+
</Canvas>
48+
3749
## Responsive
3850

3951
All of these utilities include responsive variations. Appending `@{breakpoint}` to the end of the class name will cause the utility to change for the given breakpoint.

0 commit comments

Comments
 (0)