-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path_m-hover.scss
67 lines (64 loc) · 1.56 KB
/
_m-hover.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
@use "sass:meta";
@use "sass:list";
/**
* Hover
*
* Add active, focus and hover pseudo selectors to element
* With $onlyNoTouch set to true, the hover style will only work when the user is using a tool device like a mouse or a trackpad.
* https://defensivecss.dev/tip/hover-media/
* https://developer.mozilla.org/fr/docs/Web/CSS/@media/hover
*
* @author Cédric Andrietti
*
* @param $onlyNoTouch
* @param $additionalSelectors
*
* Examples :
*
* .my-element {
* @include hover {
* ... your css
* }
* }
*
* .my-element {
* @include hover(false, "&:focus-within") {
* ... your css
* }
* }
*
* .my-element {
* @include hover(true, "&:focus-within") {
* ... your css
* }
* }
*
* .my-element {
* @include hover(true) {
* ... your css
* }
* }
*
*/
@mixin hover($onlyNoTouch: null, $additionalSelectors: null) {
$selectors: "&:hover", "&:active", "&:focus";
@if ($additionalSelectors) {
@if (meta.type-of($additionalSelectors) == "string") {
$selectors: $selectors "," $additionalSelectors;
}
@else if (meta.type-of($additionalSelectors) == "list") {
$selectors: list.join($selectors, $additionalSelectors, comma);
}
}
@if $onlyNoTouch {
@media (hover: hover) {
#{$selectors} {
@content;
}
}
} @else {
#{$selectors} {
@content;
}
}
}