peppa/apps/web/components/SettingsDialog.tsx
2026-11-15 14:47:50 +05:00

46 lines
1.6 KiB
TypeScript

"use client";
import { useRef, type ReactNode } from "react";
import { Ellipsis, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { useT } from "@/components/I18n";
/**
* Button that opens a side dialog (native <dialog>) with content rendered on the server.
* Default trigger is "⋯" (page settings); pass `trigger` for a labelled button such as "+ Стори".
*/
export function SettingsDialog({ title, trigger, children }: { title: string; trigger?: ReactNode; children: ReactNode }) {
const t = useT();
const ref = useRef<HTMLDialogElement>(null);
const open = () => ref.current?.showModal();
return (
<>
{trigger ? (
<Button size="sm" onClick={open}>
{trigger}
</Button>
) : (
<Button variant="ghost" size="icon" aria-label={title} title={title} onClick={open}>
<Ellipsis />
</Button>
)}
<dialog
ref={ref}
aria-label={title}
onClick={(e) => e.target === ref.current && ref.current.close()}
className="m-0 ml-auto h-dvh max-h-dvh w-[400px] max-w-full border-l bg-sidebar p-0 text-foreground backdrop:bg-black/50"
>
<div className="flex flex-col gap-4 px-4 py-5">
<div className="flex items-center gap-2">
<h2 className="m-0 text-[15px] font-semibold">{title}</h2>
<Button variant="ghost" size="icon" className="ml-auto" aria-label={t("Закрыть")} onClick={() => ref.current?.close()}>
<X />
</Button>
</div>
{children}
</div>
</dialog>
</>
);
}