refactor docker stats open/close

pull/302/head
Ben Phelps 2 years ago
parent 50fe6041f0
commit 3ae4113043

@ -1,6 +1,6 @@
import Image from "next/future/image"; import Image from "next/future/image";
import { useContext } from "react"; import classNames from "classnames";
import { Disclosure } from "@headlessui/react"; import { useContext, useState } from "react";
import Status from "./status"; import Status from "./status";
import Widget from "./widget"; import Widget from "./widget";
@ -27,72 +27,75 @@ function resolveIcon(icon) {
export default function Item({ service }) { export default function Item({ service }) {
const hasLink = service.href && service.href !== "#"; const hasLink = service.href && service.href !== "#";
const { settings } = useContext(SettingsContext); const { settings } = useContext(SettingsContext);
const [statsOpen, setStatsOpen] = useState(false);
return ( return (
<li key={service.name}> <li key={service.name}>
<Disclosure> <div
<div className={`${
className={`${ hasLink ? "cursor-pointer " : " "
hasLink ? "cursor-pointer " : " " }transition-all h-15 mb-3 p-1 rounded-md font-medium text-theme-700 hover:text-theme-700/70 dark:text-theme-200 dark:hover:text-theme-300 shadow-md shadow-black/10 dark:shadow-black/20 bg-white/50 hover:bg-theme-300/20 dark:bg-white/10 dark:hover:bg-white/20`}
}transition-all h-15 mb-3 p-1 rounded-md font-medium text-theme-700 hover:text-theme-700/70 dark:text-theme-200 dark:hover:text-theme-300 shadow-md shadow-black/10 dark:shadow-black/20 bg-white/50 hover:bg-theme-300/20 dark:bg-white/10 dark:hover:bg-white/20`} >
> <div className="flex select-none">
<div className="flex select-none"> {service.icon &&
{service.icon && (hasLink ? (
(hasLink ? (
<a
href={service.href}
target={settings.target ?? "_blank"}
rel="noreferrer"
className="flex-shrink-0 flex items-center justify-center w-12 "
>
<Image src={resolveIcon(service.icon)} width={32} height={32} alt="logo" />
</a>
) : (
<div className="flex-shrink-0 flex items-center justify-center w-12 ">
<Image src={resolveIcon(service.icon)} width={32} height={32} alt="logo" />
</div>
))}
{hasLink ? (
<a <a
href={service.href} href={service.href}
target={settings.target ?? "_blank"} target={settings.target ?? "_blank"}
rel="noreferrer" rel="noreferrer"
className="flex-1 flex items-center justify-between rounded-r-md " className="flex-shrink-0 flex items-center justify-center w-12 "
> >
<div className="flex-1 px-2 py-2 text-sm text-left"> <Image src={resolveIcon(service.icon)} width={32} height={32} alt="logo" />
{service.name}
<p className="text-theme-500 dark:text-theme-400 text-xs font-light">{service.description}</p>
</div>
</a> </a>
) : ( ) : (
<div className="flex-1 flex items-center justify-between rounded-r-md "> <div className="flex-shrink-0 flex items-center justify-center w-12 ">
<div className="flex-1 px-2 py-2 text-sm text-left"> <Image src={resolveIcon(service.icon)} width={32} height={32} alt="logo" />
{service.name}
<p className="text-theme-500 dark:text-theme-400 text-xs font-light">{service.description}</p>
</div>
</div> </div>
)} ))}
{service.container && ( {hasLink ? (
<Disclosure.Button <a
as="div" href={service.href}
className="flex-shrink-0 flex items-center justify-center w-12 cursor-pointer" target={settings.target ?? "_blank"}
> rel="noreferrer"
<Status service={service} /> className="flex-1 flex items-center justify-between rounded-r-md "
</Disclosure.Button> >
)} <div className="flex-1 px-2 py-2 text-sm text-left">
</div> {service.name}
<p className="text-theme-500 dark:text-theme-400 text-xs font-light">{service.description}</p>
<Disclosure.Panel> </div>
<div className="w-full"> </a>
<Docker service={{ widget: { container: service.container, server: service.server } }} /> ) : (
<div className="flex-1 flex items-center justify-between rounded-r-md ">
<div className="flex-1 px-2 py-2 text-sm text-left">
{service.name}
<p className="text-theme-500 dark:text-theme-400 text-xs font-light">{service.description}</p>
</div>
</div> </div>
</Disclosure.Panel> )}
{service.container && (
<button
type="button"
onClick={() => setStatsOpen(!statsOpen)}
className="flex-shrink-0 flex items-center justify-center w-12 cursor-pointer"
>
<Status service={service} />
</button>
)}
</div>
{service.widget && <Widget service={service} />} <div
className={classNames(
statsOpen ? "max-h-[55px] opacity-100" : " max-h-[0] opacity-0",
"w-full overflow-hidden transition-all duration-300 ease-in-out"
)}
>
<Docker service={{ widget: { container: service.container, server: service.server } }} />
</div> </div>
</Disclosure>
{service.widget && <Widget service={service} />}
</div>
</li> </li>
); );
} }

Loading…
Cancel
Save