-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification.html
143 lines (123 loc) · 3.35 KB
/
notification.html
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
<html>
<head>
<meta charset="UTF-8">
<title>Notifications Component</title>
<style>
body {
font-family: sans-serif;
}
hr {
margin: 50px 0;
}
/*#notification::shadow button svg {
fill: green;
}*/
:root {
--notification-text-color: blue;
--notification-close-button-color: peru;
--notification-close-button-size: 50px;
}
</style>
</head>
<body>
<h3>Shadow Dom</h3>
<button>Click me</button>
<hr>
<div id="notification">
<h3>New Message in #customer-support</h3>
<p>Have you guys thought about using Web Components yet?</p>
<button>Reply</button>
</div>
</body>
</html>
<script>
var notification = document.getElementById('notification');
var root = notification.createShadowRoot(); // Deprecated to be replaced with attachShadow();
// ::content deprecated to be replaced with ::slotted
root.innerHTML = `
<style>
:host(.is-active) {
border: 10px solid pink;
}
:host-context(.green-theme) {
background-color: green;
}
:host {
background-color: #3498db;
border-radius: 5px;
line-height: 1.4;
width: 420px;
}
button {
background: none;
border: none;
box-shadow: none;
cursor: pointer;
position: absolute;
right: 15px;
top: 10px;
width: 27px;
}
button span {
display: none;
}
button svg {
fill: var(--notification-close-button-color, #fff);
height: var(--notification-close-button-size, 27px);
width: var(--notification-button-size, 27px);
}
button:hover svg {
fill: rgba(0,0,0,0.7);
}
p {
color: var(--notification-text-color, #fff);
font-size: small;
margin-bottom: 0;
text-align: right;
}
.wrapper {
padding: 20px;
position: relative;
}
::content h3, ::content p {
color: #fff;
margin-top: 0;
padding-top: 0;
}
::content p:last-child {
margin-bottom: 0;
}
::content button {
background: none;
border: none;
border-right: 1px solid rgba(0,0,0,0.5);
border-top: 1px solid rgba(0,0,0,0.5);
border-top-right-radius: 5px;
bottom: 0;
box-shadow: none;
color: rgba(0,0,0,0.5);
cursor: pointer;
font-size: 0.8em;
left: 0;
padding: 10px 20px;
position: absolute;
}
</style>
<div class="wrapper">
<button>
<svg viewBox="0 0 36 30">
<polygon points="32.8,4.4 28.6,0.2 18,10.8 7.4,0.2 3.2,4.4 13.8,15 3.2,25.6 7.4,29.8 18,19.2 28.6,29.8 32.8,25.6 22.2,15 "/>
</svg>
<span>Close</span>
</button>
<content></content>
<p>1 minute ago</p>
</div>`;
// <content> deprecated to be replaced with <slot>
// DEMONSTRATION OF DEEP - Deprecated - use custom props instead
//
// (function() {
// var el = document.querySelector('#notification /deep/ p');
// el.style.color = 'red';
// }())
</script>