basefn 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -0
- package/package.json +82 -0
- package/rescript.json +32 -0
- package/src/Basefn.css +14 -0
- package/src/Basefn.res +105 -0
- package/src/Basefn.res.mjs +114 -0
- package/src/Basefn__Dom.res +9 -0
- package/src/Basefn__Dom.res.mjs +24 -0
- package/src/Basefn__Utils.res +15 -0
- package/src/Basefn__Utils.res.mjs +32 -0
- package/src/Demo.res +1417 -0
- package/src/Demo.res.mjs +2328 -0
- package/src/Eita.res.mjs +105 -0
- package/src/Eita__Accordion.res.mjs +77 -0
- package/src/Eita__Alert.res.mjs +81 -0
- package/src/Eita__AppLayout.res.mjs +100 -0
- package/src/Eita__Avatar.res.mjs +40 -0
- package/src/Eita__Badge.res.mjs +65 -0
- package/src/Eita__Breadcrumb.res.mjs +53 -0
- package/src/Eita__Button.res.mjs +47 -0
- package/src/Eita__Card.res.mjs +60 -0
- package/src/Eita__Checkbox.res.mjs +36 -0
- package/src/Eita__Dom.res.mjs +16 -0
- package/src/Eita__Drawer.res.mjs +112 -0
- package/src/Eita__Dropdown.res.mjs +96 -0
- package/src/Eita__Grid.res.mjs +24 -0
- package/src/Eita__Input.res.mjs +54 -0
- package/src/Eita__Kbd.res.mjs +42 -0
- package/src/Eita__Label.res.mjs +24 -0
- package/src/Eita__Modal.res.mjs +93 -0
- package/src/Eita__Progress.res.mjs +101 -0
- package/src/Eita__Radio.res.mjs +38 -0
- package/src/Eita__Select.res.mjs +40 -0
- package/src/Eita__Separator.res.mjs +70 -0
- package/src/Eita__Sidebar.res.mjs +103 -0
- package/src/Eita__Slider.res.mjs +89 -0
- package/src/Eita__Spinner.res.mjs +69 -0
- package/src/Eita__Stepper.res.mjs +114 -0
- package/src/Eita__Switch.res.mjs +84 -0
- package/src/Eita__Tabs.res.mjs +57 -0
- package/src/Eita__Textarea.res.mjs +39 -0
- package/src/Eita__Timeline.res.mjs +86 -0
- package/src/Eita__Toast.res.mjs +112 -0
- package/src/Eita__Tooltip.res.mjs +60 -0
- package/src/Eita__Topbar.res.mjs +96 -0
- package/src/Eita__Typography.res.mjs +183 -0
- package/src/Eita__Utils.res.mjs +32 -0
- package/src/Example.res +111 -0
- package/src/Example.res.mjs +176 -0
- package/src/components/Basefn__Accordion.css +70 -0
- package/src/components/Basefn__Accordion.res +79 -0
- package/src/components/Basefn__Accordion.res.mjs +77 -0
- package/src/components/Basefn__Alert.css +79 -0
- package/src/components/Basefn__Alert.res +68 -0
- package/src/components/Basefn__Alert.res.mjs +78 -0
- package/src/components/Basefn__AppLayout.css +100 -0
- package/src/components/Basefn__AppLayout.res +74 -0
- package/src/components/Basefn__AppLayout.res.mjs +100 -0
- package/src/components/Basefn__Avatar.css +25 -0
- package/src/components/Basefn__Avatar.res +23 -0
- package/src/components/Basefn__Avatar.res.mjs +40 -0
- package/src/components/Basefn__Badge.css +71 -0
- package/src/components/Basefn__Badge.res +43 -0
- package/src/components/Basefn__Badge.res.mjs +65 -0
- package/src/components/Basefn__Breadcrumb.css +36 -0
- package/src/components/Basefn__Breadcrumb.res +45 -0
- package/src/components/Basefn__Breadcrumb.res.mjs +53 -0
- package/src/components/Basefn__Button.css +83 -0
- package/src/components/Basefn__Button.res +32 -0
- package/src/components/Basefn__Button.res.mjs +54 -0
- package/src/components/Basefn__Card.css +50 -0
- package/src/components/Basefn__Card.res +45 -0
- package/src/components/Basefn__Card.res.mjs +60 -0
- package/src/components/Basefn__Checkbox.css +72 -0
- package/src/components/Basefn__Checkbox.res +25 -0
- package/src/components/Basefn__Checkbox.res.mjs +36 -0
- package/src/components/Basefn__Drawer.css +168 -0
- package/src/components/Basefn__Drawer.res +86 -0
- package/src/components/Basefn__Drawer.res.mjs +112 -0
- package/src/components/Basefn__Dropdown.css +76 -0
- package/src/components/Basefn__Dropdown.res +85 -0
- package/src/components/Basefn__Dropdown.res.mjs +96 -0
- package/src/components/Basefn__Grid.css +11 -0
- package/src/components/Basefn__Grid.res +296 -0
- package/src/components/Basefn__Grid.res.mjs +263 -0
- package/src/components/Basefn__Icon.css +12 -0
- package/src/components/Basefn__Icon.res +196 -0
- package/src/components/Basefn__Icon.res.mjs +183 -0
- package/src/components/Basefn__Input.css +44 -0
- package/src/components/Basefn__Input.res +48 -0
- package/src/components/Basefn__Input.res.mjs +63 -0
- package/src/components/Basefn__Kbd.css +65 -0
- package/src/components/Basefn__Kbd.res +27 -0
- package/src/components/Basefn__Kbd.res.mjs +42 -0
- package/src/components/Basefn__Label.css +22 -0
- package/src/components/Basefn__Label.res +18 -0
- package/src/components/Basefn__Label.res.mjs +24 -0
- package/src/components/Basefn__Modal.css +100 -0
- package/src/components/Basefn__Modal.res +74 -0
- package/src/components/Basefn__Modal.res.mjs +93 -0
- package/src/components/Basefn__Progress.css +69 -0
- package/src/components/Basefn__Progress.res +88 -0
- package/src/components/Basefn__Progress.res.mjs +101 -0
- package/src/components/Basefn__Radio.css +72 -0
- package/src/components/Basefn__Radio.res +35 -0
- package/src/components/Basefn__Radio.res.mjs +38 -0
- package/src/components/Basefn__Select.css +44 -0
- package/src/components/Basefn__Select.res +33 -0
- package/src/components/Basefn__Select.res.mjs +40 -0
- package/src/components/Basefn__Separator.css +85 -0
- package/src/components/Basefn__Separator.res +45 -0
- package/src/components/Basefn__Separator.res.mjs +70 -0
- package/src/components/Basefn__Sidebar.css +141 -0
- package/src/components/Basefn__Sidebar.res +95 -0
- package/src/components/Basefn__Sidebar.res.mjs +107 -0
- package/src/components/Basefn__Slider.css +97 -0
- package/src/components/Basefn__Slider.res +68 -0
- package/src/components/Basefn__Slider.res.mjs +89 -0
- package/src/components/Basefn__Spinner.css +63 -0
- package/src/components/Basefn__Spinner.res +44 -0
- package/src/components/Basefn__Spinner.res.mjs +69 -0
- package/src/components/Basefn__Stepper.css +141 -0
- package/src/components/Basefn__Stepper.res +86 -0
- package/src/components/Basefn__Stepper.res.mjs +114 -0
- package/src/components/Basefn__Switch.css +80 -0
- package/src/components/Basefn__Switch.res +62 -0
- package/src/components/Basefn__Switch.res.mjs +84 -0
- package/src/components/Basefn__Tabs.css +54 -0
- package/src/components/Basefn__Tabs.res +73 -0
- package/src/components/Basefn__Tabs.res.mjs +57 -0
- package/src/components/Basefn__Textarea.css +41 -0
- package/src/components/Basefn__Textarea.res +28 -0
- package/src/components/Basefn__Textarea.res.mjs +41 -0
- package/src/components/Basefn__ThemeToggle.css +5 -0
- package/src/components/Basefn__ThemeToggle.res +29 -0
- package/src/components/Basefn__ThemeToggle.res.mjs +49 -0
- package/src/components/Basefn__Timeline.css +144 -0
- package/src/components/Basefn__Timeline.res +70 -0
- package/src/components/Basefn__Timeline.res.mjs +86 -0
- package/src/components/Basefn__Toast.css +100 -0
- package/src/components/Basefn__Toast.res +92 -0
- package/src/components/Basefn__Toast.res.mjs +112 -0
- package/src/components/Basefn__Tooltip.css +84 -0
- package/src/components/Basefn__Tooltip.res +42 -0
- package/src/components/Basefn__Tooltip.res.mjs +60 -0
- package/src/components/Basefn__Topbar.css +130 -0
- package/src/components/Basefn__Topbar.res +92 -0
- package/src/components/Basefn__Topbar.res.mjs +91 -0
- package/src/components/Basefn__Typography.css +120 -0
- package/src/components/Basefn__Typography.res +96 -0
- package/src/components/Basefn__Typography.res.mjs +175 -0
- package/src/styles/Basefn__Theme.res +63 -0
- package/src/styles/Basefn__Theme.res.mjs +65 -0
- package/src/styles/variables.css +199 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
%%raw(`import './Basefn__Drawer.css'`)
|
|
2
|
+
|
|
3
|
+
open Xote
|
|
4
|
+
|
|
5
|
+
type position = Left | Right | Top | Bottom
|
|
6
|
+
|
|
7
|
+
type size = Sm | Md | Lg
|
|
8
|
+
|
|
9
|
+
let positionToString = (position: position) => {
|
|
10
|
+
switch position {
|
|
11
|
+
| Left => "left"
|
|
12
|
+
| Right => "right"
|
|
13
|
+
| Top => "top"
|
|
14
|
+
| Bottom => "bottom"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let sizeToString = (size: size) => {
|
|
19
|
+
switch size {
|
|
20
|
+
| Sm => "sm"
|
|
21
|
+
| Md => "md"
|
|
22
|
+
| Lg => "lg"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@jsx.component
|
|
27
|
+
let make = (
|
|
28
|
+
~isOpen: Signal.t<bool>,
|
|
29
|
+
~onClose: unit => unit,
|
|
30
|
+
~position: position=Right,
|
|
31
|
+
~size: size=Md,
|
|
32
|
+
~title: option<string>=?,
|
|
33
|
+
~showCloseButton: bool=true,
|
|
34
|
+
~closeOnBackdrop: bool=true,
|
|
35
|
+
~children: Component.node,
|
|
36
|
+
~footer: option<Component.node>=?,
|
|
37
|
+
) => {
|
|
38
|
+
let handleBackdropClick = evt => {
|
|
39
|
+
if closeOnBackdrop {
|
|
40
|
+
let target = Obj.magic(evt)["target"]
|
|
41
|
+
let currentTarget = Obj.magic(evt)["currentTarget"]
|
|
42
|
+
if target === currentTarget {
|
|
43
|
+
onClose()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let getDrawerClass = () => {
|
|
49
|
+
let positionClass = "basefn-drawer--" ++ positionToString(position)
|
|
50
|
+
let sizeClass = "basefn-drawer--" ++ sizeToString(size)
|
|
51
|
+
"basefn-drawer " ++ positionClass ++ " " ++ sizeClass
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let content = Computed.make(() => {
|
|
55
|
+
if Signal.get(isOpen) {
|
|
56
|
+
[
|
|
57
|
+
<>
|
|
58
|
+
<div class="basefn-drawer-backdrop" onClick={handleBackdropClick} />
|
|
59
|
+
<div class={getDrawerClass()}>
|
|
60
|
+
{switch title {
|
|
61
|
+
| Some(titleText) =>
|
|
62
|
+
<div class="basefn-drawer__header">
|
|
63
|
+
<h2 class="basefn-drawer__title"> {Component.text(titleText)} </h2>
|
|
64
|
+
{showCloseButton
|
|
65
|
+
? <button class="basefn-drawer__close" onClick={_ => onClose()}>
|
|
66
|
+
{Component.text("\u00d7")}
|
|
67
|
+
</button>
|
|
68
|
+
: <> </>}
|
|
69
|
+
</div>
|
|
70
|
+
| None => <> </>
|
|
71
|
+
}}
|
|
72
|
+
<div class="basefn-drawer__body"> {children} </div>
|
|
73
|
+
{switch footer {
|
|
74
|
+
| Some(footerContent) => <div class="basefn-drawer__footer"> {footerContent} </div>
|
|
75
|
+
| None => <> </>
|
|
76
|
+
}}
|
|
77
|
+
</div>
|
|
78
|
+
</>,
|
|
79
|
+
]
|
|
80
|
+
} else {
|
|
81
|
+
[]
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
Component.signalFragment(content)
|
|
86
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Xote from "xote/src/Xote.res.mjs";
|
|
4
|
+
import * as Xote__JSX from "xote/src/Xote__JSX.res.mjs";
|
|
5
|
+
|
|
6
|
+
import './Basefn__Drawer.css'
|
|
7
|
+
;
|
|
8
|
+
|
|
9
|
+
function positionToString(position) {
|
|
10
|
+
switch (position) {
|
|
11
|
+
case "Left" :
|
|
12
|
+
return "left";
|
|
13
|
+
case "Right" :
|
|
14
|
+
return "right";
|
|
15
|
+
case "Top" :
|
|
16
|
+
return "top";
|
|
17
|
+
case "Bottom" :
|
|
18
|
+
return "bottom";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function sizeToString(size) {
|
|
23
|
+
switch (size) {
|
|
24
|
+
case "Sm" :
|
|
25
|
+
return "sm";
|
|
26
|
+
case "Md" :
|
|
27
|
+
return "md";
|
|
28
|
+
case "Lg" :
|
|
29
|
+
return "lg";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function Basefn__Drawer(props) {
|
|
34
|
+
let footer = props.footer;
|
|
35
|
+
let children = props.children;
|
|
36
|
+
let __closeOnBackdrop = props.closeOnBackdrop;
|
|
37
|
+
let __showCloseButton = props.showCloseButton;
|
|
38
|
+
let title = props.title;
|
|
39
|
+
let __size = props.size;
|
|
40
|
+
let __position = props.position;
|
|
41
|
+
let onClose = props.onClose;
|
|
42
|
+
let isOpen = props.isOpen;
|
|
43
|
+
let position = __position !== undefined ? __position : "Right";
|
|
44
|
+
let size = __size !== undefined ? __size : "Md";
|
|
45
|
+
let showCloseButton = __showCloseButton !== undefined ? __showCloseButton : true;
|
|
46
|
+
let closeOnBackdrop = __closeOnBackdrop !== undefined ? __closeOnBackdrop : true;
|
|
47
|
+
let handleBackdropClick = evt => {
|
|
48
|
+
if (!closeOnBackdrop) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
let target = evt.target;
|
|
52
|
+
let currentTarget = evt.currentTarget;
|
|
53
|
+
if (target === currentTarget) {
|
|
54
|
+
return onClose();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
let getDrawerClass = () => {
|
|
58
|
+
let positionClass = "basefn-drawer--" + positionToString(position);
|
|
59
|
+
let sizeClass = "basefn-drawer--" + sizeToString(size);
|
|
60
|
+
return "basefn-drawer " + positionClass + " " + sizeClass;
|
|
61
|
+
};
|
|
62
|
+
return Xote.Component.signalFragment(Xote.Computed.make(() => {
|
|
63
|
+
if (Xote.Signal.get(isOpen)) {
|
|
64
|
+
return [Xote__JSX.jsxs(Xote__JSX.jsxFragment, {
|
|
65
|
+
children: Xote__JSX.array([
|
|
66
|
+
Xote__JSX.Elements.jsx("div", {
|
|
67
|
+
class: "basefn-drawer-backdrop",
|
|
68
|
+
onClick: handleBackdropClick
|
|
69
|
+
}),
|
|
70
|
+
Xote__JSX.Elements.jsxs("div", {
|
|
71
|
+
class: getDrawerClass(),
|
|
72
|
+
children: Xote__JSX.array([
|
|
73
|
+
title !== undefined ? Xote__JSX.Elements.jsxs("div", {
|
|
74
|
+
class: "basefn-drawer__header",
|
|
75
|
+
children: Xote__JSX.array([
|
|
76
|
+
Xote__JSX.Elements.jsx("h2", {
|
|
77
|
+
class: "basefn-drawer__title",
|
|
78
|
+
children: Xote.Component.text(title)
|
|
79
|
+
}),
|
|
80
|
+
showCloseButton ? Xote__JSX.Elements.jsx("button", {
|
|
81
|
+
class: "basefn-drawer__close",
|
|
82
|
+
onClick: param => onClose(),
|
|
83
|
+
children: Xote.Component.text("\u00d7")
|
|
84
|
+
}) : Xote__JSX.jsx(Xote__JSX.jsxFragment, {})
|
|
85
|
+
])
|
|
86
|
+
}) : Xote__JSX.jsx(Xote__JSX.jsxFragment, {}),
|
|
87
|
+
Xote__JSX.Elements.jsx("div", {
|
|
88
|
+
class: "basefn-drawer__body",
|
|
89
|
+
children: children
|
|
90
|
+
}),
|
|
91
|
+
footer !== undefined ? Xote__JSX.Elements.jsx("div", {
|
|
92
|
+
class: "basefn-drawer__footer",
|
|
93
|
+
children: footer
|
|
94
|
+
}) : Xote__JSX.jsx(Xote__JSX.jsxFragment, {})
|
|
95
|
+
])
|
|
96
|
+
})
|
|
97
|
+
])
|
|
98
|
+
})];
|
|
99
|
+
} else {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}, undefined));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let make = Basefn__Drawer;
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
positionToString,
|
|
109
|
+
sizeToString,
|
|
110
|
+
make,
|
|
111
|
+
}
|
|
112
|
+
/* Not a pure module */
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
.basefn-dropdown {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-block;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.basefn-dropdown__menu {
|
|
7
|
+
position: absolute;
|
|
8
|
+
top: calc(100% + 4px);
|
|
9
|
+
left: 0;
|
|
10
|
+
min-width: 200px;
|
|
11
|
+
background: white;
|
|
12
|
+
border: 1px solid #e5e7eb;
|
|
13
|
+
border-radius: 0.5rem;
|
|
14
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
15
|
+
z-index: 100;
|
|
16
|
+
animation: basefn-dropdown-fade-in 0.15s ease-out;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.basefn-dropdown__menu--right {
|
|
21
|
+
left: auto;
|
|
22
|
+
right: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.basefn-dropdown__item {
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
gap: 0.75rem;
|
|
29
|
+
width: 100%;
|
|
30
|
+
padding: 0.75rem 1rem;
|
|
31
|
+
font-size: 0.875rem;
|
|
32
|
+
color: #374151;
|
|
33
|
+
background: none;
|
|
34
|
+
border: none;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
transition: background-color 0.15s;
|
|
37
|
+
text-align: left;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.basefn-dropdown__item:hover {
|
|
41
|
+
background-color: #f3f4f6;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.basefn-dropdown__item--disabled {
|
|
45
|
+
opacity: 0.5;
|
|
46
|
+
cursor: not-allowed;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.basefn-dropdown__item--disabled:hover {
|
|
50
|
+
background-color: transparent;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.basefn-dropdown__item--danger {
|
|
54
|
+
color: #ef4444;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.basefn-dropdown__item--danger:hover {
|
|
58
|
+
background-color: #fee2e2;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.basefn-dropdown__separator {
|
|
62
|
+
height: 1px;
|
|
63
|
+
background-color: #e5e7eb;
|
|
64
|
+
margin: 0.25rem 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@keyframes basefn-dropdown-fade-in {
|
|
68
|
+
from {
|
|
69
|
+
opacity: 0;
|
|
70
|
+
transform: translateY(-4px);
|
|
71
|
+
}
|
|
72
|
+
to {
|
|
73
|
+
opacity: 1;
|
|
74
|
+
transform: translateY(0);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
%%raw(`import './Basefn__Dropdown.css'`)
|
|
2
|
+
|
|
3
|
+
open Xote
|
|
4
|
+
|
|
5
|
+
type menuItem = {
|
|
6
|
+
label: string,
|
|
7
|
+
onClick: unit => unit,
|
|
8
|
+
disabled?: bool,
|
|
9
|
+
danger?: bool,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type menuContent =
|
|
13
|
+
| Item(menuItem)
|
|
14
|
+
| Separator
|
|
15
|
+
|
|
16
|
+
@jsx.component
|
|
17
|
+
let make = (
|
|
18
|
+
~trigger: Component.node,
|
|
19
|
+
~items: array<menuContent>,
|
|
20
|
+
~align: [#left | #right]=#left,
|
|
21
|
+
) => {
|
|
22
|
+
let isOpen = Signal.make(false)
|
|
23
|
+
|
|
24
|
+
let handleToggle = _ => {
|
|
25
|
+
Signal.update(isOpen, prev => !prev)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let handleItemClick = (onClick: unit => unit, disabled: bool) => {
|
|
29
|
+
switch disabled {
|
|
30
|
+
| true => ()
|
|
31
|
+
| _ => {
|
|
32
|
+
onClick()
|
|
33
|
+
Signal.set(isOpen, false)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let getMenuClass = () => {
|
|
39
|
+
let baseClass = "basefn-dropdown__menu"
|
|
40
|
+
let alignClass = switch align {
|
|
41
|
+
| #right => " basefn-dropdown__menu--right"
|
|
42
|
+
| #left => ""
|
|
43
|
+
}
|
|
44
|
+
baseClass ++ alignClass
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let menuContent = Computed.make(() => {
|
|
48
|
+
if Signal.get(isOpen) {
|
|
49
|
+
[
|
|
50
|
+
<div class={getMenuClass()}>
|
|
51
|
+
{items
|
|
52
|
+
->Array.mapWithIndex((item, index) => {
|
|
53
|
+
switch item {
|
|
54
|
+
| Item({label, onClick, disabled, danger}) => {
|
|
55
|
+
let className =
|
|
56
|
+
"basefn-dropdown__item" ++
|
|
57
|
+
(disabled ? " basefn-dropdown__item--disabled" : "") ++ (
|
|
58
|
+
danger ? " basefn-dropdown__item--danger" : ""
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
<button
|
|
62
|
+
key={Int.toString(index)}
|
|
63
|
+
class={className}
|
|
64
|
+
onClick={_ => handleItemClick(onClick, disabled)}
|
|
65
|
+
disabled={disabled}
|
|
66
|
+
>
|
|
67
|
+
{Component.text(label)}
|
|
68
|
+
</button>
|
|
69
|
+
}
|
|
70
|
+
| Separator => <div key={Int.toString(index)} class="basefn-dropdown__separator" />
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
->Component.fragment}
|
|
74
|
+
</div>,
|
|
75
|
+
]
|
|
76
|
+
} else {
|
|
77
|
+
[]
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
<div class="basefn-dropdown">
|
|
82
|
+
<div onClick={handleToggle}> {trigger} </div>
|
|
83
|
+
{Component.signalFragment(menuContent)}
|
|
84
|
+
</div>
|
|
85
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Xote from "xote/src/Xote.res.mjs";
|
|
4
|
+
import * as Xote__JSX from "xote/src/Xote__JSX.res.mjs";
|
|
5
|
+
|
|
6
|
+
import './Basefn__Dropdown.css'
|
|
7
|
+
;
|
|
8
|
+
|
|
9
|
+
function Basefn__Dropdown(props) {
|
|
10
|
+
let __align = props.align;
|
|
11
|
+
let items = props.items;
|
|
12
|
+
let align = __align !== undefined ? __align : "left";
|
|
13
|
+
let isOpen = Xote.Signal.make(false, undefined, undefined);
|
|
14
|
+
let handleToggle = param => Xote.Signal.update(isOpen, prev => !prev);
|
|
15
|
+
let getMenuClass = () => {
|
|
16
|
+
let alignClass = align === "right" ? " basefn-dropdown__menu--right" : "";
|
|
17
|
+
return "basefn-dropdown__menu" + alignClass;
|
|
18
|
+
};
|
|
19
|
+
let menuContent = Xote.Computed.make(() => {
|
|
20
|
+
if (Xote.Signal.get(isOpen)) {
|
|
21
|
+
return [Xote__JSX.Elements.jsx("div", {
|
|
22
|
+
class: getMenuClass(),
|
|
23
|
+
children: Xote.Component.fragment(items.map((item, index) => {
|
|
24
|
+
if (typeof item !== "object") {
|
|
25
|
+
return Xote__JSX.Elements.jsxKeyed("div", {
|
|
26
|
+
class: "basefn-dropdown__separator"
|
|
27
|
+
}, index.toString(), undefined);
|
|
28
|
+
}
|
|
29
|
+
let match = item._0;
|
|
30
|
+
let disabled = match.disabled;
|
|
31
|
+
if (disabled !== undefined) {
|
|
32
|
+
let danger = match.danger;
|
|
33
|
+
if (danger !== undefined) {
|
|
34
|
+
let onClick = match.onClick;
|
|
35
|
+
let className = "basefn-dropdown__item" + (
|
|
36
|
+
disabled ? " basefn-dropdown__item--disabled" : ""
|
|
37
|
+
) + (
|
|
38
|
+
danger ? " basefn-dropdown__item--danger" : ""
|
|
39
|
+
);
|
|
40
|
+
return Xote__JSX.Elements.jsxKeyed("button", {
|
|
41
|
+
class: className,
|
|
42
|
+
disabled: disabled,
|
|
43
|
+
onClick: param => {
|
|
44
|
+
if (disabled) {
|
|
45
|
+
return;
|
|
46
|
+
} else {
|
|
47
|
+
onClick();
|
|
48
|
+
return Xote.Signal.set(isOpen, false);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
children: Xote.Component.text(match.label)
|
|
52
|
+
}, index.toString(), undefined);
|
|
53
|
+
}
|
|
54
|
+
throw {
|
|
55
|
+
RE_EXN_ID: "Match_failure",
|
|
56
|
+
_1: [
|
|
57
|
+
"Basefn__Dropdown.res",
|
|
58
|
+
53,
|
|
59
|
+
12
|
|
60
|
+
],
|
|
61
|
+
Error: new Error()
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
throw {
|
|
65
|
+
RE_EXN_ID: "Match_failure",
|
|
66
|
+
_1: [
|
|
67
|
+
"Basefn__Dropdown.res",
|
|
68
|
+
53,
|
|
69
|
+
12
|
|
70
|
+
],
|
|
71
|
+
Error: new Error()
|
|
72
|
+
};
|
|
73
|
+
}))
|
|
74
|
+
})];
|
|
75
|
+
} else {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
}, undefined);
|
|
79
|
+
return Xote__JSX.Elements.jsxs("div", {
|
|
80
|
+
class: "basefn-dropdown",
|
|
81
|
+
children: Xote__JSX.array([
|
|
82
|
+
Xote__JSX.Elements.jsx("div", {
|
|
83
|
+
onClick: handleToggle,
|
|
84
|
+
children: props.trigger
|
|
85
|
+
}),
|
|
86
|
+
Xote.Component.signalFragment(menuContent)
|
|
87
|
+
])
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let make = Basefn__Dropdown;
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
make,
|
|
95
|
+
}
|
|
96
|
+
/* Not a pure module */
|