@colisweb/rescript-toolkit 3.3.1 → 3.4.1
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/.yarn/install-state.gz +0 -0
- package/package.json +1 -1
- package/playground/PlaygroundComponents.res +1 -0
- package/playground/components/Playground_ButtonGroup2.res +37 -0
- package/src/ui/Toolkit__Ui.res +1 -0
- package/src/ui/Toolkit__Ui_ButtonGroup2.res +60 -0
- package/src/ui/Toolkit__Ui_ButtonGroup2.resi +21 -0
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ let components: array<(string, module(Config))> = [
|
|
|
15
15
|
("multiselect", module(Playground_MultiSelect)),
|
|
16
16
|
("accordion", module(Playground_Accordion)),
|
|
17
17
|
("buttonGroup", module(Playground_ButtonGroup)),
|
|
18
|
+
("buttonGroup2", module(Playground_ButtonGroup2)),
|
|
18
19
|
("spinner", module(Playground_Spinner)),
|
|
19
20
|
("notice", module(Playground_Notice)),
|
|
20
21
|
("snackbar", module(Playground_Snackbar)),
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@module("@root/src/ui/Toolkit__Ui_ButtonGroup2.resi?raw")
|
|
2
|
+
external resi: string = "default"
|
|
3
|
+
|
|
4
|
+
@module("@root/playground/components/Playground_ButtonGroup2.res?raw")
|
|
5
|
+
external codeExample: string = "default"
|
|
6
|
+
|
|
7
|
+
@val
|
|
8
|
+
external alert: string => unit = "alert"
|
|
9
|
+
|
|
10
|
+
@react.component
|
|
11
|
+
let make = () => {
|
|
12
|
+
let sizes = Js.Dict.fromArray([("md", #md), ("lg", #xl)])
|
|
13
|
+
|
|
14
|
+
<div>
|
|
15
|
+
{sizes
|
|
16
|
+
->Js.Dict.entries
|
|
17
|
+
->Array.mapWithIndex((i, (sizeText, size)) =>
|
|
18
|
+
<div key={i->Int.toString ++ sizeText} className="flex flex-row mb-4 items-center">
|
|
19
|
+
<strong className="w-40"> {sizeText->React.string} </strong>
|
|
20
|
+
<Toolkit__Ui_ButtonGroup2
|
|
21
|
+
onIndexChange={(currentIndex, tabValue) => {
|
|
22
|
+
Js.log(currentIndex)
|
|
23
|
+
Js.log(tabValue)
|
|
24
|
+
}}
|
|
25
|
+
buttons={[
|
|
26
|
+
{label: "Option 1"->React.string, value: "test"},
|
|
27
|
+
{label: "Option 2"->React.string, onClick: _ => alert("clicked on option 2")},
|
|
28
|
+
{label: "Option 3"->React.string},
|
|
29
|
+
]}
|
|
30
|
+
className="my-4 self-center"
|
|
31
|
+
size
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
->React.array}
|
|
36
|
+
</div>
|
|
37
|
+
}
|
package/src/ui/Toolkit__Ui.res
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
type size = [
|
|
2
|
+
| #md
|
|
3
|
+
| #xl
|
|
4
|
+
]
|
|
5
|
+
|
|
6
|
+
type button<'value> = {
|
|
7
|
+
onClick?: ReactEvent.Mouse.t => unit,
|
|
8
|
+
label: React.element,
|
|
9
|
+
value?: 'value,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type buttons<'value> = array<button<'value>>
|
|
13
|
+
|
|
14
|
+
@react.component
|
|
15
|
+
let make = (
|
|
16
|
+
~buttons: buttons<'value>,
|
|
17
|
+
~onIndexChange: option<(int, option<'value>) => unit>=?,
|
|
18
|
+
~defaultActiveIndex=0,
|
|
19
|
+
~className="",
|
|
20
|
+
~size: size=#md,
|
|
21
|
+
) => {
|
|
22
|
+
let isMd = size === #md
|
|
23
|
+
let (activeIndex, setActiveIndex) = React.useState(() => defaultActiveIndex)
|
|
24
|
+
let previousIndex = Toolkit__Hooks.usePrevious(activeIndex)
|
|
25
|
+
|
|
26
|
+
React.useEffect2(() => {
|
|
27
|
+
onIndexChange->Option.forEach(fn => {
|
|
28
|
+
switch previousIndex {
|
|
29
|
+
| Some(previousIndex) if previousIndex !== activeIndex =>
|
|
30
|
+
fn(activeIndex, (buttons[activeIndex]->Option.getUnsafe).value)
|
|
31
|
+
| _ => ()
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
None
|
|
35
|
+
}, (activeIndex, previousIndex))
|
|
36
|
+
|
|
37
|
+
<div
|
|
38
|
+
className={cx([
|
|
39
|
+
className,
|
|
40
|
+
"flex justify-center items-center rounded-full font-display bg-gray-200 cw-ButtonGroup",
|
|
41
|
+
isMd ? "h-6" : "h-10",
|
|
42
|
+
isMd ? "text-sm" : "text-xl",
|
|
43
|
+
])}>
|
|
44
|
+
{buttons
|
|
45
|
+
->Array.mapWithIndex((i, button) => {
|
|
46
|
+
<button
|
|
47
|
+
key={`btn-group-${i->Int.toString}`}
|
|
48
|
+
onClick={event => {
|
|
49
|
+
setActiveIndex(_ => i)
|
|
50
|
+
button.onClick->Option.forEach(fn => {
|
|
51
|
+
fn(event)
|
|
52
|
+
})
|
|
53
|
+
}}
|
|
54
|
+
className={cx([activeIndex === i ? "selected" : ""])}>
|
|
55
|
+
{button.label}
|
|
56
|
+
</button>
|
|
57
|
+
})
|
|
58
|
+
->React.array}
|
|
59
|
+
</div>
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type size = [
|
|
2
|
+
| #md
|
|
3
|
+
| #xl
|
|
4
|
+
]
|
|
5
|
+
|
|
6
|
+
type button<'value> = {
|
|
7
|
+
onClick?: ReactEvent.Mouse.t => unit,
|
|
8
|
+
label: React.element,
|
|
9
|
+
value?: 'value,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type buttons<'value> = array<button<'value>>
|
|
13
|
+
|
|
14
|
+
@react.component
|
|
15
|
+
let make: (
|
|
16
|
+
~buttons: buttons<'value>,
|
|
17
|
+
~onIndexChange: (int, option<'value>) => unit=?,
|
|
18
|
+
~defaultActiveIndex: int=?,
|
|
19
|
+
~className: string=?,
|
|
20
|
+
~size: size=?,
|
|
21
|
+
) => React.element
|