UNPKG

3.7 kBSCSSView Raw
1// Copyright 2020 Google Inc.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21@use '@material/feature-targeting/feature-targeting';
22///
23/// Emits necessary layout styles to set a transparent border around an element
24/// without interfering with the rest of its component layout. The border is
25/// only visible in high-contrast mode. The target element should be a child of
26/// a relatively positioned top-level element (i.e. a ::before pseudo-element).
27///
28/// @param {number} $border-width - The width of the transparent border.
29/// @param {string} $border-style - The style of the transparent border.
30///
31@mixin transparent-border(
32 $border-width: 1px,
33 $border-style: solid,
34 $query: feature-targeting.all()
35) {
36 $feat-structure: feature-targeting.create-target($query, structure);
37
38 @include feature-targeting.targets($feat-structure) {
39 position: absolute;
40 box-sizing: border-box;
41 width: 100%;
42 height: 100%;
43 top: 0;
44 left: 0;
45 border: $border-width $border-style transparent;
46 border-radius: inherit;
47 content: '';
48 pointer-events: none;
49 }
50
51 // Used to satisfy Firefox v94 which does not render transparent borders in HCM (b/206440838).
52 @include forced-colors-mode($exclude-ie11: true) {
53 @include feature-targeting.targets($feat-structure) {
54 border-color: CanvasText;
55 }
56 }
57}
58
59///
60/// Visually hides text content for accessibility. This text should only be
61/// visible to screen reader users.
62/// See https://a11yproject.com/posts/how-to-hide-content/
63///
64@mixin visually-hidden($query: feature-targeting.all()) {
65 $feat-structure: feature-targeting.create-target($query, structure);
66
67 @include feature-targeting.targets($feat-structure) {
68 clip: rect(1px, 1px, 1px, 1px);
69 height: 1px;
70 overflow: hidden;
71 position: absolute;
72 white-space: nowrap; /* added line */
73 width: 1px;
74 }
75}
76
77/// Selects for IE11 support.
78///
79/// @content styles to emit for IE11 support
80@mixin ie11-support {
81 @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
82 @content;
83 }
84}
85
86/// Selects for `forced-colors` high contrast mode.
87///
88/// While in `forced-colors` mode, only system colors should be used.
89///
90/// @link https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#system_colors
91/// @link https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors
92/// @content styles to emit in `forced-colors` mode
93@mixin forced-colors-mode($exclude-ie11: false) {
94 @if $exclude-ie11 {
95 @media screen and (forced-colors: active) {
96 @content;
97 }
98 } @else {
99 @media screen and (forced-colors: active), (-ms-high-contrast: active) {
100 @content;
101 }
102 }
103}