summaryrefslogtreecommitdiff
path: root/bs5/universal/native/shared/Expander.re
blob: a64ce517f292d4f9df3754d558fbf56bfc7401f5 (plain)
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
[@warning "-26-27-32"];

open Melange_json.Primitives;

[@react.client.component]
let make =
    (
      ~id: int,
      ~title: string,
      ~children: React.element,
      ~expandedChildren: React.element,
    ) => {
  let (isExpanded, setIsExpanded) = RR.useStateValue(false);
  let (isPending, startTransition) = React.useTransition();

  <div
    className={Cx.make([
      "mb-3 flex flex-col rounded-md",
      Theme.background(Theme.Color.Gray4),
      Theme.border(Theme.Color.None),
    ])}>
    <div
      className={Cx.make([
        "relative p-4 w-full justify-between items-start flex-wrap transition-[max-height] duration-250 ease-out scale-100 flex flex-col gap-1 cursor-pointer",
      ])}>
      children
      {isExpanded ? expandedChildren : React.null}
    </div>
    <div
      className="px-4 mt-1 mb-4 cursor-pointer self-center w-full"
      onClick={_ => setIsExpanded(!isExpanded)}>
      <div
        className={Cx.make([
          isExpanded ? "" : "rotate-180",
          "w-full rounded-md flex items-center justify-center pt-1 text-sm select-none",
          "transition-[background-color] duration-250 ease-out",
          Theme.text(Theme.Color.Gray11),
          Theme.background(Theme.Color.Gray5),
          Theme.hover([Theme.background(Theme.Color.Gray7)]),
        ])}>
        {React.string("^")}
      </div>
    </div>
  </div>;
};