Profile: add subscribe menu

This commit is contained in:
thislight 2024-11-03 20:50:31 +08:00
parent 8a435be4c8
commit 65fa4c4fa5
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E
6 changed files with 226 additions and 151 deletions

View file

@ -3,8 +3,9 @@ import { MenuList } from "@suid/material";
import {
createEffect,
createSignal,
type Component,
type JSX,
type ParentComponent,
type ParentProps,
} from "solid-js";
import { ANIM_CURVE_STD } from "./theme";
import "./Menu.css";
@ -13,13 +14,13 @@ import {
animateShrinkToTopRight,
} from "../platform/anim";
type Anchor = Pick<DOMRect, "top" | "left" | "right">
export type Anchor = Pick<DOMRect, "top" | "left" | "right">
type Props = {
export type MenuProps = ParentProps<{
open?: boolean;
onClose?: JSX.EventHandlerUnion<HTMLDialogElement, Event>;
anchor: () => Anchor;
};
}>;
function px(n?: number) {
if (n) {
@ -29,7 +30,22 @@ function px(n?: number) {
}
}
const Menu: ParentComponent<Props> = (props) => {
export function createManagedMenuState() {
const [anchor, setAnchor] = createSignal<Anchor>();
return [
setAnchor,
{
get open() {
return !!anchor();
},
anchor: anchor as () => Anchor,
onClose: () => setAnchor(),
},
] as const;
}
const Menu: Component<MenuProps> = (props) => {
let root: HTMLDialogElement;
const windowSize = useWindowSize();