File size: 1,218 Bytes
9cd6ddb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { ChevronDownIcon } from "@heroicons/react/solid";
import classNames from "classnames";
import { useState } from "react";
import { useIntl } from "react-intl";

export const Collapse = ({
  children,
  title,
  className,
  open: defaultOpen = false,
  onOpenClassName,
  parentClassName,
}: {
  children: React.ReactNode;
  title: string | React.ReactNode;
  className?: string;
  open?: boolean;
  onOpenClassName?: string;
  parentClassName?: string;
}) => {
  const [open, setOpen] = useState(defaultOpen);
  const intl = useIntl();

  return (
    <div className={`${parentClassName} w-full`}>
      <div
        className={`${className} flex items-center justify-between cursor-pointer transition-all duration-200 ${
          open && onOpenClassName
        }`}
        onClick={() => setOpen(!open)}
      >
        {typeof title === "string" ? intl.formatMessage({ id: title }) : title}
        <div>
          <ChevronDownIcon
            className={classNames(
              "w-5 text-white opacity-50 transition-all duration-200",
              {
                "rotate-180": open,
              }
            )}
          />
        </div>
      </div>
      {open && children}
    </div>
  );
};