Files
Arkie-Library-Frontend/src/components/messageStream/bubbles/ImageWithTextBubble.tsx

42 lines
1.4 KiB
TypeScript
Raw Normal View History

2026-05-26 12:07:13 +08:00
import { useI18n } from "../../../i18n";
import type { Post } from "../../../types/post";
import { useLightbox } from "../overlays/ImageLightbox";
import { autolink } from "../utils/autolink";
2026-05-26 12:07:13 +08:00
import { postDisplayText } from "../utils/postText";
export function ImageWithTextBubble({ post }: { post: Post }) {
const { openLightbox } = useLightbox();
2026-05-26 12:07:13 +08:00
const { lang } = useI18n();
const att = post.attachments[0];
2026-05-26 12:07:13 +08:00
const text = postDisplayText(post, lang);
if (!att) return null;
const ratio =
att.width && att.height ? `${att.width} / ${att.height}` : "4 / 3";
return (
2026-05-26 14:07:10 +08:00
<div className="relative overflow-hidden rounded-xl bg-black/20">
<button
type="button"
2026-05-26 12:07:13 +08:00
onClick={() => openLightbox([att], 0, text, post.id)}
2026-05-26 14:07:10 +08:00
className="block w-full"
aria-label={att.filename}
>
<img
src={att.url}
alt={att.filename}
loading="lazy"
2026-05-26 14:07:10 +08:00
className="block h-auto w-full"
style={{ aspectRatio: ratio }}
/>
</button>
2026-05-26 12:07:13 +08:00
{text ? (
2026-05-26 14:07:10 +08:00
<div className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/85 via-black/55 to-transparent px-4 pb-4 pt-16 text-[14px] leading-snug text-neutral-100">
2026-05-26 18:03:07 +08:00
<div className="message-stream-copyable-text select-text whitespace-pre-wrap break-words">
2026-05-26 14:07:10 +08:00
{autolink(text)}
</div>
</div>
) : null}
</div>
);
}