fixed the dropdown
This commit is contained in:
parent
db47a2a142
commit
2856e23a4a
|
@ -11,7 +11,9 @@ type Props = {
|
||||||
|
|
||||||
export default function Checkbox({ label, state, className, onClick }: Props) {
|
export default function Checkbox({ label, state, className, onClick }: Props) {
|
||||||
return (
|
return (
|
||||||
<label className={`cursor-pointer flex items-center gap-2 ${className}`}>
|
<label
|
||||||
|
className={`cursor-pointer flex items-center gap-2 ${className || ""}`}
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={state}
|
checked={state}
|
||||||
|
|
|
@ -5,6 +5,7 @@ type Props = {
|
||||||
onClickOutside: Function;
|
onClickOutside: Function;
|
||||||
className?: string;
|
className?: string;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
|
onMount?: (rect: DOMRect) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
function useOutsideAlerter(
|
function useOutsideAlerter(
|
||||||
|
@ -32,10 +33,19 @@ export default function ClickAwayHandler({
|
||||||
onClickOutside,
|
onClickOutside,
|
||||||
className,
|
className,
|
||||||
style,
|
style,
|
||||||
|
onMount,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const wrapperRef = useRef(null);
|
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
useOutsideAlerter(wrapperRef, onClickOutside);
|
useOutsideAlerter(wrapperRef, onClickOutside);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (wrapperRef.current && onMount) {
|
||||||
|
const rect = wrapperRef.current.getBoundingClientRect();
|
||||||
|
onMount(rect); // Pass the bounding rectangle to the parent
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={wrapperRef} className={className} style={style}>
|
<div ref={wrapperRef} className={className} style={style}>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
@ -40,7 +40,9 @@ export default function CollectionCard({ collection, className }: Props) {
|
||||||
theme === "dark" ? "#262626" : "#f3f4f6"
|
theme === "dark" ? "#262626" : "#f3f4f6"
|
||||||
} 50%, ${theme === "dark" ? "#262626" : "#f9fafb"} 100%)`,
|
} 50%, ${theme === "dark" ? "#262626" : "#f9fafb"} 100%)`,
|
||||||
}}
|
}}
|
||||||
className={`border border-solid border-sky-100 dark:border-neutral-700 self-stretch min-h-[12rem] rounded-2xl shadow duration-100 hover:shadow-none hover:opacity-80 group relative ${className}`}
|
className={`border border-solid border-sky-100 dark:border-neutral-700 self-stretch min-h-[12rem] rounded-2xl shadow duration-100 hover:shadow-none hover:opacity-80 group relative ${
|
||||||
|
className || ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
onClick={() => setExpandDropdown(!expandDropdown)}
|
onClick={() => setExpandDropdown(!expandDropdown)}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import React, { MouseEventHandler } from "react";
|
import React, { MouseEventHandler, useEffect, useState } from "react";
|
||||||
import ClickAwayHandler from "./ClickAwayHandler";
|
import ClickAwayHandler from "./ClickAwayHandler";
|
||||||
|
|
||||||
type MenuItem =
|
type MenuItem =
|
||||||
|
@ -19,42 +19,95 @@ type Props = {
|
||||||
onClickOutside: Function;
|
onClickOutside: Function;
|
||||||
className?: string;
|
className?: string;
|
||||||
items: MenuItem[];
|
items: MenuItem[];
|
||||||
|
points: { x: number; y: number };
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
|
width: number; // in rem
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Dropdown({
|
export default function Dropdown({
|
||||||
style,
|
points,
|
||||||
onClickOutside,
|
onClickOutside,
|
||||||
className,
|
className,
|
||||||
items,
|
items,
|
||||||
|
width,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
return (
|
const [pos, setPos] = useState<{ x: number; y: number }>();
|
||||||
<ClickAwayHandler
|
const [dropdownHeight, setDropdownHeight] = useState<number>();
|
||||||
style={style}
|
|
||||||
onClickOutside={onClickOutside}
|
|
||||||
className={`${className} py-1 shadow-md border border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-800 rounded-md flex flex-col z-20`}
|
|
||||||
>
|
|
||||||
{items.map((e, i) => {
|
|
||||||
const inner = e && (
|
|
||||||
<div className="cursor-pointer rounded-md">
|
|
||||||
<div className="flex items-center gap-2 py-1 px-2 hover:bg-slate-200 dark:hover:bg-neutral-700 duration-100">
|
|
||||||
<p className="text-black dark:text-white select-none">{e.name}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return e && e.href ? (
|
function convertRemToPixels(rem: number) {
|
||||||
<Link key={i} href={e.href}>
|
return (
|
||||||
{inner}
|
rem * parseFloat(getComputedStyle(document.documentElement).fontSize)
|
||||||
</Link>
|
);
|
||||||
) : (
|
}
|
||||||
e && (
|
|
||||||
<div key={i} onClick={e.onClick}>
|
useEffect(() => {
|
||||||
{inner}
|
const dropdownWidth = convertRemToPixels(width);
|
||||||
|
|
||||||
|
let finalX = points.x;
|
||||||
|
let finalY = points.y;
|
||||||
|
|
||||||
|
// Check for x-axis overflow (left side)
|
||||||
|
if (points.x + dropdownWidth > window.innerWidth) {
|
||||||
|
finalX = points.x - dropdownWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for y-axis overflow (bottom side)
|
||||||
|
if (dropdownHeight && points.y + dropdownHeight > window.innerHeight) {
|
||||||
|
finalY =
|
||||||
|
window.innerHeight - (dropdownHeight + (window.innerHeight - points.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
setPos({ x: finalX, y: finalY });
|
||||||
|
}, [points, width, dropdownHeight]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const dropdownWidth = convertRemToPixels(width);
|
||||||
|
|
||||||
|
if (points.x + dropdownWidth > window.innerWidth) {
|
||||||
|
setPos({ x: points.x - dropdownWidth, y: points.y });
|
||||||
|
} else setPos(points);
|
||||||
|
}, [points, width]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
pos && (
|
||||||
|
<ClickAwayHandler
|
||||||
|
onMount={(e) => {
|
||||||
|
setDropdownHeight(e.height);
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
position: "fixed",
|
||||||
|
top: `${pos?.y}px`,
|
||||||
|
left: `${pos?.x}px`,
|
||||||
|
}}
|
||||||
|
onClickOutside={onClickOutside}
|
||||||
|
className={`${
|
||||||
|
className || ""
|
||||||
|
} py-1 shadow-md border border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-800 rounded-md flex flex-col z-20 w-[${width}rem]`}
|
||||||
|
>
|
||||||
|
{items.map((e, i) => {
|
||||||
|
const inner = e && (
|
||||||
|
<div className="cursor-pointer rounded-md">
|
||||||
|
<div className="flex items-center gap-2 py-1 px-2 hover:bg-slate-200 dark:hover:bg-neutral-700 duration-100">
|
||||||
|
<p className="text-black dark:text-white select-none">
|
||||||
|
{e.name}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
);
|
|
||||||
})}
|
return e && e.href ? (
|
||||||
</ClickAwayHandler>
|
<Link key={i} href={e.href}>
|
||||||
|
{inner}
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
e && (
|
||||||
|
<div key={i} onClick={e.onClick}>
|
||||||
|
{inner}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ClickAwayHandler>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,14 +132,15 @@ export default function LinkCard({ link, count, className }: Props) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`h-fit border border-solid border-sky-100 dark:border-neutral-700 bg-gradient-to-tr from-slate-200 dark:from-neutral-800 from-10% to-gray-50 dark:to-[#303030] via-20% shadow hover:shadow-none duration-100 rounded-2xl relative group ${className}`}
|
className={`h-fit border border-solid border-sky-100 dark:border-neutral-700 bg-gradient-to-tr from-slate-200 dark:from-neutral-800 from-10% to-gray-50 dark:to-[#303030] via-20% shadow hover:shadow-none duration-100 rounded-2xl relative group ${
|
||||||
|
className || ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
{(permissions === true ||
|
{(permissions === true ||
|
||||||
permissions?.canUpdate ||
|
permissions?.canUpdate ||
|
||||||
permissions?.canDelete) && (
|
permissions?.canDelete) && (
|
||||||
<div
|
<div
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
console.log(expandDropdown);
|
|
||||||
setExpandDropdown({ x: e.clientX, y: e.clientY });
|
setExpandDropdown({ x: e.clientX, y: e.clientY });
|
||||||
}}
|
}}
|
||||||
id={"expand-dropdown" + link.id}
|
id={"expand-dropdown" + link.id}
|
||||||
|
@ -228,11 +229,7 @@ export default function LinkCard({ link, count, className }: Props) {
|
||||||
</div>
|
</div>
|
||||||
{expandDropdown ? (
|
{expandDropdown ? (
|
||||||
<Dropdown
|
<Dropdown
|
||||||
style={{
|
points={{ x: expandDropdown.x, y: expandDropdown.y }}
|
||||||
position: "fixed",
|
|
||||||
top: `${expandDropdown.y}px`,
|
|
||||||
left: `${expandDropdown.x}px`,
|
|
||||||
}}
|
|
||||||
items={[
|
items={[
|
||||||
permissions === true
|
permissions === true
|
||||||
? {
|
? {
|
||||||
|
@ -278,7 +275,7 @@ export default function LinkCard({ link, count, className }: Props) {
|
||||||
if (target.id !== "expand-dropdown" + link.id)
|
if (target.id !== "expand-dropdown" + link.id)
|
||||||
setExpandDropdown(false);
|
setExpandDropdown(false);
|
||||||
}}
|
}}
|
||||||
className="w-40"
|
width={10}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default function Modal({ toggleModal, className, children }: Props) {
|
||||||
<div className="overflow-y-auto py-2 fixed top-0 bottom-0 right-0 left-0 bg-gray-500 bg-opacity-10 backdrop-blur-sm flex justify-center items-center fade-in z-30">
|
<div className="overflow-y-auto py-2 fixed top-0 bottom-0 right-0 left-0 bg-gray-500 bg-opacity-10 backdrop-blur-sm flex justify-center items-center fade-in z-30">
|
||||||
<ClickAwayHandler
|
<ClickAwayHandler
|
||||||
onClickOutside={toggleModal}
|
onClickOutside={toggleModal}
|
||||||
className={`m-auto ${className}`}
|
className={`m-auto ${className || ""}`}
|
||||||
>
|
>
|
||||||
<div className="slide-up relative border-sky-100 dark:border-neutral-700 rounded-2xl border-solid border shadow-lg p-5 bg-white dark:bg-neutral-900">
|
<div className="slide-up relative border-sky-100 dark:border-neutral-700 rounded-2xl border-solid border shadow-lg p-5 bg-white dark:bg-neutral-900">
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -24,7 +24,9 @@ export default function ProfilePhoto({ src, className, priority }: Props) {
|
||||||
|
|
||||||
return !image ? (
|
return !image ? (
|
||||||
<div
|
<div
|
||||||
className={`bg-sky-600 dark:bg-sky-600 text-white h-10 w-10 aspect-square shadow rounded-full border border-slate-200 dark:border-neutral-700 flex items-center justify-center ${className}`}
|
className={`bg-sky-600 dark:bg-sky-600 text-white h-10 w-10 aspect-square shadow rounded-full border border-slate-200 dark:border-neutral-700 flex items-center justify-center ${
|
||||||
|
className || ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faUser} className="w-1/2 h-1/2 aspect-square" />
|
<FontAwesomeIcon icon={faUser} className="w-1/2 h-1/2 aspect-square" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -36,7 +38,9 @@ export default function ProfilePhoto({ src, className, priority }: Props) {
|
||||||
width={112}
|
width={112}
|
||||||
priority={priority}
|
priority={priority}
|
||||||
draggable={false}
|
draggable={false}
|
||||||
className={`h-10 w-10 bg-sky-600 dark:bg-sky-600 shadow rounded-full aspect-square border border-slate-200 dark:border-neutral-700 ${className}`}
|
className={`h-10 w-10 bg-sky-600 dark:bg-sky-600 shadow rounded-full aspect-square border border-slate-200 dark:border-neutral-700 ${
|
||||||
|
className || ""
|
||||||
|
}`}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,9 @@ export default function SettingsSidebar({ className }: { className?: string }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`dark:bg-neutral-900 bg-white h-full w-64 overflow-y-auto border-solid border-white border dark:border-neutral-900 border-r-sky-100 dark:border-r-neutral-700 p-5 z-20 flex flex-col gap-5 justify-between ${className}`}
|
className={`dark:bg-neutral-900 bg-white h-full w-64 overflow-y-auto border-solid border-white border dark:border-neutral-900 border-r-sky-100 dark:border-r-neutral-700 p-5 z-20 flex flex-col gap-5 justify-between ${
|
||||||
|
className || ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<Link href="/settings/account">
|
<Link href="/settings/account">
|
||||||
|
|
|
@ -51,7 +51,9 @@ export default function Sidebar({ className }: { className?: string }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`bg-gray-100 dark:bg-neutral-800 h-full w-64 xl:w-80 overflow-y-auto border-solid border dark:border-neutral-800 border-r-sky-100 dark:border-r-neutral-700 px-2 z-20 ${className}`}
|
className={`bg-gray-100 dark:bg-neutral-800 h-full w-64 xl:w-80 overflow-y-auto border-solid border dark:border-neutral-800 border-r-sky-100 dark:border-r-neutral-700 px-2 z-20 ${
|
||||||
|
className || ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<div className="flex justify-center gap-2 mt-2">
|
<div className="flex justify-center gap-2 mt-2">
|
||||||
<Link
|
<Link
|
||||||
|
|
|
@ -25,7 +25,7 @@ export default function SubmitButton({
|
||||||
loading
|
loading
|
||||||
? "bg-sky-600 cursor-auto"
|
? "bg-sky-600 cursor-auto"
|
||||||
: "bg-sky-700 hover:bg-sky-600 cursor-pointer"
|
: "bg-sky-700 hover:bg-sky-600 cursor-pointer"
|
||||||
} ${className}`}
|
} ${className || ""}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!loading && onClick) onClick();
|
if (!loading && onClick) onClick();
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -27,7 +27,9 @@ export default function TextInput({
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
className={`w-full rounded-md p-2 border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-950 border-solid border outline-none focus:border-sky-300 focus:dark:border-sky-600 duration-100 ${className}`}
|
className={`w-full rounded-md p-2 border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-950 border-solid border outline-none focus:border-sky-300 focus:dark:border-sky-600 duration-100 ${
|
||||||
|
className || ""
|
||||||
|
}`}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Ŝarĝante…
Reference in New Issue