import type { mastodon } from "masto"; import { type Component, For, createSignal } from "solid-js"; import { css } from "solid-styled"; import tootStyle from "./toot.module.css"; import { Portal } from "solid-js/web"; import MediaViewer, { MEDIA_VIEWER_HEROSRC } from "./MediaViewer"; import { HeroSourceProvider } from "../platform/anim"; const MediaAttachmentGrid: Component<{ attachments: mastodon.v1.MediaAttachment[]; }> = (props) => { let rootRef: HTMLElement; const [viewerIndex, setViewerIndex] = createSignal(); const viewerOpened = () => typeof viewerIndex() !== "undefined"; const gridTemplateColumns = () => { const l = props.attachments.length; if (l < 2) { return "1fr"; } if (l < 4) { return "repeat(2, 1fr)"; } return "repeat(3, 1fr)"; }; const openViewerFor = (index: number) => { setViewerIndex(index); }; css` .attachments { grid-template-columns: ${gridTemplateColumns()}; } `; return (
e.stopImmediatePropagation()} > {(item, index) => { switch (item.type) { case "image": return ( {item.description ); case "video": case "gifv": case "audio": case "unknown": return
; } }}
({ [MEDIA_VIEWER_HEROSRC]: rootRef.children.item( viewerIndex() || 0, ) as HTMLElement, })} > setViewerIndex(undefined)} />
); }; export default MediaAttachmentGrid;