-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.fs
45 lines (38 loc) · 1.12 KB
/
App.fs
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
module Lit.TodoMVC.App
open Lit
[<RequireQualifiedAccess>]
type Tab =
| Todos
| Virtualizer
[<LitElement("my-app")>]
let MyApp() =
let _ = LitElement.init(fun cfg ->
cfg.useShadowDom <- false
)
let activeTab, setActiveTab = Hook.useState(Tab.Todos)
let renderTab tab text =
html $"""<li class={if tab = activeTab then "is-active" else ""}>
<a @click={Ev(fun ev ->
ev.preventDefault()
setActiveTab tab
)}>
{text}
</a>
</li>"""
let content =
match activeTab with
| Tab.Todos ->
Lit.ofImport(Todos.register, fun _ ->
html $"""<todo-app local-storage="todo-app"></todo-app>""")
| Tab.Virtualizer ->
Lit.ofImport(Virtualizer.register, fun _ ->
html $"<contact-list></contact-list>")
html $"""
<div class="tabs" style="margin-bottom: 0.5rem;">
<ul>
{renderTab Tab.Todos "Todos"}
{renderTab Tab.Virtualizer "Virtual Scroll"}
</ul>
</div>
{content}
"""