-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_header.ex
275 lines (261 loc) · 6.73 KB
/
page_header.ex
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
267
268
269
270
271
272
273
274
275
defmodule PhoenixDuskmoon.PageHeader do
@moduledoc """
render Page Header
"""
use PhoenixDuskmoon, :html
@doc """
Generates a Page header.
## Example
<.dm_page_header>
<:menu to={~p"/storybook"}>
Storybook
</:menu>
<:user_profile>
(^_^)
</:user_profile>
</.dm_page_header>
"""
@doc type: :component
attr(:id, :string,
default: "wc-page-header-header",
doc: """
html attribute id
"""
)
attr(:nav_id, :string,
default: "wc-page-header-nav",
doc: """
nav html attribute id
"""
)
attr(:class, :any,
default: "",
doc: """
html attribute class
"""
)
attr(:nav_class, :any,
default: "",
doc: """
nav html attribute class
"""
)
slot(:menu,
required: false,
doc: """
Appbar menus
"""
) do
attr(:class, :string)
attr(:to, :string)
end
slot(:user_profile,
required: false,
doc: """
Appbar right side user_profile.
"""
) do
attr(:class, :string)
end
def dm_page_header(assigns) do
~H"""
<nav
id={@nav_id}
class={[
"w-full h-12",
"flex items-center flex-none",
"transition-all",
"fixed hidden",
@nav_class
]}
>
<div
class={[
"container mx-auto",
"hidden lg:flex flex-row justify-between items-center"
]}
>
<div class="flex flex-row gap-4">
<a
:for={menu <- @menu}
class={[
"py-2 px-6",
"text-lg font-semibold leading-6 text-center",
"hover:opacity-50",
Map.get(menu, :class, "")
]}
href={Map.get(menu, :to, false)}
>
<%= render_slot(menu) %>
</a>
</div>
<div
:for={user_profile <- @user_profile}
class={["flex", Map.get(user_profile, :class, "")]}
>
<%= render_slot(user_profile) %>
</div>
</div>
<div
class={[
"container px-8 h-full relative",
"flex lg:hidden flex-col justify-center items-center"
]}
>
<label for="mobile-menu">
<PhoenixDuskmoon.Icons.dm_mdi name="menu" class="w-8 h-8" />
</label>
<input class="hidden peer" id="mobile-menu" type="checkbox" />
<div
class={[
"hidden peer-checked:flex flex-col items-center",
"absolute top-12 left-0 right-0",
@nav_class
]}
>
<a
:for={menu <- @menu}
class={[
"py-2 px-12 w-full",
"text-lg font-semibold leading-6 text-center",
"hover:opacity-50",
Map.get(menu, :class, "")
]}
href={Map.get(menu, :to, false)}
>
<%= render_slot(menu) %>
</a>
<hr />
<div
:for={user_profile <- @user_profile}
class={[
"py-2 px-12 w-full",
"text-lg font-semibold leading-6",
"hover:opacity-50 flex justify-center",
Map.get(user_profile, :class, "")
]}
>
<%= render_slot(user_profile) %>
</div>
</div>
</div>
</nav>
<header
id={@id}
class={[
"w-full min-h-fit",
"flex flex-col",
@class
]}
>
<nav class={["w-full h-12", "flex items-center flex-none"]}>
<div
class={[
"container mx-auto",
"hidden lg:flex flex-row justify-between items-center"
]}
>
<div class={["flex flex-row gap-4"]}>
<a
:for={menu <- @menu}
class={[
"py-2 px-6",
"text-lg font-semibold leading-6 text-center",
"hover:opacity-50",
Map.get(menu, :class, "")
]}
href={Map.get(menu, :to, false)}
>
<%= render_slot(menu) %>
</a>
</div>
<div
:for={user_profile <- @user_profile}
class={["flex", Map.get(user_profile, :class, "")]}
>
<%= render_slot(user_profile) %>
</div>
</div>
<div
class={[
"container px-8 relative",
"flex lg:hidden flex-row justify-between items-center"
]}
>
<label for="dm-mobile-menu-control">
<PhoenixDuskmoon.Icons.dm_mdi name="menu" class="w-8 h-8" />
</label>
<input class="hidden peer" id="dm-mobile-menu-control" type="checkbox" />
<div
class={[
"hidden peer-checked:flex flex-col items-start",
"absolute top-12 left-0 right-0",
@class
]}
>
<a
:for={menu <- @menu}
class={[
"py-2 px-12 w-full",
"text-lg font-semibold leading-6",
"hover:opacity-50",
Map.get(menu, :class, "")
]}
href={Map.get(menu, :to, false)}
>
<%= render_slot(menu) %>
</a>
<div
:for={user_profile <- @user_profile}
class={[
"py-2 px-12 w-full",
"text-lg font-semibold leading-6",
"hover:opacity-50",
Map.get(user_profile, :class, "")
]}
>
<%= render_slot(user_profile) %>
</div>
</div>
</div>
</nav>
<div class="flex-1 flex flex-col justify-center items-center">
<%= render_slot(@inner_block) %>
</div>
</header>
<script type="module">
(function() {
function respondToVisibility(element, callback) {
var list = [];
for(let i = 0; i <= 10; i++) {
list.push(i / 10);
}
var options = {
root: null,
rootMargin: "0px",
threshold: list,
};
var observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
callback(entry.intersectionRatio);
});
}, options);
observer.observe(element);
}
var nid = '<%= @nav_id %>';
var hid = '<%= @id %>';
var nel = document.getElementById(nid);
var hel = document.getElementById(hid);
respondToVisibility(hel, function(intersectionRatio) {
if (intersectionRatio <= 0.5) {
nel.classList.remove('hidden');
nel.style.opacity = 1 - intersectionRatio;
} else {
nel.classList.add('hidden');
}
});
})();
</script>
"""
end
end