-
Notifications
You must be signed in to change notification settings - Fork 183
/
_utils.scss
266 lines (233 loc) · 6.36 KB
/
_utils.scss
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* Backpack - Skyscanner's Design System
*
* Copyright 2016 Skyscanner Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* stylelint-disable at-rule-disallowed-list */
@import 'tokens.scss';
////
/// @group utils
////
/// Standard focus indicator for elements.
///
/// @example scss
/// .selector {
/// @include bpk-focus-indicator();
/// }
@mixin bpk-focus-indicator {
outline: ($bpk-one-pixel-rem * 2) solid $bpk-text-link-day;
outline-offset: ($bpk-one-pixel-rem * 2);
}
/// Hide visually and from screen readers.
///
/// @example scss
/// .selector {
/// @include bpk-hidden();
/// }
@mixin bpk-hidden {
display: none !important; /* stylelint-disable-line declaration-no-important */
}
/// Hide only visually, but have it available for screen readers:
///
/// http://snook.ca/archives/html_and_css/hiding-content-for-accessibility
///
/// @example scss
/// .selector {
/// @include bpk-visually-hidden();
/// }
@mixin bpk-visually-hidden {
position: absolute;
width: 1px; /* stylelint-disable-line unit-disallowed-list */
height: 1px; /* stylelint-disable-line unit-disallowed-list */
margin: -1px; /* stylelint-disable-line unit-disallowed-list */
padding: 0;
border: 0;
white-space: nowrap;
overflow: hidden;
clip: rect(0 0 0 0);
}
/// Modifies the bpk-visually-hidden mixin to allow the element to be focusable when navigated to via the keyboard:
///
/// https://www.drupal.org/node/897638
///
/// @require {mixin} bpk-visually-hidden
///
/// @example scss
/// .selector {
/// @include bpk-visually-hidden();
/// @include bpk-visually-hidden--focusable();
/// }
@mixin bpk-visually-hidden--focusable {
&:active,
&:focus {
position: static;
width: auto;
height: auto;
margin: 0;
overflow: visible;
clip: auto;
}
}
/// Hide visually and from screen readers, but maintain layout.
///
/// @example scss
/// .selector {
/// @include bpk-invisible();
/// }
@mixin bpk-invisible {
visibility: hidden;
}
/// Clearfix: contain floats.
///
/// @example scss
/// .selector {
/// @include bpk-clearfix();
/// }
@mixin bpk-clearfix {
&::before,
&::after {
content: '';
display: table;
}
&::after {
clear: both;
}
}
/// Target RTL specific styles.
///
/// @content
///
/// @example scss
/// .selector {
/// @include bpk-rtl() {
/// /* RTL scss goes here */
/// }
/// }
@mixin bpk-rtl {
html[dir='rtl'] & {
@content;
}
}
/// :hover pseudo selector wrapper which prevents styles displaying on touch devices
///
/// @content
///
/// @example scss
/// .selector {
/// @include bpk-hover() {
/// /* Non-touch specific hover scss goes here */
/// }
/// }
@mixin bpk-hover {
.bpk-no-touch-support &:hover:not(:active):not(:disabled) {
@content;
}
// Duplicating the above rule with `:global(...)` pseudo selector around the
// global `.bpk-no-touch-support` class to provide support for CSS modules.
// - when processed through css-loader, the `:global(...)` pseudo selector will be dropped
// leaving a duplicate rule which in turn will be 'uglified' out - so no worries there
// - when processed through node-sass only, the `:global(...)` pseudo selector will be left
// intact and ignored by all browsers
// stylelint-disable-next-line selector-pseudo-class-no-unknown
:global(.bpk-no-touch-support) &:hover:not(:active):not(:disabled) {
@content;
}
}
/// Target locale specific styles.
///
/// @content
///
/// @example scss
/// .selector {
/// @include bpk-locale('ja-JP') {
/// /* ja-JP scss goes here */
/// }
/// }
@mixin bpk-locale($locale) {
html[lang='#{$locale}'] &,
html[lang='#{to_lower_case($locale)}'] & {
@content;
}
}
/// Create a Backpack themeable property with
/// fallback support for old browsers and when
/// the CSS variable is not defined.
///
/// @content
///
/// @example scss
/// .selector {
/// @include bpk-themeable-property(color, --bpk-link-text-color, $fallback-text-color);
/// }
@mixin bpk-themeable-property($property, $variableName, $fallback) {
#{$property}: $fallback;
#{$property}: var($variableName, $fallback);
}
/// Create a property that uses the Backpack primary color blue-500.
///
/// @content
///
/// @example scss
/// .selector {
/// @include bpk-apply-primary-color-to(color);
/// }
@mixin bpk-apply-primary-color-to($property) {
@include bpk-themeable-property(
$property,
--bpk-primary-color,
$bpk-color-sky-blue
);
}
/// Replace part of a string with another string.
///
/// @param {string} $string - The string inside which the replacement should take place.
/// @param {string} $search - The substring to be replaced.
/// @param {string} $replace [''] - The string to replace $search.
@function str-replace($string, $search, $replace: '') {
/* Disabling rule here as the recommendation method is for newer sass versions that we don't yet support */
/* stylelint-disable-next-line scss/no-global-function-names */
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace +
str-replace(
str-slice($string, $index + str-length($search)),
$search,
$replace
);
}
@return $string;
}
/// Increases the tappable area of the element to the
/// minimum required for touch devices.
///
/// @content
///
/// @example scss
/// .selector {
/// @include bpk-touch-area;
/// }
@mixin bpk-touch-tappable {
position: relative;
&::before {
position: absolute;
/* stylelint-disable-next-line function-calc-no-invalid */
top: calc((-#{bpk-spacing-xxl() + bpk-spacing-sm()} / 2) + 50%);
/* stylelint-disable-next-line function-calc-no-invalid */
left: calc((-#{bpk-spacing-xxl() + bpk-spacing-sm()} / 2) + 50%);
content: '';
width: bpk-spacing-xxl() + bpk-spacing-sm();
height: bpk-spacing-xxl() + bpk-spacing-sm();
}
}