UNPKG

8.96 kBSCSSView Raw
1//
2// Copyright 2021 Google Inc-
3//
4// Permission is hereby granted, free of charge, to any person obtaining a copy
5// of this software and associated documentation files (the "Software"), to deal
6// in the Software without restriction, including without limitation the rights
7// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8// copies of the Software, and to permit persons to whom the Software is
9// furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software-
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT- IN NO EVENT SHALL THE
17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20// THE SOFTWARE-
21//
22
23// Selector '-mdc-*' should only be used in this project-
24// stylelint-disable selector-class-pattern --
25// Internal styling for Dialog MDC component-
26
27@use 'sass:map';
28@use 'sass:meta';
29@use '@material/elevation/elevation-theme';
30@use '@material/shape/shape';
31@use '@material/theme/keys';
32@use '@material/theme/theme';
33@use '@material/tokens/resolvers';
34@use '@material/button/button-text-theme';
35
36$light-theme: (
37 container-color: null,
38 container-elevation: null,
39 container-shadow-color: null,
40 container-shape: null,
41 with-divider-divider-color: null,
42 with-divider-divider-height: null,
43 with-icon-icon-size: null,
44 with-icon-icon-color: null,
45 subhead-font: null,
46 subhead-line-height: null,
47 subhead-size: null,
48 subhead-weight: null,
49 subhead-tracking: null,
50 subhead-color: null,
51 supporting-text-font: null,
52 supporting-text-line-height: null,
53 supporting-text-size: null,
54 supporting-text-weight: null,
55 supporting-text-tracking: null,
56 supporting-text-color: null,
57 action-label-text-font: null,
58 action-label-text-line-height: null,
59 action-label-text-size: null,
60 action-label-text-weight: null,
61 action-label-text-tracking: null,
62 action-label-text-color: null,
63 action-hover-state-layer-color: null,
64 action-hover-state-layer-opacity: null,
65 action-hover-label-text-color: null,
66 action-focus-state-layer-color: null,
67 action-focus-state-layer-opacity: null,
68 action-focus-label-text-color: null,
69 action-pressed-state-layer-color: null,
70 action-pressed-state-layer-opacity: null,
71 action-pressed-label-text-color: null,
72 // TODO(b/229523517): add headline token support to dialog
73 headline-color: null,
74 headline-font: null,
75 headline-line-height: null,
76 headline-size: null,
77 headline-tracking: null,
78 headline-weight: null,
79);
80
81$custom-property-prefix: 'dialog';
82
83@mixin theme($theme, $resolvers: resolvers.$material) {
84 @include theme.validate-theme-keys($light-theme, $theme);
85 $theme: _resolve-elevation($theme, map.get($resolvers, elevation));
86 @include keys.declare-custom-properties(
87 $theme,
88 $prefix: $custom-property-prefix
89 );
90}
91
92@mixin theme-styles($theme, $resolvers: resolvers.$material) {
93 @include theme.validate-theme-keys($light-theme, $theme);
94 $theme: keys.create-theme-properties(
95 $theme,
96 $prefix: $custom-property-prefix
97 );
98
99 @include _container-color(map.get($theme, container-color));
100 @include _container-elevation(
101 map.get($resolvers, elevation),
102 map.get($theme, container-elevation),
103 map.get($theme, container-shadow-color)
104 );
105 @include container-shape(map.get($theme, container-shape));
106 @include _divider-color(map.get($theme, with-divider-divider-color));
107 @include _divider-height(map.get($theme, with-divider-divider-height));
108 @include _icon-size(map.get($theme, with-icon-icon-size));
109 @include _icon-color(map.get($theme, with-icon-icon-color));
110 @include subhead-typography(
111 (
112 font: map.get($theme, subhead-font),
113 line-height: map.get($theme, subhead-line-height),
114 size: map.get($theme, subhead-size),
115 weight: map.get($theme, subhead-weight),
116 tracking: map.get($theme, subhead-tracking),
117 )
118 );
119 @include _subhead-color(map.get($theme, subhead-color));
120 @include _supporting-text-typography(
121 (
122 font: map.get($theme, supporting-text-font),
123 line-height: map.get($theme, supporting-text-line-height),
124 size: map.get($theme, supporting-text-size),
125 weight: map.get($theme, supporting-text-weight),
126 tracking: map.get($theme, supporting-text-tracking),
127 )
128 );
129 @include _supporting-text-color(map.get($theme, supporting-text-color));
130
131 .mdc-dialog__actions .mdc-button {
132 @include button-text-theme.theme-styles-internal(
133 (
134 focus-label-text-color: map.get($theme, action-focus-label-text-color),
135 focus-state-layer-color: map.get($theme, action-focus-state-layer-color),
136 focus-state-layer-opacity:
137 map.get($theme, action-focus-state-layer-opacity),
138 hover-label-text-color: map.get($theme, action-hover-text-color),
139 hover-state-layer-color: map.get($theme, action-hover-state-layer-color),
140 hover-state-layer-opacity:
141 map.get($theme, action-hover-state-layer-opacity),
142 label-text-color: map.get($theme, action-label-text-color),
143 label-text-font: map.get($theme, action-label-text-font),
144 label-text-size: map.get($theme, action-label-text-size),
145 label-text-tracking: map.get($theme, action-label-text-tracking),
146 label-text-weight: map.get($theme, action-label-text-weight),
147 pressed-label-text-color:
148 map.get($theme, action-pressed-label-text-color),
149 pressed-state-layer-color:
150 map.get($theme, action-pressed-state-layer-color),
151 pressed-state-layer-opacity:
152 map.get($theme, action-pressed-state-layer-opacity),
153 )
154 );
155 }
156}
157
158@mixin _container-color($color) {
159 .mdc-dialog__surface {
160 @include theme.property(background-color, $color);
161 }
162}
163
164@mixin _container-elevation($elevation-resolver, $elevation, $shadow-color) {
165 .mdc-dialog__surface {
166 @include elevation-theme.with-resolver(
167 $elevation-resolver,
168 $elevation: $elevation,
169 $shadow-color: $shadow-color
170 );
171 }
172}
173
174@mixin container-shape($radius) {
175 .mdc-dialog__surface {
176 @include shape.radius($radius);
177 }
178}
179
180@mixin _divider-color($color) {
181 &.mdc-dialog--scrollable .mdc-dialog__title,
182 &.mdc-dialog--scrollable .mdc-dialog__actions,
183 &.mdc-dialog--scrollable.mdc-dialog-scroll-divider-footer
184 .mdc-dialog__actions {
185 @include theme.property(border-color, $color);
186 }
187
188 &.mdc-dialog--scrollable .mdc-dialog__title {
189 @include theme.property(border-bottom-color, $color);
190 }
191}
192
193@mixin _divider-height($height) {
194 .mdc-dialog__actions {
195 @include theme.property(border-top-width, $height);
196 }
197
198 &.mdc-dialog--scrollable .mdc-dialog__title {
199 @include theme.property(border-bottom-width, $height);
200 }
201}
202
203@mixin _icon-size($size) {
204 .mdc-dialog__title-icon {
205 @include theme.property(height, $size);
206 @include theme.property(width, $size);
207 @include theme.property(font-size, $size);
208 }
209}
210
211@mixin _icon-color($color) {
212 .mdc-dialog__title-icon {
213 @include theme.property(color, $color);
214 }
215}
216
217@mixin subhead-typography($typography) {
218 .mdc-dialog__title {
219 @include theme.property(font-family, map.get($typography, font));
220 @include theme.property(line-height, map.get($typography, line-height));
221 @include theme.property(font-size, map.get($typography, size));
222 @include theme.property(font-weight, map.get($typography, weight));
223 @include theme.property(letter-spacing, map.get($typography, tracking));
224 }
225}
226
227@mixin _subhead-color($color) {
228 .mdc-dialog__title {
229 @include theme.property(color, $color);
230 }
231}
232
233@mixin _supporting-text-typography($typography) {
234 .mdc-dialog__content {
235 @include theme.property(font-family, map.get($typography, font));
236 @include theme.property(line-height, map.get($typography, line-height));
237 @include theme.property(font-size, map.get($typography, size));
238 @include theme.property(font-weight, map.get($typography, weight));
239 @include theme.property(letter-spacing, map.get($typography, tracking));
240 }
241}
242
243@mixin _supporting-text-color($color) {
244 .mdc-dialog__content {
245 @include theme.property(color, $color);
246 }
247}
248
249@function _resolve-elevation($theme, $elevation-resolver) {
250 @if map.get($theme, container-elevation) and
251 map.get($theme, container-shadow-color)
252 {
253 $resolved-value: meta.call(
254 $elevation-resolver,
255 $elevation: map.get($theme, container-elevation),
256 $shadow-color: map.get($theme, container-shadow-color)
257 );
258 $theme: map.set($theme, container-elevation, $resolved-value);
259 }
260
261 @return $theme;
262}