mirror of https://github.com/usememos/memos
chore: clean dropdown
parent
c522e1450a
commit
7f5148d490
@ -1,64 +0,0 @@
|
|||||||
import { ReactNode, useEffect, useRef } from "react";
|
|
||||||
import useToggle from "react-use/lib/useToggle";
|
|
||||||
import Icon from "../Icon";
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
trigger?: ReactNode;
|
|
||||||
actions?: ReactNode;
|
|
||||||
disabled?: boolean;
|
|
||||||
className?: string;
|
|
||||||
actionsClassName?: string;
|
|
||||||
positionClassName?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Dropdown: React.FC<Props> = (props: Props) => {
|
|
||||||
const { trigger, actions, disabled, className, actionsClassName, positionClassName } = props;
|
|
||||||
const [dropdownStatus, toggleDropdownStatus] = useToggle(false);
|
|
||||||
const dropdownWrapperRef = useRef<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (dropdownStatus) {
|
|
||||||
const handleClickOutside = (event: MouseEvent) => {
|
|
||||||
if (!dropdownWrapperRef.current?.contains(event.target as Node)) {
|
|
||||||
toggleDropdownStatus(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
window.addEventListener("click", handleClickOutside, {
|
|
||||||
capture: true,
|
|
||||||
once: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [dropdownStatus]);
|
|
||||||
|
|
||||||
const handleDropdownClick = () => {
|
|
||||||
if (disabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
toggleDropdownStatus();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
ref={dropdownWrapperRef}
|
|
||||||
className={`relative flex flex-col justify-start items-start select-none ${className ?? ""}`}
|
|
||||||
onClick={handleDropdownClick}
|
|
||||||
>
|
|
||||||
{trigger ? (
|
|
||||||
trigger
|
|
||||||
) : (
|
|
||||||
<button className="flex flex-row justify-center items-center border dark:border-zinc-700 p-1 rounded shadow text-gray-600 dark:text-gray-200 cursor-pointer hover:opacity-80">
|
|
||||||
<Icon.MoreHorizontal className="w-4 h-auto" />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
<div
|
|
||||||
className={`w-auto absolute flex flex-col justify-start items-start bg-white dark:bg-zinc-700 z-10 p-1 rounded-md shadow ${
|
|
||||||
dropdownStatus ? "" : "!hidden"
|
|
||||||
} ${actionsClassName ?? ""} ${positionClassName ?? "top-full right-0 mt-1"}`}
|
|
||||||
>
|
|
||||||
{actions}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Dropdown;
|
|
@ -1,50 +0,0 @@
|
|||||||
.date-picker-wrapper {
|
|
||||||
@apply flex flex-col justify-start items-start p-4;
|
|
||||||
|
|
||||||
> .date-picker-header {
|
|
||||||
@apply flex flex-row justify-center items-center w-full mb-2;
|
|
||||||
|
|
||||||
> .btn-text {
|
|
||||||
@apply w-6 h-6 rounded cursor-pointer select-none flex flex-col justify-center items-center opacity-40 hover:bg-gray-200;
|
|
||||||
}
|
|
||||||
|
|
||||||
> .normal-text {
|
|
||||||
@apply mx-1 leading-6 font-mono;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> .date-picker-day-container {
|
|
||||||
@apply flex flex-row justify-start items-start;
|
|
||||||
width: 280px;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
|
|
||||||
> .date-picker-day-header {
|
|
||||||
@apply flex flex-row justify-around items-center w-full;
|
|
||||||
|
|
||||||
> .day-item {
|
|
||||||
@apply w-9 h-9 select-none flex flex-col justify-center items-center;
|
|
||||||
color: gray;
|
|
||||||
font-size: 13px;
|
|
||||||
margin: 2px 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> .day-item {
|
|
||||||
@apply w-9 h-9 rounded-full text-sm select-none cursor-pointer flex flex-col justify-center items-center hover:bg-gray-200 dark:hover:bg-zinc-600;
|
|
||||||
margin: 2px;
|
|
||||||
|
|
||||||
&.current {
|
|
||||||
@apply text-blue-600 !bg-blue-100 text-base font-medium;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.disabled {
|
|
||||||
@apply cursor-not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.null {
|
|
||||||
background-color: unset;
|
|
||||||
cursor: unset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue