-
Notifications
You must be signed in to change notification settings - Fork 31
/
popover-card.scss
124 lines (99 loc) · 3.42 KB
/
popover-card.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
@import "../style/base";
@import "popover-card-vars";
:host {
--card-elevation: #{$popover-card-elevation};
display: flex;
flex-direction: var(--_flex-direction, column);
}
#content {
transform: translate(calc(#{$popover-card-arrow-width} * var(--_content-translate-x-multiplier, 0)), calc(#{$popover-card-arrow-width} * var(--_content-translate-y-multiplier, 0)));
overflow: hidden;
}
#arrow {
transform: rotate(var(--_arrow-rotation, 0deg)) translate(calc(50% * var(--_arrow-translate-x-multiplier, 0)), calc(50% * var(--_arrow-translate-y-multiplier, 0)));
left: var(--_arrow-offset-x, unset);
top: var(--_arrow-offset-y, unset);
justify-self: var(--_justify-content, flex-start);
align-self: var(--_align-items, flex-start);
pointer-events: none;
position: relative;
width: $popover-card-arrow-width;
height: $popover-card-arrow-height;
fill: $popover-card-arrow-fill;
z-index: 1;
display: none;
}
// Only display the arrow if host-context is supported
:host-context([data-transform-origin-x][data-transform-origin-y]) #arrow {
display: block;
}
// Position the arrow inside the arrow container according to the transform origin.
:host-context([data-transform-origin-x="left"]) {
--_align-items: flex-start;
}
:host-context([data-transform-origin-x="center"]) {
--_align-items: center;
}
:host-context([data-transform-origin-x="right"]) {
--_align-items: flex-end;
}
:host-context([data-transform-origin-y="top"]) {
--_justify-content: flex-start;
}
:host-context([data-transform-origin-y="center"]) {
--_justify-content: center;
}
:host-context([data-transform-origin-y="bottom"]) {
--_flex-direction: column-reverse;
}
// It doesn't make sense to show an arrow when the transform origin is in the center
:host-context([data-transform-origin-x="center"][data-transform-origin-y="center"]) {
#arrow {
display: none;
}
}
// #####################################
// I LEARNED TO WRITE THE BELOW CODE IN A COURSE AT HOGWARTS. YES. MAGIC IS REAL.
// #####################################
// Top rules
:host-context([data-transform-origin-x="left"][data-transform-origin-y="top"]) {
--_content-translate-x-multiplier: -2;
--_arrow-translate-x-multiplier: -1;
}
:host-context([data-transform-origin-x="right"][data-transform-origin-y="top"]) {
--_content-translate-x-multiplier: 2;
--_arrow-translate-x-multiplier: 1;
}
// Bottom rules
:host-context([data-transform-origin-y="bottom"]) {
--_arrow-rotation: 180deg;
}
:host-context([data-transform-origin-x="left"][data-transform-origin-y="bottom"]) {
--_content-translate-x-multiplier: -2;
--_arrow-translate-x-multiplier: 1;
}
:host-context([data-transform-origin-x="right"][data-transform-origin-y="bottom"]) {
--_content-translate-x-multiplier: 2;
--_arrow-translate-x-multiplier: -1;
}
:host-context([data-transform-origin-y="center"]) {
--_arrow-translate-x-multiplier: 0;
}
// Center rules
:host-context([data-transform-origin-y="center"]) {
--_align-items: center;
}
:host-context([data-transform-origin-x="left"][data-transform-origin-y="center"]) {
--_flex-direction: row;
--_arrow-rotation: -90deg;
#content {
transform: translateX(calc(((#{$popover-card-arrow-width} - #{$popover-card-arrow-height}) / 2) * -1));
}
}
:host-context([data-transform-origin-x="right"][data-transform-origin-y="center"]) {
--_flex-direction: row-reverse;
--_arrow-rotation: 90deg;
#content {
transform: translateX(calc((#{$popover-card-arrow-width} - #{$popover-card-arrow-height}) / 2));
}
}