@colisweb/rescript-toolkit 3.3.1 → 3.4.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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "3.3.1",
3
+ "version": "3.4.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -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
+ }
@@ -1,5 +1,6 @@
1
1
  module Button = Toolkit__Ui_Button
2
2
  module ButtonGroup = Toolkit__Ui_ButtonGroup
3
+ module ButtonGroup2 = Toolkit__Ui_ButtonGroup2
3
4
  module Spinner = Toolkit__Ui_Spinner
4
5
  module Card = Toolkit__Ui_Card
5
6
  module Modal = Toolkit__Ui_Modal
@@ -0,0 +1,55 @@
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
+
25
+ React.useEffect1(() => {
26
+ onIndexChange->Option.forEach(fn =>
27
+ fn(activeIndex, (buttons[activeIndex]->Option.getUnsafe).value)
28
+ )
29
+ None
30
+ }, [activeIndex])
31
+
32
+ <div
33
+ className={cx([
34
+ className,
35
+ "flex justify-center items-center rounded-full font-display bg-gray-200 cw-ButtonGroup",
36
+ isMd ? "h-6" : "h-10",
37
+ isMd ? "text-sm" : "text-xl",
38
+ ])}>
39
+ {buttons
40
+ ->Array.mapWithIndex((i, button) => {
41
+ <button
42
+ key={`btn-group-${i->Int.toString}`}
43
+ onClick={event => {
44
+ setActiveIndex(_ => i)
45
+ button.onClick->Option.forEach(fn => {
46
+ fn(event)
47
+ })
48
+ }}
49
+ className={cx([activeIndex === i ? "selected" : ""])}>
50
+ {button.label}
51
+ </button>
52
+ })
53
+ ->React.array}
54
+ </div>
55
+ }
@@ -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