el.xwx.moe/components/IconPicker.tsx

84 lines
2.0 KiB
TypeScript
Raw Normal View History

import React, { useState } from "react";
2024-08-16 22:00:37 -05:00
import TextInput from "./TextInput";
import Popover from "./Popover";
import { HexColorPicker } from "react-colorful";
2024-08-20 15:59:01 -05:00
import { useTranslation } from "next-i18next";
import Icon from "./Icon";
2024-08-20 15:59:01 -05:00
import { IconWeight } from "@phosphor-icons/react";
import IconGrid from "./IconGrid";
2024-08-30 01:38:58 -05:00
import IconPopover from "./IconPopover";
import clsx from "clsx";
2024-08-16 22:00:37 -05:00
type Props = {
2024-08-24 14:50:29 -05:00
alignment?: string;
color: string;
setColor: Function;
2024-08-20 15:59:01 -05:00
iconName?: string;
setIconName: Function;
2024-08-20 15:59:01 -05:00
weight: "light" | "regular" | "bold" | "fill" | "duotone" | "thin";
setWeight: Function;
2024-08-24 14:50:29 -05:00
hideDefaultIcon?: boolean;
2024-08-20 15:59:01 -05:00
reset: Function;
className?: string;
};
2024-08-16 22:00:37 -05:00
const IconPicker = ({
alignment,
color,
setColor,
iconName,
setIconName,
weight,
setWeight,
2024-08-24 14:50:29 -05:00
hideDefaultIcon,
className,
2024-08-20 15:59:01 -05:00
reset,
}: Props) => {
2024-08-20 15:59:01 -05:00
const { t } = useTranslation();
const [iconPicker, setIconPicker] = useState(false);
2024-08-16 22:00:37 -05:00
return (
2024-08-20 15:59:01 -05:00
<div className="relative">
<div
onClick={() => setIconPicker(!iconPicker)}
className="btn btn-square w-20 h-20"
>
{iconName ? (
<Icon
icon={iconName}
size={60}
weight={(weight || "regular") as IconWeight}
color={color || "#0ea5e9"}
/>
2024-08-24 14:50:29 -05:00
) : !iconName && hideDefaultIcon ? (
<p className="p-1">{t("set_custom_icon")}</p>
2024-08-20 15:59:01 -05:00
) : (
<i
className="bi-folder-fill text-6xl"
style={{ color: color || "#0ea5e9" }}
></i>
)}
</div>
{iconPicker && (
2024-08-30 01:38:58 -05:00
<IconPopover
alignment={alignment}
color={color}
setColor={setColor}
iconName={iconName}
setIconName={setIconName}
weight={weight}
setWeight={setWeight}
reset={reset}
2024-08-20 15:59:01 -05:00
onClose={() => setIconPicker(false)}
2024-08-30 01:38:58 -05:00
className={clsx(
className,
alignment || "lg:-translate-x-1/3 top-20 left-0"
)}
/>
2024-08-20 15:59:01 -05:00
)}
</div>
2024-08-16 22:00:37 -05:00
);
};
export default IconPicker;