Skip to content

Commit 9af9c79

Browse files
committed
feat(focus indicators): Add config map to base focus indicators mixin and tweak some default styles.
1 parent 46babbd commit 9af9c79

File tree

4 files changed

+71
-43
lines changed

4 files changed

+71
-43
lines changed

src/dev-app/theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@import '../material/core/theming/all-theme';
2-
@import '../material/core/focus-indicator/focus-indicator';
2+
@import '../material/core/focus-indicators/focus-indicators';
33
@import '../material-experimental/column-resize/column-resize';
44
@import '../material-experimental/mdc-helpers/mdc-helpers';
55
@import '../material-experimental/mdc-theming/all-theme';

src/material-experimental/mdc-helpers/_mdc-helpers.scss

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,39 +217,55 @@ $mat-typography-level-mappings: (
217217
///
218218
/// @example
219219
/// .my-app {
220-
/// @include mat-mdc-strong-focus-indicators();
220+
/// @include mat-mdc-strong-focus-indicators($config);
221221
/// }
222-
@mixin mat-mdc-strong-focus-indicators() {
223-
// Base styles for the focus indicators.
222+
@mixin mat-mdc-strong-focus-indicators($config: ()) {
223+
// Default focus indicator config.
224+
$default-config: (
225+
border-style: solid,
226+
border-width: 3px,
227+
border-radius: 4px,
228+
);
229+
230+
// Merge default config with user config.
231+
$config: map-merge($default-config, $config);
232+
$border-style: map-get($config, border-style);
233+
$border-width: map-get($config, border-width);
234+
$border-radius: map-get($config, border-radius);
235+
236+
// Base styles for focus indicators.
224237
.mat-mdc-focus-indicator::before {
225238
@include mat-fill();
226-
227-
border-radius: $mat-focus-indicator-border-radius;
228-
border: $mat-focus-indicator-border-width $mat-focus-indicator-border-style transparent;
229239
box-sizing: border-box;
230240
pointer-events: none;
241+
border: $border-width $border-style transparent;
242+
border-radius: $border-radius;
231243
}
232244

233245
// By default, all focus indicators are flush with the bounding box of their
234246
// host element. For particular elements (listed below), default inset/offset
235247
// values are necessary to ensure that the focus indicator is sufficiently
236248
// contrastive and renders appropriately.
237249

238-
.mat-mdc-focus-indicator.mdc-button::before,
239-
.mat-mdc-focus-indicator.mdc-chip::before,
250+
.mat-mdc-focus-indicator.mat-mdc-unelevated-button::before,
251+
.mat-mdc-focus-indicator.mat-mdc-raised-button::before,
240252
.mat-mdc-focus-indicator.mdc-fab::before,
241-
.mat-mdc-focus-indicator.mdc-icon-button::before {
242-
margin: $mat-focus-indicator-border-width * -2;
253+
.mat-mdc-focus-indicator.mdc-chip::before {
254+
margin: -($border-width + 2px);
255+
}
256+
257+
.mat-mdc-focus-indicator.mat-mdc-outlined-button::before {
258+
margin: -($border-width + 3px);
243259
}
244260

245261
.mat-mdc-focus-indicator.mat-mdc-chip-remove::before,
246262
.mat-mdc-focus-indicator.mat-chip-row-focusable-text-content::before {
247-
margin: $mat-focus-indicator-border-width * -1;
263+
margin: -$border-width;
248264
}
249265

250266
.mat-mdc-focus-indicator.mat-mdc-tab::before,
251267
.mat-mdc-focus-indicator.mat-mdc-tab-link::before {
252-
margin: $mat-focus-indicator-border-width * 2;
268+
margin: 5px;
253269
}
254270

255271
// Render the focus indicator on focus. Defining a pseudo element's
@@ -269,24 +285,24 @@ $mat-typography-level-mappings: (
269285

270286
/// Mixin that sets the color of the focus indicators.
271287
///
272-
/// @param {color|map} $themeOrMap
288+
/// @param {color|map} $theme-or-color
273289
/// If theme, focus indicators are set to the primary color of the theme. If
274290
/// color, focus indicators are set to that color.
275291
///
276292
/// @example
277293
/// .demo-dark-theme {
278-
/// @include mat-mdc-strong-focus-indicators-theme($darkThemeMap);
294+
/// @include mat-mdc-strong-focus-indicators-theme($dark-theme-map);
279295
/// }
280296
///
281297
/// @example
282298
/// .demo-red-theme {
283-
/// @include mat-mdc-strong-focus-indicators-theme(#F00);
299+
/// @include mat-mdc-strong-focus-indicators-theme(#f00);
284300
/// }
285-
@mixin mat-mdc-strong-focus-indicators-theme($themeOrColor) {
301+
@mixin mat-mdc-strong-focus-indicators-theme($theme-or-color) {
286302
.mat-mdc-focus-indicator::before {
287303
border-color: if(
288-
type-of($themeOrColor) == 'map',
289-
mat-color(map_get($themeOrColor, primary)),
290-
$themeOrColor);
304+
type-of($theme-or-color) == 'map',
305+
mat-color(map_get($theme-or-color, primary)),
306+
$theme-or-color);
291307
}
292308
}

src/material/core/focus-indicators/_all-focus-indicators.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,60 @@
11
@import '../theming/theming';
22
@import '../style/layout-common';
33

4-
// Focus indicator styles.
5-
$mat-focus-indicator-border-radius: 4px;
6-
$mat-focus-indicator-border-width: 2px;
7-
$mat-focus-indicator-border-style: solid;
8-
94
/// Mixin that turns on strong focus indicators.
105
///
116
/// @example
127
/// .my-app {
13-
/// @include mat-strong-focus-indicators();
8+
/// @include mat-strong-focus-indicators($config);
149
/// }
15-
@mixin mat-strong-focus-indicators() {
10+
@mixin mat-strong-focus-indicators($config: ()) {
11+
// Default focus indicator config.
12+
$default-config: (
13+
border-style: solid,
14+
border-width: 3px,
15+
border-radius: 4px,
16+
);
17+
18+
// Merge default config with user config.
19+
$config: map-merge($default-config, $config);
20+
$border-style: map-get($config, border-style);
21+
$border-width: map-get($config, border-width);
22+
$border-radius: map-get($config, border-radius);
1623

17-
// Base styles for the focus indicators.
24+
// Base styles for focus indicators.
1825
.mat-focus-indicator::before {
1926
@include mat-fill();
20-
21-
border-radius: $mat-focus-indicator-border-radius;
22-
border: $mat-focus-indicator-border-width $mat-focus-indicator-border-style transparent;
2327
box-sizing: border-box;
2428
pointer-events: none;
29+
border: $border-width $border-style transparent;
30+
border-radius: $border-radius;
2531
}
2632

2733
// By default, all focus indicators are flush with the bounding box of their
2834
// host element. For particular elements (listed below), default inset/offset
2935
// values are necessary to ensure that the focus indicator is sufficiently
3036
// contrastive and renders appropriately.
3137

32-
.mat-focus-indicator.mat-button-base::before,
33-
.mat-focus-indicator.mat-card::before,
38+
.mat-focus-indicator.mat-flat-button::before,
39+
.mat-focus-indicator.mat-raised-button::before,
40+
.mat-focus-indicator.mat-fab::before,
41+
.mat-focus-indicator.mat-mini-fab::before,
3442
.mat-focus-indicator.mat-chip::before,
3543
.mat-focus-indicator.mat-sort-header-button::before {
36-
margin: $mat-focus-indicator-border-width * -2;
44+
margin: -($border-width + 2px);
45+
}
46+
47+
.mat-focus-indicator.mat-stroked-button::before {
48+
margin: -($border-width + 3px);
3749
}
3850

3951
.mat-focus-indicator.mat-calendar-body-cell::before {
40-
margin: $mat-focus-indicator-border-width * -1;
52+
margin: -$border-width;
4153
}
4254

4355
.mat-focus-indicator.mat-tab-link::before,
4456
.mat-focus-indicator.mat-tab-label::before {
45-
margin: $mat-focus-indicator-border-width * 2;
57+
margin: 5px;
4658
}
4759

4860
// Render the focus indicator on focus. Defining a pseudo element's
@@ -66,24 +78,24 @@ $mat-focus-indicator-border-style: solid;
6678

6779
/// Mixin that sets the color of the focus indicators.
6880
///
69-
/// @param {color|map} $themeOrMap
81+
/// @param {color|map} $theme-or-color
7082
/// If theme, focus indicators are set to the primary color of the theme. If
7183
/// color, focus indicators are set to that color.
7284
///
7385
/// @example
7486
/// .demo-dark-theme {
75-
/// @include mat-strong-focus-indicators-theme($darkThemeMap);
87+
/// @include mat-strong-focus-indicators-theme($dark-theme-map);
7688
/// }
7789
///
7890
/// @example
7991
/// .demo-red-theme {
80-
/// @include mat-strong-focus-indicators-theme(#F00);
92+
/// @include mat-strong-focus-indicators-theme(#f00);
8193
/// }
82-
@mixin mat-strong-focus-indicators-theme($themeOrColor) {
94+
@mixin mat-strong-focus-indicators-theme($theme-or-color) {
8395
.mat-focus-indicator::before {
8496
border-color: if(
85-
type-of($themeOrColor) == 'map',
86-
mat-color(map_get($themeOrColor, primary)),
87-
$themeOrColor);
97+
type-of($theme-or-color) == 'map',
98+
mat-color(map_get($theme-or-color, primary)),
99+
$theme-or-color);
88100
}
89101
}

0 commit comments

Comments
 (0)