mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-03 23:07:34 +01:00
* feat(messenger): delivered, read and when; delete for me or for everyone; edit history (0.39.0) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmsmMXvM981mcszxEA6 * fix(sheet): a close the app caused never shuts the next sheet; tests wait for it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmsmMXvM981mcszxEA6 * test(messenger): say what the page looked like when the actions sheet did not open Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmsmMXvM981mcszxEA6 * fix(sheet): a late close event never shuts a sheet that is open again Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmsmMXvM981mcszxEA6 --------- Co-authored-by: Claude <noreply@anthropic.com>
45 lines
2.3 KiB
JavaScript
45 lines
2.3 KiB
JavaScript
"use client";
|
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
import { useEffect, useRef } from "react";
|
|
import { IconX } from "./icons.js";
|
|
/**
|
|
* A sheet from the bottom edge on a phone, a centred panel on a desktop: the
|
|
* attach menu, the sources of an answer, anything a tap opens that is more
|
|
* than a menu. A native `<dialog>` opened with `showModal()`: it renders in
|
|
* the browser's top layer, so a composer inside a transformed or
|
|
* overflow-clipped panel still gets a full sheet, and the browser supplies
|
|
* Escape, the focus trap and focus restore.
|
|
*/
|
|
export function Sheet({ open, onClose, title, closeLabel = "Close", children, }) {
|
|
const ref = useRef(null);
|
|
useEffect(() => {
|
|
const d = ref.current;
|
|
if (!d)
|
|
return;
|
|
if (open && !d.open && typeof d.showModal === "function")
|
|
d.showModal();
|
|
else if (!open && d.open)
|
|
d.close();
|
|
}, [open]);
|
|
return (_jsx("dialog", { ref: ref, className: "ck-sheet", "aria-label": title, onClose: () => {
|
|
// A <dialog>'s close event arrives a task after it closed. If the
|
|
// sheet is open again by then (an action closed it and the next long
|
|
// press reopened it), the event is about the old one: shutting the
|
|
// new sheet for it is the bug CI found.
|
|
if (ref.current?.open)
|
|
return;
|
|
onClose();
|
|
},
|
|
// A tap on the backdrop lands on the <dialog> itself, never on the
|
|
// panel inside it: that is the scrim.
|
|
onClick: (e) => {
|
|
if (e.target === e.currentTarget)
|
|
onClose();
|
|
}, children: _jsxs("div", { className: "ck-sheet-panel", children: [_jsxs("div", { className: "ck-sheet-head", children: [_jsx("span", { className: "ck-sheet-title", children: title }), _jsx("button", { type: "button", className: "ck-icon-btn ck-sheet-close", onClick: onClose, "aria-label": closeLabel, title: closeLabel, children: _jsx(IconX, {}) })] }), children] }) }));
|
|
}
|
|
/** A touch screen gets the sheet; a mouse gets the plainer thing (a file
|
|
* dialog, a row of chips) in one click. */
|
|
export function prefersSheet() {
|
|
return typeof window !== "undefined" && window.matchMedia?.("(pointer: coarse)").matches;
|
|
}
|
|
//# sourceMappingURL=Sheet.js.map
|