-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Expand file tree
/
Copy path_button-base.scss
More file actions
182 lines (155 loc) · 6.03 KB
/
_button-base.scss
File metadata and controls
182 lines (155 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
@use '../core/tokens/token-utils';
@use '../core/style/layout-common';
// Adds styles necessary to provide stateful interactions with the button. This includes providing
// content for the state container's ::before and ::after so that they can be given a background
// color and opacity for states like hover, active, and focus. Additionally, adds styles to the
// ripple and state container so that they fill the button, match the border radius, and avoid
// pointer events.
@mixin mat-private-button-interactive($focus-indicator-inherits-shape: true) {
-webkit-tap-highlight-color: transparent;
// The ripple container should match the bounds of the entire button.
.mat-mdc-button-ripple,
.mat-mdc-button-persistent-ripple,
.mat-mdc-button-persistent-ripple::before {
@include layout-common.fill;
// Disable pointer events for the ripple container and state overlay because the container
// will overlay the user content and we don't want to disable mouse events on the user content.
// Pointer events can be safely disabled because the ripple trigger element is the host element.
pointer-events: none;
// Inherit the border radius from the parent so that state overlay and ripples don't exceed the
// parent button boundaries. Note that an inherited border radius does not work properly if
// the actual button element does have a border because it causes the inner content to be
// smaller. We have special logic for stroked buttons to handle this scenario.
border-radius: inherit;
}
// This style used to be applied by the MatRipple
// directive, which is no longer attached to this element.
.mat-mdc-button-ripple {
overflow: hidden;
}
// We use ::before so that we can reuse some of MDC's theming.
.mat-mdc-button-persistent-ripple::before {
content: '';
opacity: 0;
}
// The content should appear over the state and ripple layers, otherwise they may adversely affect
// the accessibility of the text content.
.mdc-button__label,
.mat-icon {
z-index: 1;
position: relative;
}
// The focus indicator should match the bounds of the entire button.
.mat-focus-indicator {
@include layout-common.fill();
@if ($focus-indicator-inherits-shape) {
border-radius: inherit;
}
}
&:focus-visible > .mat-focus-indicator::before {
content: '';
@if ($focus-indicator-inherits-shape) {
border-radius: inherit;
}
}
}
@mixin mat-private-button-ripple(
$ripple-color-token, $state-layer-color-token, $disabled-state-layer-color-token,
$hover-state-layer-opacity-token, $focus-state-layer-opacity-token,
$pressed-state-layer-opacity-token, $fallbacks
) {
.mat-ripple-element {
background-color: token-utils.slot($ripple-color-token, $fallbacks);
}
& > .mat-mdc-button-persistent-ripple::before {
background-color: token-utils.slot($state-layer-color-token, $fallbacks);
}
&.mat-mdc-button-disabled > .mat-mdc-button-persistent-ripple::before {
background-color: token-utils.slot($disabled-state-layer-color-token, $fallbacks);
}
&:hover > .mat-mdc-button-persistent-ripple::before {
opacity: token-utils.slot($hover-state-layer-opacity-token, $fallbacks);
}
&.cdk-program-focused,
&.cdk-keyboard-focused,
&.mat-mdc-button-disabled-interactive:focus {
> .mat-mdc-button-persistent-ripple::before {
opacity: token-utils.slot($focus-state-layer-opacity-token, $fallbacks);
}
}
&:active > .mat-mdc-button-persistent-ripple::before {
opacity: token-utils.slot($pressed-state-layer-opacity-token, $fallbacks);
}
}
// MDC's disabled buttons define a default cursor with pointer-events none. However, they select
// :disabled for this, which does not affect anchor tags.
// TODO(andrewseguin): Discuss with the MDC team about a mixin we can call for applying this style,
// and note that having pointer-events may have unintended side-effects, e.g. allowing the user
// to click the target underneath the button.
@mixin mat-private-button-disabled() {
// `[disabled]` shouldn't be necessary, but we keep it to maintain
// compatibility with apps setting it through host bindings.
&[disabled],
&.mat-mdc-button-disabled {
cursor: default;
pointer-events: none;
@content;
}
&.mat-mdc-button-disabled-interactive {
pointer-events: auto;
}
}
@mixin mat-private-button-touch-target(
$is-square,
$touch-target-size-token,
$touch-target-display-token,
$fallbacks) {
& > .mat-mdc-button-touch-target {
position: absolute;
top: 50%;
height: token-utils.slot($touch-target-size-token, $fallbacks);
display: token-utils.slot($touch-target-display-token, $fallbacks);
@if $is-square {
left: 50%;
width: token-utils.slot($touch-target-size-token, $fallbacks);
transform: translate(-50%, -50%);
} @else {
left: 0;
right: 0;
transform: translateY(-50%);
}
}
}
@mixin mat-private-button-horizontal-layout(
$icon-spacing-token, $icon-offset-token, $with-icon-horizontal-padding-token, $fallbacks) {
$icon-spacing: token-utils.slot($icon-spacing-token, $fallbacks, true);
$icon-offset: token-utils.slot($icon-offset-token, $fallbacks, true);
@if ($with-icon-horizontal-padding-token) {
// stylelint-disable-next-line selector-class-pattern
&:has(.material-icons, mat-icon, [matButtonIcon]) {
padding: 0 token-utils.slot($with-icon-horizontal-padding-token, $fallbacks, true);
}
}
// MDC expects button icons to contain this HTML content:
// ```html
// <span class="mdc-button__icon material-icons">favorite</span>
// ```
// However, Angular Material expects a `mat-icon` instead. The following
// styles will lay out the icons appropriately.
& > .mat-icon {
margin-right: $icon-spacing;
margin-left: $icon-offset;
[dir='rtl'] & {
margin-right: $icon-offset;
margin-left: $icon-spacing;
}
}
& > .mdc-button__label + .mat-icon {
margin-right: $icon-offset;
margin-left: $icon-spacing;
[dir='rtl'] & {
margin-right: $icon-spacing;
margin-left: $icon-offset;
}
}
}