Skip to content

Commit aacbbf6

Browse files
Use CSS variables for spacing (#873)
* Replace (nearly) all `@su` less variables with CSS variables * Add a comment explaining `--su1` Addresses https://github.com/StackExchange/Stacks/pull/873/files#r824834866 * Be explicit in calling out static spacing units Co-authored-by: Aaron Shekey <[email protected]>
1 parent 016ae13 commit aacbbf6

Some content is hidden

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

43 files changed

+583
-437
lines changed

docs/_data/atomics.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
{
2828
"class": "bs-ring",
29-
"output": "box-shadow: 0 0 0 @su4 var(--focus-ring);",
29+
"output": "box-shadow: 0 0 0 var(--su-static4) var(--focus-ring);",
3030
"hover": true,
3131
"focus": true
3232
}
@@ -1120,7 +1120,7 @@
11201120
},
11211121
{
11221122
"class": "outline-ring",
1123-
"output": "outline: solid @su4 var(--focus-ring);",
1123+
"output": "outline: solid var(--su-static4) var(--focus-ring);",
11241124
"define": "<p class='mb0'>Adds an outline that mimics our button focus styling.</p>",
11251125
"focus": true
11261126
}

docs/assets/less/stacks-documentation.less

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
@import "../../../lib/css/stacks.less"; // These are actual styles used in SO projects
1515

1616
.stacks-section {
17-
margin-top: @su48;
18-
margin-bottom: @su48;
17+
margin-top: var(--su48);
18+
margin-bottom: var(--su48);
1919
}
2020

2121
.stacks-header {
@@ -180,16 +180,16 @@
180180
// -- Section Title
181181
.stacks-h2 {
182182
font-size: var(--fs-headline1);
183-
padding-top: @su64 + @su24; // Hack for #anchor positioning
184-
margin-top: -@su64 + -@su24; // Hack for #anchor positioning
183+
padding-top: calc(var(--su96) - var(--su8)); // Hack for #anchor positioning
184+
margin-top: calc((var(--su96) - var(--su8)) * -1); // Hack for #anchor positioning
185185
}
186186

187187
// -- Sub-section Title
188188
.stacks-h3 {
189189
font-size: var(--fs-subheading);
190190
color: var(--fc-medium);
191-
padding-top: @su64 + @su24; // Hack for #anchor positioning
192-
margin-top: -@su64 + -@su24; // Hack for #anchor positioning
191+
padding-top: calc(var(--su96) - var(--su8)); // Hack for #anchor positioning
192+
margin-top: calc((var(--su96) - var(--su8)) * -1); // Hack for #anchor positioning
193193
}
194194

195195
.stacks-h4 {
@@ -219,7 +219,7 @@
219219
// -- Code Tag
220220
// ----------------------------------------------------------------------------
221221
.stacks-code {
222-
padding: 3px 5px @su2 @su4;
222+
padding: 3px 5px var(--su2) var(--su4);
223223
border-radius: var(--br-sm);
224224
background-color: var(--black-075);
225225
font-size: var(--fs-caption);
@@ -247,7 +247,7 @@
247247
// $ CODE STYLES
248248
// ----------------------------------------------------------------------------
249249
.stacks-preview {
250-
margin-bottom: @su48;
250+
margin-bottom: var(--su48);
251251
border-radius: var(--br-md);
252252
box-shadow: var(--bs-sm);
253253

@@ -272,7 +272,7 @@
272272

273273
// Preview area
274274
.stacks-preview--example {
275-
padding: @su16;
275+
padding: var(--su16);
276276
border-bottom-left-radius: var(--br-md);
277277
border-bottom-right-radius: var(--br-md);
278278
border: 1px solid var(--bc-medium);
@@ -300,7 +300,7 @@
300300

301301
// -- Preview Area
302302
.stacks-icon-preview {
303-
padding: @su8;
303+
padding: var(--su8);
304304
min-height: 4em;
305305
border-top-left-radius: var(--br-sm);
306306
border-top-right-radius: var(--br-sm);
@@ -319,7 +319,7 @@
319319
// ----------------------------------------------------------------------------
320320

321321
.stacks-flex-example--item {
322-
padding: @su8;
322+
padding: var(--su8);
323323
border: 1px solid var(--bc-medium);
324324
background-color: var(--black-075);
325325
font-family: var(--ff-mono);
@@ -331,8 +331,8 @@
331331
// $ COLORS
332332
// ----------------------------------------------------------------------------
333333
.stacks-swatch {
334-
width: @su32;
335-
height: @su32;
334+
width: var(--su-static32);
335+
height: var(--su-static32);
336336
}
337337

338338
// ============================================================================
@@ -401,17 +401,17 @@
401401
.stacks-theme-button {
402402
color: var(--black-300);
403403
position: relative;
404-
padding-right: @su24 !important;
404+
padding-right: var(--su-static24) !important;
405405

406406
&:after {
407407
content: "";
408408
position: absolute;
409409
z-index: var(--zi-active);
410-
top: calc(50% - 2px);
411-
right: @su12 - @su2;
410+
top: calc(50% - var(--su-static2));
411+
right: calc(var(--su-static12) - var(--su-static2));
412412
border-style: solid;
413-
border-width: @su4;
414-
border-top-width: @su4;
413+
border-width: var(--su-static4);
414+
border-top-width: var(--su-static4);
415415
border-bottom-width: 0;
416416
border-color: currentColor transparent;
417417
pointer-events: none;

docs/product/components/banners.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<!-- Override stacks classes for demos -->
1010
<style>
1111
.s-banner[aria-hidden=false] {
12-
-webkit-transform: translate3d(0, 63px, 0);
13-
transform: translate3d(0, 63px, 0);
12+
-webkit-transform: translate3d(0, calc(var(--su64) - var(--su1)), 0);
13+
transform: translate3d(0, calc(var(--su64) - var(--su1)), 0);
1414
}
1515
.s-banner[aria-hidden=false].is-pinned {
1616
-webkit-transform: translate3d(0, 0, 0);

lib/css/atomic/_stacks-borders.less

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,34 @@
4646
// ----------------------------------------------------------------------------
4747
// $$ All Sides
4848
#stacks-internals #responsify('.baw0', { border-width: 0 !important; });
49-
.baw1 { border-width: (@su2 / 2) !important; }
50-
.baw2 { border-width: @su2 !important; }
51-
.baw3 { border-width: @su4 !important; }
49+
.baw1 { border-width: var(--su-static1) !important; }
50+
.baw2 { border-width: var(--su-static2) !important; }
51+
.baw3 { border-width: var(--su-static4) !important; }
5252

5353
// $$ Top Border
5454
#stacks-internals #responsify('.btw0', { border-top-width: 0 !important; });
55-
.btw1 { border-top-width: (@su2 / 2) !important; }
56-
.btw2 { border-top-width: @su2 !important; }
57-
.btw3 { border-top-width: @su4 !important; }
55+
.btw1 { border-top-width: var(--su-static1) !important; }
56+
.btw2 { border-top-width: var(--su-static2) !important; }
57+
.btw3 { border-top-width: var(--su-static4) !important; }
5858

5959
// $$ Right Border
6060
#stacks-internals #responsify('.brw0', { border-right-width: 0 !important; });
61-
.brw1 { border-right-width: (@su2 / 2) !important; }
62-
.brw2 { border-right-width: @su2 !important; }
63-
.brw3 { border-right-width: @su4 !important; }
61+
.brw1 { border-right-width: var(--su-static1) !important; }
62+
.brw2 { border-right-width: var(--su-static2) !important; }
63+
.brw3 { border-right-width: var(--su-static4) !important; }
6464

6565
// $$ Bottom Border
6666
#stacks-internals #responsify('.bbw0', { border-bottom-width: 0 !important; });
67-
.bbw1 { border-bottom-width: (@su2 / 2) !important; }
68-
.bbw2 { border-bottom-width: @su2 !important; }
69-
.bbw3 { border-bottom-width: @su4 !important; }
67+
.bbw1 { border-bottom-width: var(--su-static1) !important; }
68+
.bbw2 { border-bottom-width: var(--su-static2) !important; }
69+
.bbw3 { border-bottom-width: var(--su-static4) !important; }
7070

7171
// $$ Left Border
7272
#stacks-internals #responsify('.blw0', { border-left-width: 0 !important; });
7373
.blw0 { border-left-width: 0 !important; }
74-
.blw1 { border-left-width: (@su2 / 2) !important; }
75-
.blw2 { border-left-width: @su2 !important; }
76-
.blw3 { border-left-width: @su4 !important; }
74+
.blw1 { border-left-width: var(--su-static1) !important; }
75+
.blw2 { border-left-width: var(--su-static2) !important; }
76+
.blw3 { border-left-width: var(--su-static4) !important; }
7777

7878
// $$ Y-Axis Border
7979
.byw0 { .btw0; .bbw0; }

lib/css/atomic/_stacks-flex.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
// $ FLEX SPACING
197197
// Insert spaces or gutters in between flex items
198198
// ----------------------------------------------------------------------------
199+
// TODO: Make this play nice with spacing units… or yeet this in the age of gap
199200
.gs2 { #stacks-internals #flex-builder-helpers .gutter-spacing(@su2); }
200201
.gs4 { #stacks-internals #flex-builder-helpers .gutter-spacing(@su4); }
201202
.gs6 { #stacks-internals #flex-builder-helpers .gutter-spacing(@su6); }

lib/css/atomic/_stacks-grid.less

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
// into its own section and documentation
2222
// ----------------------------------------------------------------------------
2323
#stacks-internals #responsify('.g0', { gap: 0 });
24-
#stacks-internals #responsify('.g1', { gap: @su1 });
25-
#stacks-internals #responsify('.g2', { gap: @su2 });
26-
#stacks-internals #responsify('.g4', { gap: @su4; });
27-
#stacks-internals #responsify('.g6', { gap: @su6; });
28-
#stacks-internals #responsify('.g8', { gap: @su8; });
29-
#stacks-internals #responsify('.g12', { gap: @su12; });
30-
#stacks-internals #responsify('.g16', { gap: @su16; });
31-
#stacks-internals #responsify('.g24', { gap: @su24; });
32-
#stacks-internals #responsify('.g32', { gap: @su32; });
33-
#stacks-internals #responsify('.g48', { gap: @su48; });
34-
#stacks-internals #responsify('.g64', { gap: @su64; });
24+
#stacks-internals #responsify('.g1', { gap: var(--su1) });
25+
#stacks-internals #responsify('.g2', { gap: var(--su2) });
26+
#stacks-internals #responsify('.g4', { gap: var(--su4); });
27+
#stacks-internals #responsify('.g6', { gap: var(--su6); });
28+
#stacks-internals #responsify('.g8', { gap: var(--su8); });
29+
#stacks-internals #responsify('.g12', { gap: var(--su12); });
30+
#stacks-internals #responsify('.g16', { gap: var(--su16); });
31+
#stacks-internals #responsify('.g24', { gap: var(--su24); });
32+
#stacks-internals #responsify('.g32', { gap: var(--su32); });
33+
#stacks-internals #responsify('.g48', { gap: var(--su48); });
34+
#stacks-internals #responsify('.g64', { gap: var(--su64); });
3535

3636
// ============================================================================
3737
// $ GRID FLOW

lib/css/atomic/_stacks-misc.less

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
// $ OUTLINE
268268
// ----------------------------------------------------------------------------
269269
.outline-none { outline: 0 !important; }
270-
.outline-ring { outline: solid @su4 var(--focus-ring); }
270+
.outline-ring { outline: solid var(--su-static4) var(--focus-ring); }
271271

272272
.f\:outline-ring {
273273
&:focus,
@@ -293,7 +293,7 @@
293293
.bs-lg { box-shadow: var(--bs-lg) !important; }
294294
.h\:bs-lg:hover { .bs-lg; }
295295
.bs-xl { box-shadow: var(--bs-xl) !important; }
296-
.bs-ring { box-shadow: 0 0 0 @su4 var(--focus-ring); }
296+
.bs-ring { box-shadow: 0 0 0 var(--su-static4) var(--focus-ring); }
297297
.h\:bs-ring:hover { .bs-ring; }
298298
.f\:bs-ring {
299299
&:focus,
@@ -303,12 +303,12 @@
303303
}
304304

305305
// -- Added hover styles for box-shadow
306-
.bs-sm.bs-hover:hover { box-shadow: 0 @su2 @su8 @black-050 !important; }
307-
.bs-md.bs-hover:hover { box-shadow: 0 @su4 @su8 @black-100 !important; }
308-
.bs-lg.bs-hover:hover { box-shadow: 0 @su4 @su12 fade(@black-300, 70%) !important; }
309-
.bs-i-sm.bs-hover:hover { box-shadow: inset 0 (@su2/2) @su8 0 fade(@black-200, 75%) !important; }
310-
.bs-i-md.bs-hover:hover { box-shadow: inset 0 (@su2/2) @su8 0 fade(@black-350, 80%) !important; }
311-
.bs-i-lg.bs-hover:hover { box-shadow: inset 0 (@su2/2) @su12 0 @black-350 !important; }
306+
.bs-sm.bs-hover:hover { box-shadow: 0 var(--su-static2) var(--su-static8) @black-050 !important; }
307+
.bs-md.bs-hover:hover { box-shadow: 0 var(--su-static4) var(--su-static8) @black-100 !important; }
308+
.bs-lg.bs-hover:hover { box-shadow: 0 var(--su-static4) var(--su-static12) fade(@black-300, 70%) !important; }
309+
.bs-i-sm.bs-hover:hover { box-shadow: inset 0 var(--su-static1) var(--su-static8) 0 fade(@black-200, 75%) !important; }
310+
.bs-i-md.bs-hover:hover { box-shadow: inset 0 var(--su-static1) var(--su-static8) 0 fade(@black-350, 80%) !important; }
311+
.bs-i-lg.bs-hover:hover { box-shadow: inset 0 var(--su-static1) var(--su-static12) 0 @black-350 !important; }
312312

313313
// ============================================================================
314314
// $ TRANSITIONS

0 commit comments

Comments
 (0)