refactor(v2): give the list view's repeated parts one home

The redesign wrote the same compact sort control into three headers, the
same compact row anatomy into four components, and a second rAF tween
beside the one it had just added.

- Extract ListSortMenu, which also settles the three different answers
  the headers gave when no column carries the current sort.
- Move the compact row's flex/stack/facts rules to global.css, beside
  the list chrome already there.
- Share one `tween` helper between the two animating composables.
- Let useAnimatedNumber take an already-formatted value, so Stat and
  PageHeader stop repeating the same number-or-string branch.
- Make the tick column a layout token instead of a constant, a CSS
  variable declared only for phones, and three literal fallbacks.
- Read the expansion duration from the motion token it documents.
- Drop the `compact` aliases that only renamed `smAndDown`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016bZ7R3xC73MZu1vTNuatPK
This commit is contained in:
zurdi
2026-09-20 19:49:51 +02:00
parent 32eb667606
commit 8feef65006
19 changed files with 305 additions and 335 deletions

View File

@@ -84,6 +84,7 @@ const NAME_OVERRIDES = {
alphaStripWidth: "--r-alpha-strip-w",
listRowHeight: "--r-list-row-h",
listHeaderHeight: "--r-list-header-h",
listSelectWidth: "--r-list-select-w",
listRowDetailHeight: "--r-list-row-detail-h",
},
colorBrand: {

View File

@@ -3,9 +3,10 @@
// list-mode view. Mirrors GameListHeader's anatomy: each sortable
// column is a button that toggles asc → desc → asc on the parent's
// sort state via the `sort` event.
import { RIcon, RMenu, RMenuItem } from "@v2/lib";
import { RIcon } from "@v2/lib";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import ListSortMenu from "@/v2/components/shared/ListSortMenu.vue";
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
import {
COLLECTION_LIST_COLUMNS,
@@ -36,15 +37,9 @@ const gridStyle = { gridTemplateColumns: COLLECTION_LIST_GRID_TEMPLATE };
// Phones and tablets drop the columns (the rows go compact), so the sort
// key they carried moves into a menu — same as the gallery's list header.
const { smAndDown } = useBreakpoint();
const compact = computed(() => smAndDown.value);
const sortableColumns = computed(() =>
COLLECTION_LIST_COLUMNS.filter((col) => col.sortKey),
);
const sortLabel = computed(() =>
t(
sortableColumns.value.find((col) => col.key === props.sortKey)?.labelKey ??
sortableColumns.value[0]?.labelKey ??
"common.name",
const sortOptions = computed(() =>
COLLECTION_LIST_COLUMNS.flatMap((col) =>
col.sortKey ? [{ key: col.sortKey, label: t(col.labelKey) }] : [],
),
);
@@ -60,46 +55,16 @@ function handleClick(col: CollectionListColumn) {
<template>
<div
v-if="compact"
v-if="smAndDown"
class="coll-list-header coll-list-header--compact"
role="row"
>
<RMenu location="bottom start" :offset="6" sheet-on-mobile>
<template #activator="{ props: activatorProps }">
<button
v-bind="activatorProps"
type="button"
class="coll-list-header__cell coll-list-header__cell--sortable coll-list-header__cell--active"
>
<span class="coll-list-header__label">{{ sortLabel }}</span>
<RIcon
:icon="
sortDir === 'asc' ? 'mdi-arrow-up-thin' : 'mdi-arrow-down-thin'
"
size="14"
class="coll-list-header__icon"
/>
</button>
</template>
<RMenuItem
v-for="col in sortableColumns"
:key="col.key"
:label="t(col.labelKey)"
:variant="sortKey === col.sortKey ? 'active' : 'default'"
@click="handleClick(col)"
>
<template #append>
<RIcon
v-if="sortKey === col.sortKey"
:icon="
sortDir === 'asc' ? 'mdi-arrow-up-thin' : 'mdi-arrow-down-thin'
"
size="14"
class="coll-list-header__icon"
/>
</template>
</RMenuItem>
</RMenu>
<ListSortMenu
:options="sortOptions"
:sort-key="sortKey"
:sort-dir="sortDir"
@sort="emit('sort', $event)"
/>
</div>
<div v-else class="coll-list-header" :style="gridStyle" role="row">

View File

@@ -47,7 +47,6 @@ const { t } = useI18n();
// Phones and tablets have no room for the columns: the row goes two-line,
// same as the gallery's list rows.
const { smAndDown } = useBreakpoint();
const compact = computed(() => smAndDown.value);
const router = useRouter();
const coverEl = ref<HTMLElement | null>(null);
const { morphTransition } = useViewTransition();
@@ -97,8 +96,8 @@ function onRowClick(e: MouseEvent) {
<template>
<a
v-if="compact"
class="coll-list-row coll-list-row--compact"
v-if="smAndDown"
class="coll-list-row coll-list-row--compact r-list-compact"
:href="to"
:aria-label="t('rom.open-game', { name })"
@click="onRowClick"
@@ -106,12 +105,12 @@ function onRowClick(e: MouseEvent) {
<div ref="coverEl" class="coll-list-row__thumb" :style="morphStyle">
<CollectionMosaic :covers="covers" />
</div>
<div class="coll-list-row__stack">
<div class="r-list-compact__stack">
<div class="coll-list-row__name">{{ name }}</div>
<div class="coll-list-row__facts">
<div class="r-list-compact__facts">
<RIcon :icon="kindBadge.icon" size="13" />
<span>{{ kindBadge.label }}</span>
<span class="coll-list-row__dot">·</span>
<span class="r-list-compact__dot">·</span>
<span>{{
t("collection.games-count", romCount, { named: { n: romCount } })
}}</span>
@@ -203,41 +202,11 @@ function onRowClick(e: MouseEvent) {
/* Compact (phones / tablets): cover + name, and the columns collapse into
one line of facts. */
.coll-list-row--compact {
display: flex;
align-items: center;
gap: var(--r-space-3);
padding: 0 var(--r-row-pad);
}
/* Clear of the screen edge, which the row itself runs to. */
.coll-list-row__lock {
margin-inline-end: var(--r-space-2);
color: var(--r-color-fg-muted);
}
.coll-list-row__stack {
display: flex;
flex-direction: column;
justify-content: center;
gap: 3px;
flex: 1;
min-width: 0;
}
.coll-list-row__facts {
display: flex;
align-items: center;
gap: 5px;
font-size: var(--r-font-size-sm);
color: var(--r-color-fg-muted);
min-width: 0;
}
.coll-list-row__facts > span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.coll-list-row__dot {
color: var(--r-color-fg-faint);
}
.coll-list-row:focus-visible {
outline: none;

View File

@@ -9,9 +9,10 @@
// Sticky positioning is owned by the parent (`GalleryShell` pins this
// below the toolbar at `top: --r-v2-shell-toolbar-h`). The header
// itself only paints — it doesn't manage scroll.
import { RCheckbox, RIcon, RMenu, RMenuItem } from "@v2/lib";
import { RCheckbox, RIcon } from "@v2/lib";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import ListSortMenu from "@/v2/components/shared/ListSortMenu.vue";
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
import { useGallerySelectAll } from "@/v2/composables/useGallerySelectAll";
import storeGallerySelection from "@/v2/stores/gallerySelection";
@@ -54,16 +55,7 @@ const gridStyle = computed(() => ({
// Phones and tablets drop the columns (the rows go compact), so the sort
// key they used to carry moves into a menu on the header.
const { smAndDown } = useBreakpoint();
const compact = computed(() => smAndDown.value);
const sortOptions = computed(() => getSortOptions(props.showPlatformColumn));
// `sortKey` is null whenever the gallery's order is one the columns don't
// carry (`last_played`, `fs_name`, …); naming a column there would claim a
// sort that isn't in effect.
const sortLabel = computed(
() =>
sortOptions.value.find((option) => option.key === props.sortKey)?.label ??
t("gallery.sort-by"),
);
const selection = storeGallerySelection();
// Whole-result select-all shared with the SelectionBar and Ctrl/Cmd+A;
@@ -82,22 +74,19 @@ function onSelectAllClick(e: MouseEvent) {
}
}
function sortBy(key: ListSortKey) {
// Toggle direction when re-picking the active key; otherwise start the
function handleClick(col: ListColumn) {
if (!isSortableColumn(col)) return;
// Toggle direction when re-clicking the active column; otherwise start the
// new one ascending, like every other sortable table in the app.
const nextDir: "asc" | "desc" =
props.sortKey === key && props.sortDir === "asc" ? "desc" : "asc";
emit("sort", { key, dir: nextDir });
}
function handleClick(col: ListColumn) {
if (isSortableColumn(col)) sortBy(col.key);
props.sortKey === col.key && props.sortDir === "asc" ? "desc" : "asc";
emit("sort", { key: col.key, dir: nextDir });
}
</script>
<template>
<div
v-if="compact"
v-if="smAndDown"
class="game-list-header game-list-header--compact"
role="row"
>
@@ -118,42 +107,12 @@ function handleClick(col: ListColumn) {
@click="onSelectAllClick"
/>
<RMenu location="bottom start" :offset="6" sheet-on-mobile>
<template #activator="{ props: activatorProps }">
<button
v-bind="activatorProps"
type="button"
class="game-list-header__cell game-list-header__cell--sortable game-list-header__cell--active"
>
<span class="game-list-header__label">{{ sortLabel }}</span>
<RIcon
:icon="
sortDir === 'asc' ? 'mdi-arrow-up-thin' : 'mdi-arrow-down-thin'
"
size="14"
class="game-list-header__icon"
/>
</button>
</template>
<RMenuItem
v-for="option in sortOptions"
:key="String(option.key)"
:label="option.label"
:variant="sortKey === option.key ? 'active' : 'default'"
@click="sortBy(option.key)"
>
<template #append>
<RIcon
v-if="sortKey === option.key"
:icon="
sortDir === 'asc' ? 'mdi-arrow-up-thin' : 'mdi-arrow-down-thin'
"
size="14"
class="game-list-header__icon"
/>
</template>
</RMenuItem>
</RMenu>
<ListSortMenu
:options="sortOptions"
:sort-key="sortKey"
:sort-dir="sortDir"
@sort="emit('sort', $event)"
/>
</div>
<div v-else class="game-list-header" :style="gridStyle" role="row">
@@ -232,7 +191,7 @@ function handleClick(col: ListColumn) {
}
.game-list-header--compact .game-list-header__check {
flex: none;
width: var(--r-list-select-w, 36px);
width: var(--r-list-select-w);
}
.game-list-header__cell {

View File

@@ -156,7 +156,6 @@ function cellModifiers(key: ListColumn["key"]) {
// Phones and tablets have no room for the columns: the row collapses to a
// title plus the facts line, and the rest moves into the detail panel.
const { smAndDown } = useBreakpoint();
const compact = computed(() => smAndDown.value);
/** Column header label, so the detail panel's captions and the desktop
* column titles can't drift apart. */
@@ -344,8 +343,8 @@ function onRowPointerEnd() {
<template v-if="rom">
<!-- COMPACT (phones / tablets) — two lines plus the chevron; the
columns move into the detail panel below. -->
<template v-if="compact">
<div class="game-list-row__compact">
<template v-if="smAndDown">
<div class="game-list-row__compact r-list-compact">
<div class="game-list-row__select">
<RCheckbox
v-if="!isStatic"
@@ -373,7 +372,7 @@ function onRowPointerEnd() {
/>
</div>
<div class="game-list-row__stack">
<div class="r-list-compact__stack">
<div class="game-list-row__name">
{{ rom.name ?? rom.fs_name_no_ext }}
</div>
@@ -701,7 +700,7 @@ function onRowPointerEnd() {
<template v-else>
<!-- Compact skeleton — same two-line shape as the compact row. -->
<div v-if="compact" class="game-list-row__compact">
<div v-if="smAndDown" class="game-list-row__compact r-list-compact">
<div class="game-list-row__select" />
<div class="game-list-row__cover">
<RSkeletonBlock
@@ -709,7 +708,7 @@ function onRowPointerEnd() {
:height="LIST_COVER_HEIGHT_PX"
/>
</div>
<div class="game-list-row__stack" :style="titleSkeletonGapStyle">
<div class="r-list-compact__stack" :style="titleSkeletonGapStyle">
<RSkeletonBlock
v-for="(bar, i) in LIST_TITLE_SKELETON_BARS"
:key="i"
@@ -815,11 +814,7 @@ html[data-bp~="sm-and-down"] .game-list-row {
border-bottom: 0;
}
.game-list-row__compact {
display: flex;
align-items: center;
gap: var(--r-space-3);
height: var(--r-list-row-h);
padding: 0 var(--r-row-pad);
border-bottom: 1px solid var(--r-color-border);
}
.game-list-row--expanded .game-list-row__compact {
@@ -827,15 +822,7 @@ html[data-bp~="sm-and-down"] .game-list-row {
}
.game-list-row__compact > .game-list-row__select {
flex: none;
width: var(--r-list-select-w, 36px);
}
.game-list-row__stack {
display: flex;
flex-direction: column;
justify-content: center;
gap: 3px;
flex: 1;
min-width: 0;
width: var(--r-list-select-w);
}
/* Two lines of title: most names fit whole, and the row keeps its height
(cover 64 + two lines + the facts line still sit inside it). */

View File

@@ -45,11 +45,10 @@ const titleGapStyle = { gap: `${LIST_TITLE_SKELETON_GAP_PX}px` };
// Phones and tablets render the compact two-line row, so the placeholder
// follows it instead of the columns.
const { smAndDown } = useBreakpoint();
const compact = computed(() => smAndDown.value);
</script>
<template>
<div v-if="compact" class="r-glr-skel r-glr-skel--compact">
<div v-if="smAndDown" class="r-glr-skel r-glr-skel--compact r-list-compact">
<!-- Stands in for the compact row's tick column, or the cover would start
further left here than in the row this replaces. -->
<div class="r-glr-skel__select" />
@@ -59,7 +58,7 @@ const compact = computed(() => smAndDown.value);
:height="LIST_COVER_HEIGHT_PX"
/>
</div>
<div class="r-glr-skel__stack" :style="titleGapStyle">
<div class="r-list-compact__stack" :style="titleGapStyle">
<RSkeletonBlock
v-for="(bar, i) in LIST_TITLE_SKELETON_BARS"
:key="i"
@@ -140,22 +139,9 @@ const compact = computed(() => smAndDown.value);
border-bottom: 1px solid var(--r-color-border);
}
.r-glr-skel--compact {
display: flex;
align-items: center;
gap: var(--r-space-3);
padding: 0 var(--r-row-pad);
}
.r-glr-skel--compact > .r-glr-skel__select {
flex: none;
width: var(--r-list-select-w, 36px);
}
.r-glr-skel__stack {
display: flex;
flex-direction: column;
justify-content: center;
flex: 1;
min-width: 0;
width: var(--r-list-select-w);
}
.r-glr-skel__cell {

View File

@@ -143,7 +143,7 @@ export function getListColumns(showPlatform: boolean): readonly ListColumn[] {
// Fixed track widths (px) — kept as data so the grid template AND the row's
// natural min-width (below) derive from the same numbers.
const LIST_SELECT_TRACK_PX = 36;
const LIST_SELECT_TRACK_PX = parseInt(layout.listSelectWidth, 10);
const LIST_PLATFORM_TRACK_PX = 200;
const LIST_METRIC_TRACKS_PX = [88, 96, 96, 56, 72, 110, 110, 88];
/** Minimum width of the title column so it stays readable when the row is

View File

@@ -5,8 +5,9 @@
//
// Phones and tablets have no columns to head (the rows go compact), so the
// sort key they carried moves into a menu — same as the collections list.
import { RIcon, RMenu, RMenuItem } from "@v2/lib";
import { RIcon } from "@v2/lib";
import { computed } from "vue";
import ListSortMenu from "@/v2/components/shared/ListSortMenu.vue";
import { useBreakpoint } from "@/v2/composables/useBreakpoint";
import {
PLATFORM_COLUMNS,
@@ -26,15 +27,11 @@ const emit = defineEmits<{
}>();
const { smAndDown } = useBreakpoint();
const compact = computed(() => smAndDown.value);
const sortableColumns = computed(() =>
PLATFORM_COLUMNS.filter((col) => col.sortable),
);
const sortLabel = computed(
() =>
sortableColumns.value.find((col) => col.key === props.sortKey)?.label ??
sortableColumns.value[0]?.label ??
"",
const sortOptions = computed(() =>
PLATFORM_COLUMNS.filter((col) => col.sortable).map((col) => ({
key: col.key,
label: col.label,
})),
);
function handleClick(col: PlatformColumn) {
@@ -47,46 +44,16 @@ function handleClick(col: PlatformColumn) {
<template>
<div
v-if="compact"
v-if="smAndDown"
class="plat-list-header plat-list-header--compact"
role="row"
>
<RMenu location="bottom start" :offset="6" sheet-on-mobile>
<template #activator="{ props: activatorProps }">
<button
v-bind="activatorProps"
type="button"
class="plat-list-header__cell plat-list-header__cell--sortable plat-list-header__cell--active"
>
<span class="plat-list-header__label">{{ sortLabel }}</span>
<RIcon
:icon="
sortDir === 'asc' ? 'mdi-arrow-up-thin' : 'mdi-arrow-down-thin'
"
size="14"
class="plat-list-header__icon"
/>
</button>
</template>
<RMenuItem
v-for="col in sortableColumns"
:key="col.key"
:label="col.label"
:variant="sortKey === col.key ? 'active' : 'default'"
@click="handleClick(col)"
>
<template #append>
<RIcon
v-if="sortKey === col.key"
:icon="
sortDir === 'asc' ? 'mdi-arrow-up-thin' : 'mdi-arrow-down-thin'
"
size="14"
class="plat-list-header__icon"
/>
</template>
</RMenuItem>
</RMenu>
<ListSortMenu
:options="sortOptions"
:sort-key="sortKey"
:sort-dir="sortDir"
@sort="emit('sort', $event)"
/>
</div>
<div v-else class="plat-list-header" role="row">

View File

@@ -51,7 +51,6 @@ const { t } = useI18n();
// Phones and tablets have no room for the columns: the row goes two-line,
// the same shape the collections list takes.
const { smAndDown } = useBreakpoint();
const compact = computed(() => smAndDown.value);
const iconEl = ref<HTMLElement | null>(null);
const { morphTransition } = useViewTransition();
@@ -90,8 +89,8 @@ function onRowClick(e: MouseEvent) {
<template>
<a
v-if="compact"
class="plat-list-row plat-list-row--compact"
v-if="smAndDown"
class="plat-list-row plat-list-row--compact r-list-compact"
:href="href"
:aria-label="t('common.open-item', { name: displayName })"
@click="onRowClick"
@@ -105,20 +104,20 @@ function onRowClick(e: MouseEvent) {
:show-tooltip="false"
/>
</div>
<div class="plat-list-row__stack">
<div class="r-list-compact__stack">
<div class="plat-list-row__name">{{ displayName }}</div>
<div class="plat-list-row__facts">
<div class="r-list-compact__facts">
<span>{{
t("collection.games-count", romCount ?? 0, {
named: { n: romCount ?? 0 },
})
}}</span>
<template v-if="categoryLabel">
<span class="plat-list-row__dot">·</span>
<span class="r-list-compact__dot">·</span>
<span>{{ categoryLabel }}</span>
</template>
<template v-if="familyName">
<span class="plat-list-row__dot">·</span>
<span class="r-list-compact__dot">·</span>
<span>{{ familyName }}</span>
</template>
</div>
@@ -229,40 +228,10 @@ function onRowClick(e: MouseEvent) {
/* Compact (phones / tablets): icon + name, and the columns collapse into
one line of facts. */
.plat-list-row--compact {
display: flex;
align-items: center;
gap: var(--r-space-3);
padding: 0 var(--r-row-pad);
}
/* Clear of the screen edge, which the row itself runs to. */
.plat-list-row--compact .plat-list-row__playable {
margin-inline-end: var(--r-space-2);
}
.plat-list-row__stack {
display: flex;
flex-direction: column;
justify-content: center;
gap: 3px;
flex: 1;
min-width: 0;
}
.plat-list-row__facts {
display: flex;
align-items: center;
gap: 5px;
font-size: var(--r-font-size-sm);
color: var(--r-color-fg-muted);
min-width: 0;
}
.plat-list-row__facts > span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.plat-list-row__dot {
color: var(--r-color-fg-faint);
}
.plat-list-row:focus-visible {
outline: none;

View File

@@ -0,0 +1,102 @@
<script setup lang="ts" generic="K extends string">
// ListSortMenu — the sort control a list header shows once its columns are
// gone (phones and tablets). Shared by the gallery, platforms and collections
// headers, so the three can't answer "what is this sorted by" three ways.
import { RIcon, RMenu, RMenuItem } from "@v2/lib";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
const props = defineProps<{
options: readonly { key: K; label: string }[];
/** Null when the list's order is one the columns don't carry. */
sortKey: K | null;
sortDir: "asc" | "desc";
}>();
const emit = defineEmits<{
(e: "sort", payload: { key: K; dir: "asc" | "desc" }): void;
}>();
const { t } = useI18n();
const dirIcon = computed(() =>
props.sortDir === "asc" ? "mdi-arrow-up-thin" : "mdi-arrow-down-thin",
);
// Naming a column the list isn't sorted by would claim a sort that isn't in
// effect, so an unknown key falls back to the control's own name.
const label = computed(
() =>
props.options.find((option) => option.key === props.sortKey)?.label ??
t("gallery.sort-by"),
);
function pick(key: K) {
// Toggle direction when re-picking the active key; otherwise start the new
// one ascending, like every other sortable table in the app.
const dir: "asc" | "desc" =
props.sortKey === key && props.sortDir === "asc" ? "desc" : "asc";
emit("sort", { key, dir });
}
</script>
<template>
<RMenu location="bottom start" :offset="6" sheet-on-mobile>
<template #activator="{ props: activatorProps }">
<button v-bind="activatorProps" type="button" class="list-sort-menu">
<span class="list-sort-menu__label">{{ label }}</span>
<RIcon :icon="dirIcon" size="14" class="list-sort-menu__icon" />
</button>
</template>
<RMenuItem
v-for="option in options"
:key="option.key"
:label="option.label"
:variant="sortKey === option.key ? 'active' : 'default'"
@click="pick(option.key)"
>
<template #append>
<RIcon
v-if="sortKey === option.key"
:icon="dirIcon"
size="14"
class="list-sort-menu__icon"
/>
</template>
</RMenuItem>
</RMenu>
</template>
<style scoped>
/* Matches the column-header cells it replaces: same uppercase micro-label,
same active tone, same brand-tinted direction glyph. */
.list-sort-menu {
appearance: none;
background: transparent;
border: 0;
padding: 0;
font: inherit;
color: var(--r-color-fg);
font-size: var(--r-font-size-xs);
font-weight: var(--r-font-weight-bold);
letter-spacing: 0.07em;
text-transform: uppercase;
display: inline-flex;
align-items: center;
gap: var(--r-space-1);
min-width: 0;
height: 100%;
cursor: pointer;
text-align: start;
border-radius: var(--r-radius-sm);
}
.list-sort-menu__label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.list-sort-menu__icon {
flex-shrink: 0;
color: var(--r-color-brand-primary);
}
</style>

View File

@@ -11,7 +11,6 @@
// gallery views (Platform / Collection / Search) share one separator
// regardless of which header sits above it.
import { RTag } from "@v2/lib";
import { computed } from "vue";
import { useAnimatedNumber } from "@/v2/composables/useAnimatedNumber";
defineOptions({ inheritAttrs: false });
@@ -26,12 +25,7 @@ const props = withDefaults(
// A numeric count rolls up to its value; a string one (a range, a label) is
// printed as it comes.
const rolling = useAnimatedNumber(() =>
typeof props.count === "number" ? props.count : null,
);
const countText = computed(() =>
typeof props.count === "number" ? rolling.value : props.count,
);
const countText = useAnimatedNumber(() => props.count);
</script>
<template>

View File

@@ -2,7 +2,6 @@
// Stat — KPI column: big value on top, small uppercase label below.
// Feature component; InfoPanel and the gallery hero cards reuse it, but
// it's not general enough to be a design-system primitive.
import { computed } from "vue";
import { useAnimatedNumber } from "@/v2/composables/useAnimatedNumber";
defineOptions({ inheritAttrs: false });
@@ -19,12 +18,7 @@ const props = withDefaults(defineProps<Props>(), {
// A count rolls up to its value; anything already formatted (a size, a date)
// is printed as it comes.
const rolling = useAnimatedNumber(() =>
typeof props.value === "number" ? props.value : null,
);
const text = computed(() =>
typeof props.value === "number" ? rolling.value : props.value,
);
const text = useAnimatedNumber(() => props.value);
</script>
<template>

View File

@@ -42,7 +42,7 @@ describe("useAnimatedNumber", () => {
reduced.value = false;
const source = ref<number | null>(0);
const scope = effectScope();
const seen: (number | null)[] = [];
const seen: (string | number | null)[] = [];
let display!: ReturnType<typeof useAnimatedNumber>;
scope.run(() => {
display = useAnimatedNumber(() => source.value, { duration: 60 });

View File

@@ -9,6 +9,9 @@
import { onScopeDispose, ref, watch, type Ref } from "vue";
import { useReducedMotion } from "@/v2/composables/useReducedMotion";
import { motion } from "@/v2/tokens";
import { tween } from "@/v2/utils/tween";
type Source = string | number | null | undefined;
interface Options {
/** Roll duration in ms. Defaults to the `slow` motion token. */
@@ -17,59 +20,53 @@ interface Options {
decimals?: number;
}
/**
* Follows `source`, rolling through the numbers on the way. Anything already
* formatted (a size, a date, a range) passes straight through, so a caller
* can hand over a value it doesn't have to classify first.
*/
export function useAnimatedNumber(
source: () => number | null | undefined,
source: () => Source,
options: Options = {},
): Ref<number | null> {
): Ref<string | number | null> {
const { enabled: reducedMotion } = useReducedMotion();
const duration = options.duration ?? parseInt(motion.slow, 10);
const decimals = options.decimals ?? 0;
const display = ref<number | null>(null);
let frame: number | null = null;
const display = ref<string | number | null>(null);
let cancel: (() => void) | null = null;
function stop() {
if (frame !== null) cancelAnimationFrame(frame);
frame = null;
}
function animate(from: number, to: number) {
if (duration <= 0 || reducedMotion.value) {
display.value = to;
return;
}
// Paint the starting value now: the first frame is a whole render away,
// and in a background tab it never comes at all.
display.value = from;
const start = performance.now();
const step = (now: number) => {
const t = Math.min(1, (now - start) / duration);
const eased = 1 - (1 - t) ** 3;
// Rounding is cosmetic, for the frames in between: a raw tween value
// like 1567.4972637 would paint in full and widen the layout mid-roll.
display.value =
t < 1 ? Number((from + (to - from) * eased).toFixed(decimals)) : to;
frame = t < 1 ? requestAnimationFrame(step) : null;
};
frame = requestAnimationFrame(step);
cancel?.();
cancel = null;
}
watch(
source,
(target) => {
stop();
// A missing value is a dash at the call site, not a number to roll to.
if (target == null) {
display.value = null;
// Nothing to roll through: a missing value is a dash at the call site,
// and a formatted one is already what the caller wants painted.
if (target == null || typeof target === "string") {
display.value = target ?? null;
return;
}
// The first value rolls up from zero, which is the whole point of the
// effect: a count that arrives is a count you watch land.
const from = display.value ?? 0;
const from = typeof display.value === "number" ? display.value : 0;
if (from === target) {
display.value = target;
return;
}
animate(from, target);
cancel = tween({
from,
to: target,
durationMs: reducedMotion.value ? 0 : duration,
// Rounding is cosmetic, for the frames in between: a raw tween value
// like 1567.4972637 would paint in full and widen the layout mid-roll.
onUpdate: (value) => (display.value = Number(value.toFixed(decimals))),
// The value it lands on is the caller's, decimals and all.
onDone: () => (display.value = target),
});
},
{ immediate: true },
);

View File

@@ -15,13 +15,10 @@ import {
listRowHeight,
} from "@/v2/components/Gallery/listColumns";
import { useReducedMotion } from "@/v2/composables/useReducedMotion";
import { motion } from "@/v2/tokens";
import { tween } from "@/v2/utils/tween";
/** Matches `--r-motion-med`, the duration the rest of v2 opens things at. */
const DURATION_MS = 220;
function easeOut(t: number): number {
return 1 - (1 - t) ** 3;
}
const DURATION_MS = parseInt(motion.med, 10);
export function useListExpansion() {
const { enabled: reducedMotion } = useReducedMotion();
@@ -30,33 +27,22 @@ export function useListExpansion() {
/** How much of the panel is currently showing, in px. */
const openHeight = ref(0);
let frame: number | null = null;
let cancelAnimation: (() => void) | null = null;
function stopAnimation() {
if (frame !== null) cancelAnimationFrame(frame);
frame = null;
cancelAnimation?.();
cancelAnimation = null;
}
function animateTo(target: number, onDone?: () => void) {
stopAnimation();
if (reducedMotion.value) {
openHeight.value = target;
onDone?.();
return;
}
const from = openHeight.value;
const start = performance.now();
const step = (now: number) => {
const t = Math.min(1, (now - start) / DURATION_MS);
openHeight.value = from + (target - from) * easeOut(t);
if (t < 1) {
frame = requestAnimationFrame(step);
return;
}
frame = null;
onDone?.();
};
frame = requestAnimationFrame(step);
cancelAnimation = tween({
from: openHeight.value,
to: target,
durationMs: reducedMotion.value ? 0 : DURATION_MS,
onUpdate: (value) => (openHeight.value = value),
onDone,
});
}
function isExpanded(position: number | null | undefined): boolean {
@@ -92,7 +78,6 @@ export function useListExpansion() {
onScopeDispose(stopAnimation);
return {
expandedPosition,
isExpanded,
detailHeight,
toggle,

View File

@@ -365,6 +365,41 @@ html.r-v2-reduced-motion {
pointer-events: none;
}
/* Compact list rows (phones and tablets): the anatomy the gallery, the
platforms and collections indexes and the loading placeholder all share.
Per-surface deltas (a row's height and border, a clamped title) stay in the
component. */
.r-list-compact {
display: flex;
align-items: center;
gap: var(--r-space-3);
padding: 0 var(--r-row-pad);
}
.r-list-compact__stack {
display: flex;
flex-direction: column;
justify-content: center;
gap: 3px;
flex: 1;
min-width: 0;
}
.r-list-compact__facts {
display: flex;
align-items: center;
gap: 5px;
font-size: var(--r-font-size-sm);
color: var(--r-color-fg-muted);
min-width: 0;
}
.r-list-compact__facts > span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.r-list-compact__dot {
color: var(--r-color-fg-faint);
}
/* Column both gallery Settings tabs (platform, collection) render in, so they
share one width. */
.r-settings-column {

View File

@@ -158,6 +158,7 @@
--r-alpha-strip-w: 24px;
--r-list-row-h: 80px;
--r-list-header-h: 40px;
--r-list-select-w: 36px;
--r-list-row-detail-h: 226px;
--r-z-drawer: 2300;
--r-z-dialog: 2400;

View File

@@ -462,6 +462,8 @@ export const layout = {
// `<GameCard size="xs" />` — no dedicated list-cover token.)
listRowHeight: "80px",
listHeaderHeight: "40px",
// The row's leading tick column, narrower on phones (see global.css).
listSelectWidth: "36px",
// Height of a list row's expanded detail panel on phones and tablets,
// where the row collapses to two lines and the columns move in here.
// Fixed so the virtualiser can offset the rows below it exactly.

View File

@@ -0,0 +1,57 @@
// A minimal ease-out tween over requestAnimationFrame, shared by the two
// places that animate a number Vue renders (a rolling count, a panel's
// height). Not a composable: it takes the duration already resolved, so
// reduced motion and the motion tokens stay the caller's business.
function easeOut(t: number): number {
return 1 - (1 - t) ** 3;
}
interface TweenOptions {
from: number;
to: number;
/** 0 lands on `to` synchronously, which is what reduced motion wants. */
durationMs: number;
onUpdate: (value: number) => void;
onDone?: () => void;
}
/** Starts the tween and returns the function that cancels it. */
export function tween({
from,
to,
durationMs,
onUpdate,
onDone,
}: TweenOptions): () => void {
if (durationMs <= 0) {
onUpdate(to);
onDone?.();
return () => {};
}
let frame: number | null = null;
const cancel = () => {
if (frame !== null) cancelAnimationFrame(frame);
frame = null;
};
// Paint the starting value now: the first frame is a whole render away,
// and in a background tab it never comes at all.
onUpdate(from);
const start = performance.now();
const step = (now: number) => {
const t = Math.min(1, (now - start) / durationMs);
if (t < 1) {
onUpdate(from + (to - from) * easeOut(t));
frame = requestAnimationFrame(step);
return;
}
onUpdate(to);
frame = null;
onDone?.();
};
frame = requestAnimationFrame(step);
return cancel;
}