Skip to content

Commit c6c616b

Browse files
committed
feat(button): added built-in support for rendering CircularProgress
If both the `@react-md/button` and `@react-md/progress` packages have been installed and imported in the same file, the button will automatically decrease the `CircularProgress`'s size to be more "dense" and be the same size as an icon.
1 parent 102efe7 commit c6c616b

4 files changed

Lines changed: 115 additions & 27 deletions

File tree

packages/button/src/_mixins.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
}
121121
@include rmd-button-base;
122122
@include rmd-states-surface;
123+
@if $rmd-button-circular-progress-size != null and mixin-exists(rmd-progress-theme-update-var) {
124+
@include rmd-progress-theme-update-var(circular-size, $rmd-button-circular-progress-size);
125+
}
123126

124127
&--text {
125128
@include rmd-button-text;

packages/button/src/_variables.scss

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// @group button
33
////
44

5+
@import '~@react-md/icon/dist/functions';
56
@import '~@react-md/theme/dist/helpers';
67
@import '~@react-md/theme/dist/mixins';
78
@import '~@react-md/theme/dist/variables';
@@ -103,6 +104,46 @@ $rmd-button-floating-z-index: $rmd-utils-temporary-element-z-index !default;
103104
/// @type Number
104105
$rmd-button-floating-margin: 1.5rem !default;
105106

107+
/// The size to use for a `CircularProgress` that exists as a child of the
108+
/// `Button`. The styles will only be created if this value is not `null`, the
109+
/// `@react-md/progress` package has been installed, and the
110+
/// `@react-md/progress`'s `mixin`s have been imported in the same file as the
111+
/// `@react-md/button`'s `mixin`s.
112+
///
113+
/// @example scss - Includes `CircularProgress` size<!-- no-compile -->
114+
/// @import '~@react-md/button/dist/mixins';
115+
/// @import '~@react-md/progress/dist/mixins';
116+
/// @import '~@react-md/utils/dist/mixins';
117+
///
118+
/// // can also manually set it to a different value if desired:
119+
/// // $rmd-button-circular-progress-size: 1.5rem;
120+
///
121+
/// // or @include react-md-button;
122+
/// @include react-md-utils;
123+
///
124+
/// @example scss - Does not include `CircularProgress` size<!-- no-compile -->
125+
/// // bad example since `@react-md/progress` was not imported
126+
/// @import '~@react-md/button/dist/mixins';
127+
/// @import '~@react-md/utils/dist/mixins';
128+
///
129+
/// // or @include react-md-button;
130+
/// @include react-md-utils;
131+
///
132+
/// @example scss - Opt-out of `CircularProgress` size<!-- no-compile -->
133+
/// @import '~@react-md/button/dist/mixins';
134+
/// @import '~@react-md/progress/dist/mixins';
135+
/// @import '~@react-md/utils/dist/mixins';
136+
///
137+
/// // manually set it to `null` to prevent it from being added
138+
/// $rmd-button-circular-progress-size: null;
139+
///
140+
/// // or @include react-md-button;
141+
/// @include react-md-utils;
142+
///
143+
/// @since 2.3.0
144+
/// @type String|Number
145+
$rmd-button-circular-progress-size: rmd-icon-theme-var(size) !default;
146+
106147
/// A Map of floating position styles to create. Each key will be made into a
107148
/// className by `&--floating-#{$key}` and each value will parsed as a style
108149
/// map. If you want to remove positions, override this variable with only the

0 commit comments

Comments
 (0)