Skip to content

Commit 6e203e6

Browse files
committed
feat(core): add border-radius and spacing vars
1 parent 1c53c9e commit 6e203e6

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

packages/core/src/_base.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
@use "chip/chip";
2929
@use "table/table";
3030
@use "theme/theme";
31+
@use "border-radius";
32+
@use "spacing";
3133
@use "dialog/dialog";
3234
@use "sheet/sheet";
3335
@use "transition/transition";
@@ -386,6 +388,8 @@ $_layer-order: (
386388
///
387389
@mixin variables {
388390
@include theme.theme-variables;
391+
@include border-radius.variables;
392+
@include spacing.variables;
389393
@include typography.typography-variables;
390394
@include app-bar.variables;
391395
@include autocomplete.variables;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
@use "utils";
2+
3+
/// Set to `true` to disable the border radius variables. You probably don't
4+
/// want to do this.
5+
/// @type Boolean
6+
$disable-everything: false !default;
7+
8+
/// No Border Radius.
9+
///
10+
/// @type Number
11+
$none: 0 !default;
12+
13+
/// Extra Small Border Radius.
14+
///
15+
/// @type Number
16+
$xs: 0.25rem !default;
17+
18+
/// Small Border Radius.
19+
///
20+
/// @type Number
21+
$sm: 0.5rem !default;
22+
23+
/// Medium Border Radius.
24+
///
25+
/// @type Number
26+
$md: 0.75rem !default;
27+
28+
/// Large Border Radius.
29+
///
30+
/// @type Number
31+
$lg: 1rem !default;
32+
33+
/// Extra Large Border Radius.
34+
///
35+
/// @type Number
36+
$xl: 1.75rem !default;
37+
38+
/// Full Border Radius.
39+
///
40+
/// @type Number
41+
$full: 50% !default;
42+
43+
/// The available configurable css variables and mostly used internally for the
44+
/// `get-var`, `set-var`, and `use-var` utils.
45+
/// @type List
46+
$variables: (none, xs, sm, md, lg, xl, full);
47+
48+
/// @param {String} name - The supported variable name
49+
/// @param {any} fallback [null] - An optional fallback value
50+
/// @returns {String} a `var()` statement
51+
@function get-var($name, $fallback: null) {
52+
$var: utils.get-var-name($variables, $name, "border-radius");
53+
@if $fallback {
54+
@return var(#{$var}, #{$fallback});
55+
}
56+
57+
@return var(#{$var});
58+
}
59+
60+
/// @param {String} name - The supported variable name
61+
/// @param {any} value - The value to set the variable to. Supports `null` which
62+
/// will just be a no-op.
63+
@mixin set-var($name, $value) {
64+
@if $value {
65+
#{utils.get-var-name($variables, $name, "border-radius")}: #{$value};
66+
}
67+
}
68+
69+
/// @param {String} property - The css property to apply the variable to
70+
/// @param {String} name [$property] - The supported variable name
71+
/// @param {any} fallback [null] - An optional fallback value if the variable
72+
/// has not been set
73+
@mixin use-var($property, $name: $property, $fallback: null) {
74+
#{$property}: get-var($name, $fallback);
75+
}
76+
77+
/// Conditionally applies the css variables based on feature flags
78+
@mixin variables {
79+
@if not $disable-everything {
80+
@include set-var(none, $none);
81+
@include set-var(xs, $xs);
82+
@include set-var(sm, $sm);
83+
@include set-var(md, $md);
84+
@include set-var(lg, $lg);
85+
@include set-var(xl, $xl);
86+
@include set-var(full, $full);
87+
}
88+
}

packages/core/src/_core.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
@forward "theme/a11y";
99
@forward "theme/colors";
1010
@forward "theme/theme";
11+
@forward "border-radius" as border-radius-*;
12+
@forward "spacing" as spacing-*;
1113
@forward "typography/typography";
1214
@forward "transition/transition";
1315
@forward "box-shadows";

packages/core/src/_spacing.scss

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
@use "utils";
2+
3+
/// Set to `true` to disable all the spacing variables. You probably don't want
4+
/// to do this.
5+
/// @type Boolean
6+
$disable-everything: false !default;
7+
8+
/// No spacing. Generally applied as `gap`, `padding`, or `margin`.
9+
///
10+
/// @type Number
11+
$none: 0 !default;
12+
13+
/// Extra Small Spacing. Generally applied as `gap`, `padding`, or `margin`.
14+
///
15+
/// @type Number
16+
$xs: 0.25rem !default;
17+
18+
/// Small Spacing. Generally applied as `gap`, `padding`, or `margin`.
19+
///
20+
/// @type Number
21+
$sm: 0.5rem !default;
22+
23+
/// Medium Spacing. Generally applied as `gap`, `padding`, or `margin`.
24+
///
25+
/// @type Number
26+
$md: 1rem !default;
27+
28+
/// Large Spacing. Generally applied as `gap`, `padding`, or `margin`.
29+
///
30+
/// @type Number
31+
$lg: 1.5rem !default;
32+
33+
/// Extra Large Spacing. Generally applied as `gap`, `padding`, or `margin`.
34+
///
35+
/// @type Number
36+
$xl: 2rem !default;
37+
38+
/// The available configurable css variables and mostly used internally for the
39+
/// `get-var`, `set-var`, and `use-var` utils.
40+
/// @type List
41+
$variables: (none, xs, sm, md, lg, xl);
42+
43+
/// @param {String} name - The supported variable name
44+
/// @param {any} fallback [null] - An optional fallback value
45+
/// @returns {String} a `var()` statement
46+
@function get-var($name, $fallback: null) {
47+
$var: utils.get-var-name($variables, $name, "spacing");
48+
@if $fallback {
49+
@return var(#{$var}, #{$fallback});
50+
}
51+
52+
@return var(#{$var});
53+
}
54+
55+
/// @param {String} name - The supported variable name
56+
/// @param {any} value - The value to set the variable to. Supports `null` which
57+
/// will just be a no-op.
58+
@mixin set-var($name, $value) {
59+
@if $value {
60+
#{utils.get-var-name($variables, $name, "spacing")}: #{$value};
61+
}
62+
}
63+
64+
/// @param {String} property - The css property to apply the variable to
65+
/// @param {String} name [$property] - The supported variable name
66+
/// @param {any} fallback [null] - An optional fallback value if the variable
67+
/// has not been set
68+
@mixin use-var($property, $name: $property, $fallback: null) {
69+
#{$property}: get-var($name, $fallback);
70+
}
71+
72+
/// Conditionally applies the css variables based on feature flags
73+
@mixin variables {
74+
@if not $disable-everything {
75+
@include set-var(none, $none);
76+
@include set-var(xs, $xs);
77+
@include set-var(sm, $sm);
78+
@include set-var(md, $md);
79+
@include set-var(lg, $lg);
80+
@include set-var(xl, $xl);
81+
}
82+
}

0 commit comments

Comments
 (0)