feat: tags on tasks
This commit is contained in:
125
src/components/ModalTags.tsx
Normal file
125
src/components/ModalTags.tsx
Normal file
@@ -0,0 +1,125 @@
|
||||
import { cn } from "@/utils/class-merge";
|
||||
import { BookOpenIcon, DocumentDuplicateIcon } from "@heroicons/react/24/outline";
|
||||
import { FunctionComponent } from "preact";
|
||||
import { Dispatch, StateUpdater, useEffect, useState } from "preact/hooks";
|
||||
import Button from "./ui/Button";
|
||||
import ModalWindow from "./ui/Modal";
|
||||
|
||||
export interface ITags {
|
||||
first: string;
|
||||
second: string;
|
||||
}
|
||||
|
||||
interface ModalTagsProps {
|
||||
isOpen?: boolean;
|
||||
setIsOpen?: Dispatch<StateUpdater<boolean>>;
|
||||
onClose?: () => void;
|
||||
value?: ITags;
|
||||
onChange?: Dispatch<StateUpdater<ITags>>;
|
||||
tagsList?: {
|
||||
first: string[];
|
||||
second: string[];
|
||||
};
|
||||
}
|
||||
|
||||
const ModalTags: FunctionComponent<ModalTagsProps> = ({ isOpen, setIsOpen, onClose, onChange, value, tagsList }) => {
|
||||
const [showFirstTags, setShowFirstTags] = useState(false);
|
||||
const [showSecondTags, setShowSecondTags] = useState(false);
|
||||
useEffect(() => {
|
||||
if (showFirstTags && showSecondTags) setShowFirstTags(false);
|
||||
}, [showSecondTags]);
|
||||
useEffect(() => {
|
||||
if (showFirstTags && showSecondTags) setShowSecondTags(false);
|
||||
}, [showFirstTags]);
|
||||
return (
|
||||
<ModalWindow
|
||||
isOpen={isOpen}
|
||||
setIsOpen={setIsOpen}
|
||||
onClose={() => {
|
||||
onClose!();
|
||||
setShowFirstTags(false);
|
||||
setShowSecondTags(false);
|
||||
}}
|
||||
className="relative h-[14rem] justify-between py-4 md:h-[14rem] md:w-[25rem]"
|
||||
zIndex={70}
|
||||
>
|
||||
<p class="text-2xl font-semibold">Теги</p>
|
||||
<div class="flex w-[85%] flex-col gap-2 md:w-full">
|
||||
<Button
|
||||
className="flex w-full flex-row items-center justify-center gap-1 text-[1rem]!"
|
||||
onClick={() => setShowFirstTags(!showFirstTags)}
|
||||
>
|
||||
<BookOpenIcon class="size-6" />
|
||||
{value?.first || "Предмет"}
|
||||
</Button>
|
||||
<Button
|
||||
className="flex w-full flex-row items-center justify-center gap-1 text-[1rem]! break-words"
|
||||
onClick={() => setShowSecondTags(!showSecondTags)}
|
||||
>
|
||||
<DocumentDuplicateIcon class="size-6" />
|
||||
{value?.second || "Тема"}
|
||||
</Button>
|
||||
{showFirstTags && (
|
||||
<div class="absolute top-0 left-full ml-5 flex h-fit w-[18rem] flex-col items-center rounded-[4rem] bg-white px-8 py-4 text-xs">
|
||||
<div class="flex h-fit max-h-[45vh] w-full flex-col gap-3 overflow-y-auto">
|
||||
{tagsList?.first.map((tag) => (
|
||||
<div
|
||||
class="flex cursor-pointer flex-row gap-2"
|
||||
onClick={() =>
|
||||
onChange?.((prev) => {
|
||||
return { ...prev, first: tag };
|
||||
})
|
||||
}
|
||||
>
|
||||
<div
|
||||
class={cn(
|
||||
"pointer-events-none flex aspect-square size-4 flex-col items-center justify-center rounded-full border-1 border-black text-white select-none",
|
||||
{
|
||||
"bg-black": value?.first === tag,
|
||||
}
|
||||
)}
|
||||
>
|
||||
✓
|
||||
</div>
|
||||
<p>{tag}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{showSecondTags && (
|
||||
<div class="absolute top-0 left-full ml-5 flex h-fit w-[18rem] rounded-[4rem] bg-white px-8 py-4 text-xs">
|
||||
<div class="flex h-fit max-h-[45vh] w-full flex-col gap-3 overflow-y-auto">
|
||||
{tagsList?.second.map((tag) => (
|
||||
<div
|
||||
class="flex cursor-pointer flex-row gap-2"
|
||||
onClick={() =>
|
||||
onChange?.((prev) => {
|
||||
return { ...prev, second: tag };
|
||||
})
|
||||
}
|
||||
>
|
||||
<div
|
||||
class={cn(
|
||||
"pointer-events-none flex aspect-square size-4 flex-col items-center justify-center rounded-full border-1 border-black text-white select-none",
|
||||
{
|
||||
"bg-black": value?.second === tag,
|
||||
}
|
||||
)}
|
||||
>
|
||||
✓
|
||||
</div>
|
||||
<p>{tag}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ModalWindow>
|
||||
);
|
||||
};
|
||||
|
||||
ModalTags.displayName = "AHModalTags";
|
||||
|
||||
export default ModalTags;
|
||||
@@ -220,6 +220,9 @@ const BigCalendar: FunctionComponent<BigCalendarProps> = ({
|
||||
|
||||
return (
|
||||
<div className={`flex w-full flex-col ${className}`}>
|
||||
<div class="fixed top-0 right-[20rem] z-100 flex h-full w-full flex-col items-center justify-center bg-white">
|
||||
Закрыто
|
||||
</div>
|
||||
<div className="mb-4 flex items-center justify-between px-2">
|
||||
<button
|
||||
onClick={handlePrevMonth}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { FunctionComponent } from "preact";
|
||||
import { HTMLProps } from "preact/compat";
|
||||
import { forwardRef, HTMLProps } from "preact/compat";
|
||||
import { tv } from "tailwind-variants";
|
||||
import classes from "./Button.module.scss";
|
||||
const button = tv({
|
||||
@@ -18,19 +17,14 @@ interface ButtonProps extends HTMLProps<HTMLButtonElement> {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const Button: FunctionComponent<ButtonProps> = ({
|
||||
children,
|
||||
onClick = () => {},
|
||||
color = "primary",
|
||||
className = "",
|
||||
type = "button",
|
||||
}) => {
|
||||
const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
|
||||
const { children, onClick = () => {}, color = "primary", className = "", type = "button" } = props;
|
||||
return (
|
||||
<button type={type} class={button({ color: color, class: className })} onClick={onClick}>
|
||||
<button ref={ref} type={type} class={button({ color: color, class: className })} onClick={onClick}>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
Button.displayName = "AHButton";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user