6
6
7
7
@use ' @material/theme/keys' ;
8
8
@use ' @material/theme/validate' ;
9
+ @use ' @material/shape/shape' ;
9
10
@use ' ./focus-ring-shared-theme' ;
10
11
11
12
$_custom-property-prefix : ' focus-ring-outward' ;
@@ -15,6 +16,9 @@ $default-outward-theme: map.merge(
15
16
focus-ring-shared-theme .$default-shared-theme ,
16
17
(
17
18
focus-ring-shared-theme .$ring-offset-key : 2px ,
19
+ // Target shape can be provided as a single value, or as a list with
20
+ // 1-4 values where each value would correspond to border radius of one
21
+ // or more corners.
18
22
focus-ring-shared-theme .$target-shape-key : 0px ,
19
23
)
20
24
);
@@ -26,22 +30,42 @@ $default-outward-theme: map.merge(
26
30
/// @param {Map} $theme - A map with one or more of the keys of $default-outward-theme.
27
31
@mixin theme ($theme ) {
28
32
$theme : validate .theme ($default-outward-theme , $theme );
33
+ $theme : _expand-target-shape-value ($theme );
29
34
@include keys .declare-custom-properties ($theme , $_custom-property-prefix );
30
35
}
31
36
32
37
@mixin theme-styles ($theme : $default-outward-theme ) {
33
38
$theme : validate .theme-styles ($default-outward-theme , $theme );
39
+ $theme : _expand-target-shape-value ($theme );
34
40
$theme : keys .create-theme-vars ($theme , $_custom-property-prefix );
35
41
36
42
$ring-color : map .get ($theme , focus-ring-shared-theme .$ring-color-key );
37
43
$ring-offset : map .get ($theme , focus-ring-shared-theme .$ring-offset-key );
38
44
$track-width : map .get ($theme , focus-ring-shared-theme .$track-width-key );
39
- $target-shape : map .get ($theme , focus-ring-shared-theme .$target-shape-key );
45
+ $target-shape-start-start : map .get (
46
+ $theme ,
47
+ ' #{focus-ring-shared-theme .$target-shape-key } -start-start'
48
+ );
49
+ $target-shape-start-end : map .get (
50
+ $theme ,
51
+ ' #{focus-ring-shared-theme .$target-shape-key } -start-end'
52
+ );
53
+ $target-shape-end-end : map .get (
54
+ $theme ,
55
+ ' #{focus-ring-shared-theme .$target-shape-key } -end-end'
56
+ );
57
+ $target-shape-end-start : map .get (
58
+ $theme ,
59
+ ' #{focus-ring-shared-theme .$target-shape-key } -end-start'
60
+ );
40
61
41
62
/// Mold the focus ring to the target shape.
42
63
/// See the diagram for insights into why the border-radius calc is needed:
43
64
/// http://screen/9J9CzpCxJxxDHCb.png
44
- border-radius : calc ($target-shape + $ring-offset );
65
+ border-start-start-radius : calc ($target-shape-start-start + $ring-offset );
66
+ border-start-end-radius : calc ($target-shape-start-end + $ring-offset );
67
+ border-end-end-radius : calc ($target-shape-end-end + $ring-offset );
68
+ border-end-start-radius : calc ($target-shape-end-start + $ring-offset );
45
69
inset : calc (-1 * $ring-offset );
46
70
box-shadow : 0 0 0 $track-width $ring-color ;
47
71
// HCM ignores box-shadow, so a transparent outline is added to ensure
@@ -76,3 +100,23 @@ $default-outward-theme: map.merge(
76
100
}
77
101
}
78
102
}
103
+
104
+ /// Replaces target shape value or list provided in theme with four key-value
105
+ /// pairs corresponding to four corners' border radiuses.
106
+ ///
107
+ /// @example :
108
+ /// _expand-target-shape-value(('target-shape': 4px)) =>
109
+ /// (
110
+ /// 'target-shape-start-start': 4px,
111
+ /// 'target-shape-start-end': 4px,
112
+ /// 'target-shape-end-end': 4px,
113
+ /// 'target-shape-end-start': 4px
114
+ /// )
115
+ ///
116
+ @function _expand-target-shape-value ($theme ) {
117
+ @return shape .resolve-theme (
118
+ $theme ,
119
+ meta .get-function (' resolver' , $module : ' shape' ),
120
+ focus-ring-shared-theme .$target-shape-key
121
+ );
122
+ }
0 commit comments