2022-09-07 16:53:24 +03:00
|
|
|
import { useContext, Fragment } from "react";
|
2022-08-25 11:14:17 +03:00
|
|
|
import { IoColorPalette } from "react-icons/io5";
|
|
|
|
import { Popover, Transition } from "@headlessui/react";
|
2022-09-07 16:53:24 +03:00
|
|
|
import classNames from "classnames";
|
2022-09-26 12:04:37 +03:00
|
|
|
import { ColorContext } from "utils/contexts/color";
|
2022-08-25 11:14:17 +03:00
|
|
|
|
|
|
|
const colors = [
|
|
|
|
"slate",
|
|
|
|
"gray",
|
|
|
|
"zinc",
|
|
|
|
"neutral",
|
|
|
|
"stone",
|
|
|
|
"amber",
|
|
|
|
"yellow",
|
|
|
|
"lime",
|
|
|
|
"green",
|
|
|
|
"emerald",
|
|
|
|
"teal",
|
|
|
|
"cyan",
|
|
|
|
"sky",
|
|
|
|
"blue",
|
|
|
|
"indigo",
|
|
|
|
"violet",
|
|
|
|
"purple",
|
|
|
|
"fuchsia",
|
|
|
|
"pink",
|
|
|
|
"rose",
|
|
|
|
"red",
|
2022-09-09 06:45:43 +03:00
|
|
|
"white",
|
2022-08-25 11:14:17 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
export default function ColorToggle() {
|
|
|
|
const { color: active, setColor } = useContext(ColorContext);
|
|
|
|
|
|
|
|
if (!active) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-09-10 23:36:54 +02:00
|
|
|
<div id="color" className="w-full self-center">
|
2022-08-25 11:14:17 +03:00
|
|
|
<Popover className="relative flex items-center">
|
2025-03-02 08:42:57 -08:00
|
|
|
<Popover.Button className="outline-hidden">
|
2022-09-07 16:53:24 +03:00
|
|
|
<IoColorPalette
|
|
|
|
className="h-5 w-5 text-theme-800 dark:text-theme-200 transition duration-150 ease-in-out"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-09-26 15:03:02 +03:00
|
|
|
<span className="sr-only">Change color</span>
|
2022-09-07 16:53:24 +03:00
|
|
|
</Popover.Button>
|
|
|
|
<Transition
|
|
|
|
as={Fragment}
|
|
|
|
enter="transition ease-out duration-200"
|
|
|
|
enterFrom="opacity-0 translate-y-1"
|
|
|
|
enterTo="opacity-100 translate-y-0"
|
|
|
|
leave="transition ease-in duration-150"
|
|
|
|
leaveFrom="opacity-100 translate-y-0"
|
|
|
|
leaveTo="opacity-0 translate-y-1"
|
|
|
|
>
|
|
|
|
<Popover.Panel className="absolute -top-[75px] left-0">
|
2022-09-11 19:11:58 +03:00
|
|
|
<div className="rounded-md shadow-lg ring-1 ring-black ring-opacity-5 w-[85vw] sm:w-full">
|
2022-09-09 06:45:43 +03:00
|
|
|
<div className="relative grid gap-2 p-2 grid-cols-11 bg-white/50 dark:bg-white/10 shadow-black/10 dark:shadow-black/20 rounded-md shadow-md">
|
2022-09-07 16:53:24 +03:00
|
|
|
{colors.map((color) => (
|
|
|
|
<button type="button" onClick={() => setColor(color)} key={color}>
|
|
|
|
<div
|
2022-09-15 19:58:41 +03:00
|
|
|
title={color}
|
2022-09-07 16:53:24 +03:00
|
|
|
className={classNames(
|
|
|
|
active === color ? "border-2" : "border-0",
|
2023-10-17 23:26:55 -07:00
|
|
|
`rounded-md w-5 h-5 border-black/50 dark:border-white/50 theme-${color} bg-theme-400`,
|
2022-09-07 16:53:24 +03:00
|
|
|
)}
|
|
|
|
/>
|
2022-09-26 15:03:02 +03:00
|
|
|
<span className="sr-only">{color}</span>
|
2022-09-07 16:53:24 +03:00
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Popover.Panel>
|
|
|
|
</Transition>
|
2022-08-25 11:14:17 +03:00
|
|
|
</Popover>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|