summaryrefslogtreecommitdiff
path: root/src/components/CollapsibleItemGroup.tsx
blob: a66a8ba5d937430f9f18ff1634288fa3d36ca289 (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
70
71
72
73
74
75
76
77
78
79
import { ButtonItem, Field, PanelSectionRow } from "@decky/ui";
import { type RefObject } from "react";
import { RiArrowDownSFill, RiArrowUpSFill } from "react-icons/ri";

export interface CollapsibleItem {
  id: string;
  label: string;
  description: string;
}

export const collapsibleItemGroupStyles = `
  .LSFG_GameGroupCollapseButton_Container > div > div > div > button,
  .LSFG_GameGroupCollapseButton_Container > div > div > div > div > button {
    height: 24px !important;
    min-height: 24px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .LSFG_GameGroupCollapseButton_Container svg {
    display: block;
    margin: 0;
  }
`;

interface Props {
  title: string;
  items: CollapsibleItem[];
  collapsed: boolean;
  onToggle: () => void;
  onSelect: (id: string) => void;
  toggleRef?: RefObject<HTMLDivElement>;
}

export function CollapsibleItemGroup({
  title,
  items,
  collapsed,
  onToggle,
  onSelect,
  toggleRef,
}: Props) {
  if (items.length === 0) return null;

  return (
    <>
      <PanelSectionRow>
        <Field label={`${title} (${items.length})`} bottomSeparator="none" />
      </PanelSectionRow>
      <PanelSectionRow>
        <div
          ref={toggleRef}
          className="LSFG_GameGroupCollapseButton_Container"
          style={{ marginTop: "-2px", marginBottom: "4px" }}
        >
          <ButtonItem
            layout="below"
            bottomSeparator={collapsed ? "standard" : "none"}
            onClick={onToggle}
          >
            {collapsed ? <RiArrowDownSFill /> : <RiArrowUpSFill />}
          </ButtonItem>
        </div>
      </PanelSectionRow>
      {!collapsed && items.map((item) => (
        <PanelSectionRow key={item.id}>
          <Field
            label={item.label}
            description={item.description}
            onActivate={() => onSelect(item.id)}
            highlightOnFocus
          />
        </PanelSectionRow>
      ))}
    </>
  );
}