Skip to content

Commit e8e7199

Browse files
authored
feat(material/checkbox): refactor pseudo-checkbox size styles (#25419)
* feat(material/checkbox): refactor pseudo-checkbox size styles * feat(material/checkbox): keep 16px
1 parent b863b14 commit e8e7199

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

src/material/_index.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
legacy-optgroup-typography, legacy-optgroup-theme;
7373
@forward './core/selection/pseudo-checkbox/pseudo-checkbox-theme' as pseudo-checkbox-* show
7474
pseudo-checkbox-color, pseudo-checkbox-typography, pseudo-checkbox-theme;
75+
@forward './core/selection/pseudo-checkbox/pseudo-checkbox-common' as pseudo-checkbox-* show
76+
pseudo-checkbox-legacy-size;
7577
@forward './core/focus-indicators/focus-indicators-theme' as strong-focus-indicators-* show
7678
strong-focus-indicators-color, strong-focus-indicators-theme;
7779
@forward './autocomplete/autocomplete-theme' as autocomplete-* show autocomplete-theme,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@use 'sass:math';
2+
@use '../../style/checkbox-common';
3+
4+
// Padding inside of a pseudo checkbox.
5+
$padding: checkbox-common.$border-width * 2;
6+
7+
/// Applies the styles that set the size of the pseudo checkbox
8+
@mixin size($box-size) {
9+
$mark-size: $box-size - (2 * $padding);
10+
11+
.mat-pseudo-checkbox {
12+
width: $box-size;
13+
height: $box-size;
14+
}
15+
16+
.mat-pseudo-checkbox-indeterminate::after {
17+
top: math.div($box-size - checkbox-common.$border-width, 2) -
18+
checkbox-common.$border-width;
19+
width: $box-size - 6px;
20+
}
21+
22+
.mat-pseudo-checkbox-checked::after {
23+
top: math.div($box-size, 2) - math.div($mark-size, 4) -
24+
math.div($box-size, 10) - checkbox-common.$border-width;
25+
width: $mark-size;
26+
height: math.div($mark-size - checkbox-common.$border-width, 2);
27+
}
28+
}
29+
30+
/// Applies the legacy size styles to the pseudo-checkbox
31+
@mixin legacy-size() {
32+
@include size(checkbox-common.$legacy-size);
33+
}

src/material/core/selection/pseudo-checkbox/pseudo-checkbox.scss

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22
@use '../../style/checkbox-common';
33
@use '../../style/private';
44
@use '../../style/variables';
5-
6-
// Padding inside of a pseudo checkbox.
7-
$_padding: checkbox-common.$border-width * 2;
8-
9-
// Size of the checkmark in a pseudo checkbox.
10-
$_checkmark-size: checkbox-common.$size - (2 * $_padding);
11-
5+
@use './pseudo-checkbox-common';
126

137
.mat-pseudo-checkbox {
14-
width: checkbox-common.$size;
15-
height: checkbox-common.$size;
168
border: checkbox-common.$border-width solid;
179
border-radius: 2px;
1810
cursor: pointer;
@@ -51,22 +43,19 @@ $_checkmark-size: checkbox-common.$size - (2 * $_padding);
5143
}
5244

5345
.mat-pseudo-checkbox-indeterminate::after {
54-
top: math.div(checkbox-common.$size - checkbox-common.$border-width, 2) -
55-
checkbox-common.$border-width;
5646
left: math.div(checkbox-common.$border-width, 2);
57-
width: checkbox-common.$size - 6px;
5847
opacity: 1;
5948
border-radius: 2px;
6049
}
6150

6251
.mat-pseudo-checkbox-checked::after {
63-
top: math.div(checkbox-common.$size, 2) - math.div($_checkmark-size, 4) -
64-
math.div(checkbox-common.$size, 10) - checkbox-common.$border-width;
65-
left: $_padding - checkbox-common.$border-width * 1.5;
66-
width: $_checkmark-size;
67-
height: math.div($_checkmark-size - checkbox-common.$border-width, 2);
52+
left: pseudo-checkbox-common.$padding - checkbox-common.$border-width * 1.5;
6853
border-left: checkbox-common.$border-width solid currentColor;
6954
transform: rotate(-45deg);
7055
opacity: 1;
7156
box-sizing: content-box;
7257
}
58+
59+
// TODO(andrewseguin): Change this to the non-legacy size once
60+
// the above mixins have landed internally.
61+
@include pseudo-checkbox-common.size(checkbox-common.$legacy-size);

src/material/core/style/_checkbox-common.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// The width/height of the checkbox element.
22
$size: 16px !default;
33

4+
// The width/height of the legacy-checkbox element.
5+
$legacy-size: 16px !default;
6+
47
// The width of the checkbox border shown when the checkbox is unchecked.
58
$border-width: 2px;
69

0 commit comments

Comments
 (0)