-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasefn__Topbar.res
More file actions
80 lines (73 loc) · 1.9 KB
/
Basefn__Topbar.res
File metadata and controls
80 lines (73 loc) · 1.9 KB
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
%%raw(`import './Basefn__Topbar.css'`)
open Xote
type size = Sm | Md | Lg
type navItem = {
label: string,
active: bool,
onClick: unit => unit,
}
let sizeToString = (size: size) => {
switch size {
| Sm => "sm"
| Md => "md"
| Lg => "lg"
}
}
@jsx.component
let make = (
~logo: option<Node.node>=?,
~navItems: option<array<navItem>>=?,
~leftContent: option<Node.node>=?,
~centerContent: option<Node.node>=?,
~rightContent: option<Node.node>=?,
~onMenuClick: option<unit => unit>=?,
~size: size=Md,
) => {
let class = "basefn-topbar basefn-topbar--" ++ sizeToString(size)
<header class>
<div class="basefn-topbar__left">
{switch onMenuClick {
| Some(handler) =>
<button class="basefn-topbar__menu-button" onClick={_ => handler()}>
{Node.text("\u2630")}
</button>
| None => <> </>
}}
{switch logo {
| Some(logoContent) => <div class="basefn-topbar__logo"> {logoContent} </div>
| None => <> </>
}}
{switch leftContent {
| Some(content) => content
| None => <> </>
}}
</div>
<div class="basefn-topbar__center">
{switch navItems {
| Some(items) =>
<nav class="basefn-topbar__nav">
{items
->Array.mapWithIndex((item, index) => {
let className =
"basefn-topbar__nav-item" ++ (item.active ? " basefn-topbar__nav-item--active" : "")
<button key={Int.toString(index)} class={className} onClick={_ => item.onClick()}>
{Node.text(item.label)}
</button>
})
->Node.fragment}
</nav>
| None => <> </>
}}
{switch centerContent {
| Some(content) => content
| None => <> </>
}}
</div>
<div class="basefn-topbar__right">
{switch rightContent {
| Some(content) => content
| None => <> </>
}}
</div>
</header>
}