Skip to content

Commit 36071da

Browse files
committed
refactor: abstract checkbox presentation to standalone component
Moves the presentation logic from the `md-checkbox` to a `md-pseudo-checkbox` that can be re-used in other components, like `md-select` and `md-selection-list`. Renames and refactors a bunch of CSS classes, unit tests, properties etc. Relates to #2412.
1 parent b49bfce commit 36071da

13 files changed

+847
-644
lines changed

src/lib/checkbox/_checkbox-theme.scss

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,9 @@
22

33

44
@mixin md-checkbox-theme($theme) {
5-
$is-dark-theme: map-get($theme, is-dark);
65
$primary: map-get($theme, primary);
76
$accent: map-get($theme, accent);
87
$warn: map-get($theme, warn);
9-
$background: map-get($theme, background);
10-
11-
12-
// The color of the checkbox border.
13-
$checkbox-border-color: if($is-dark-theme, rgba(white, 0.7), rgba(black, 0.54)) !default;
14-
15-
// The color of the checkbox's checkmark / mixedmark.
16-
$checkbox-mark-color: md-color($background, background);
17-
18-
// NOTE(traviskaufman): While the spec calls for translucent blacks/whites for disabled colors,
19-
// this does not work well with elements layered on top of one another. To get around this we
20-
// blend the colors together based on the base color and the theme background.
21-
$white-30pct-opacity-on-dark: #686868;
22-
$black-26pct-opacity-on-light: #b0b0b0;
23-
$disabled-color: if($is-dark-theme, $white-30pct-opacity-on-dark, $black-26pct-opacity-on-light);
24-
25-
.md-checkbox-frame {
26-
border-color: $checkbox-border-color;
27-
}
28-
29-
.md-checkbox-checkmark {
30-
fill: $checkbox-mark-color;
31-
}
32-
33-
.md-checkbox-checkmark-path {
34-
// !important is needed here because a stroke must be set as an attribute on the SVG in order
35-
// for line animation to work properly.
36-
stroke: $checkbox-mark-color !important;
37-
}
38-
39-
.md-checkbox-mixedmark {
40-
background-color: $checkbox-mark-color;
41-
}
42-
43-
.md-checkbox-indeterminate, .md-checkbox-checked {
44-
&.md-primary .md-checkbox-background {
45-
background-color: md-color($primary, 500);
46-
}
47-
48-
&.md-accent .md-checkbox-background {
49-
background-color: md-color($accent, 500);
50-
}
51-
52-
&.md-warn .md-checkbox-background {
53-
background-color: md-color($warn, 500);
54-
}
55-
}
56-
57-
.md-checkbox-disabled {
58-
&.md-checkbox-checked, &.md-checkbox-indeterminate {
59-
.md-checkbox-background {
60-
background-color: $disabled-color;
61-
}
62-
}
63-
64-
&:not(.md-checkbox-checked) {
65-
.md-checkbox-frame {
66-
border-color: $disabled-color;
67-
}
68-
}
69-
}
708

719
.md-checkbox:not(.md-checkbox-disabled) {
7210
&.md-primary .md-checkbox-ripple .md-ripple-foreground {

src/lib/checkbox/checkbox.html

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,12 @@
2020
[mdRippleCentered]="true"
2121
[mdRippleSpeedFactor]="0.3"
2222
mdRippleBackgroundColor="rgba(0, 0, 0, 0)"></div>
23-
<div class="md-checkbox-frame"></div>
24-
<div class="md-checkbox-background">
25-
<svg version="1.1"
26-
class="md-checkbox-checkmark"
27-
xmlns="http://www.w3.org/2000/svg"
28-
viewBox="0 0 24 24"
29-
xml:space="preserve">
30-
<path class="md-checkbox-checkmark-path"
31-
fill="none"
32-
stroke="white"
33-
d="M4.1,12.7 9,17.6 20.3,6.3"/>
34-
</svg>
35-
<!-- Element for rendering the indeterminate state checkbox. -->
36-
<div class="md-checkbox-mixedmark"></div>
37-
</div>
23+
24+
<md-pseudo-checkbox
25+
[color]="color"
26+
[checked]="checked"
27+
[indeterminate]="indeterminate"
28+
[disabled]="disabled"></md-pseudo-checkbox>
3829
</div>
3930
<span class="md-checkbox-label">
4031
<ng-content></ng-content>

0 commit comments

Comments
 (0)