ui: re-introduce adaptive download pill sizing for album tiles

- AttachmentDownloadPill: bring back the optional adaptive sizing
  branch (default off). When the host sets containerType: inline-size,
  the pill scales 22-30px with the tile width using a steeper
  18cqw curve, so two-image tiles already reach 30px while tiny
  thumbs in mixed layouts stay at 22px.
- AlbumBubble: opt every tile into adaptive sizing and add the query
  container so the cqw units resolve against each tile's width.
- Single-image and video bubbles continue to render the pill at a
  fixed 30px (no host opt-in needed).
This commit is contained in:
TerryM
2026-05-30 01:27:02 +08:00
parent 4e5093cae0
commit fd46359fd9
2 changed files with 45 additions and 6 deletions

View File

@@ -12,6 +12,14 @@ type AttachmentDownloadPillProps = {
attachment: Attachment; attachment: Attachment;
leadingLabel?: string; leadingLabel?: string;
className?: string; className?: string;
/**
* When true, the pill scales with its host container's width via container-
* query units (clamped 22-30px). The host element must establish a query
* container with `style={{ containerType: "inline-size" }}`. Use this on
* album tiles so the pill shrinks on small thumbnails in mixed layouts.
* Defaults to false (fixed 30px) for standalone images/videos.
*/
adaptive?: boolean;
}; };
export function AttachmentDownloadPill({ export function AttachmentDownloadPill({
@@ -19,6 +27,7 @@ export function AttachmentDownloadPill({
attachment, attachment,
leadingLabel, leadingLabel,
className = "absolute left-2 top-2", className = "absolute left-2 top-2",
adaptive = false,
}: AttachmentDownloadPillProps) { }: AttachmentDownloadPillProps) {
const { t } = useI18n(); const { t } = useI18n();
const { showToast } = useToast(); const { showToast } = useToast();
@@ -42,23 +51,47 @@ export function AttachmentDownloadPill({
type="button" type="button"
onClick={handleDownload} onClick={handleDownload}
disabled={isDownloading} disabled={isDownloading}
className={`group z-10 inline-flex overflow-hidden rounded-full bg-black/80 text-[12px] text-white shadow-lg ring-1 ring-inset ring-white/20 backdrop-blur-md transition hover:bg-black/90 disabled:cursor-wait ${className}`} className={`group z-10 inline-flex overflow-hidden rounded-full bg-black/80 ${
adaptive ? "text-[clamp(10px,7cqw,12px)]" : "text-[12px]"
} text-white shadow-lg ring-1 ring-inset ring-white/20 backdrop-blur-md transition hover:bg-black/90 disabled:cursor-wait ${className}`}
aria-label={ aria-label={
isDownloading ? t("downloading") : `Download ${attachment.filename}` isDownloading ? t("downloading") : `Download ${attachment.filename}`
} }
aria-busy={isDownloading} aria-busy={isDownloading}
> >
<span className="flex h-[30px] w-[30px] items-center justify-center bg-[#545454]/50 transition group-hover:bg-[#545454]/70"> <span
className={`flex items-center justify-center bg-[#545454]/50 transition group-hover:bg-[#545454]/70 ${
adaptive
? "h-[clamp(22px,18cqw,30px)] w-[clamp(22px,18cqw,30px)]"
: "h-[30px] w-[30px]"
}`}
>
{isDownloading ? ( {isDownloading ? (
<LoaderCircle <LoaderCircle
className="h-[18px] w-[18px] animate-spin" className={`${
adaptive
? "h-[clamp(13px,11cqw,18px)] w-[clamp(13px,11cqw,18px)]"
: "h-[18px] w-[18px]"
} animate-spin`}
strokeWidth={2.3} strokeWidth={2.3}
/> />
) : ( ) : (
<DownloadCloudIcon className="h-[18px] w-[18px]" /> <DownloadCloudIcon
className={
adaptive
? "h-[clamp(13px,11cqw,18px)] w-[clamp(13px,11cqw,18px)]"
: "h-[18px] w-[18px]"
}
/>
)} )}
</span> </span>
<span className="flex h-[30px] items-center gap-0.5 px-2.5"> <span
className={`flex items-center gap-0.5 ${
adaptive
? "h-[clamp(22px,18cqw,30px)] px-[clamp(6px,6cqw,10px)]"
: "h-[30px] px-2.5"
}`}
>
{isDownloading ? ( {isDownloading ? (
t("downloading") t("downloading")
) : ( ) : (

View File

@@ -51,6 +51,8 @@ export function AlbumBubble({ post }: { post: Post }) {
top: `${tile.top * 100}%`, top: `${tile.top * 100}%`,
width: `calc(${tile.width * 100}% - ${ALBUM_GAP}px)`, width: `calc(${tile.width * 100}% - ${ALBUM_GAP}px)`,
height: `calc(${tile.height * 100}% - ${ALBUM_GAP}px)`, height: `calc(${tile.height * 100}% - ${ALBUM_GAP}px)`,
// Query container so the download pill scales with this tile.
containerType: "inline-size",
}} }}
> >
<button <button
@@ -76,7 +78,11 @@ export function AlbumBubble({ post }: { post: Post }) {
) : null} ) : null}
</button> </button>
{!isLastSlot ? ( {!isLastSlot ? (
<AttachmentDownloadPill postId={post.id} attachment={att} /> <AttachmentDownloadPill
postId={post.id}
attachment={att}
adaptive
/>
) : null} ) : null}
</div> </div>
); );