-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path_f-context-selector.scss
78 lines (73 loc) · 1.99 KB
/
_f-context-selector.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
@use "sass:meta";
@use "../01-abstract/variables";
/**
* Context selector - Make a context selector (editor / style)
*
* @author Milan Ricoul
*
* @param $default
* @param $editor
* @param $selector
*
* Examples :
* #{ context-selector('#main__content', '#editor', '.block') } {
* ... your css
* }
*
* return for style.scss :
* #main__content .block {
* ... your css
* }
*
* return for editor.scss :
* #editor .block {
* ... your css
* }
*
* $selectors: ".blocks-gallery-image,", ".blocks-gallery-item";
* #{ context-selector('.wp-block-gallery', '.blocks-gallery-grid', selectors) } {
* ... your css
* }
*
* return for style.scss :
* .wp-block-gallery .blocks-gallery-image,
* .wp-block-gallery .blocks-gallery-item {
* ... your css
* }
*
* return for editor.scss :
* .blocks-gallery-grid .blocks-gallery-image,
* .blocks-gallery-grid .blocks-gallery-item {
* ... your css
* }
*
* It can be used to define a variable :
* $parent: context-selector('#main__content', '#editor')
* #{(dollar)parent} > .block {
* ... your css
* }
*
* the variable $entry-file-name is defined in style.scss and editor.scss
*
*/
@function context-selector($default: null, $editor: null, $selector: null) {
$full-selector: "";
$parent: "";
@if (variables.$entry-file-name == "editor" and $editor) {
$parent: $editor;
} @else if (variables.$entry-file-name == "style" and $default) {
$parent: $default;
} @else {
@return $selector;
}
@if (meta.type-of($selector) == "string") {
$full-selector: $parent + " " + $selector;
} @else if (meta.type-of($selector) == "list") {
@each $s in $selector {
$full-selector: $full-selector + $parent + " " + $s;
}
} @else {
$full-selector: $parent;
}
@return $full-selector;
}