summaryrefslogtreecommitdiff
path: root/bs5/universal/native/shared/SidebarNoteContent.re
blob: 36872dc4dcf9854b106b099c3e4ac4aa090490a9 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
[@warning "-26-27-32"];

open Melange_json.Primitives;

module Square = {
  [@react.component]
  let make = (~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>;
  };
};

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

  let isActive =
    switch (router.location.selectedId) {
    | Some(selectedId) => selectedId == id
    | None => false
    };

  <div
    className={Cx.make([
      "mb-3 flex flex-col rounded-md",
      Theme.background(Theme.Color.Gray4),
      isActive
        ? Theme.border(Theme.Color.Gray8) : 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",
      ])}
      onClick={_ => {
        startTransition(() => {
          router.navigate({
            selectedId: Some(id),
            isEditing: false,
            searchText: router.location.searchText,
          })
        })
      }}>
      children
      {isExpanded ? expandedChildren : React.null}
    </div>
    <div
      className="px-4 mt-1 mb-4 cursor-pointer self-center w-full"
      onClick={_ => setIsExpanded(!isExpanded)}>
      <Square isExpanded />
    </div>
  </div>;
};