feat(frontend-v2): add RVirtualScroller primitive

Wraps Vuetify's VVirtualScroll with the project's wrapper contract
(inheritAttrs: false, $attrs forwarding, slot passthrough). Items
are typed as unknown[] so consumers cast at the call site — making
the primitive non-generic keeps it usable inside Storybook
components: {} registrations, where Vue 3.4 generic components
clash with the Component record type.

Story exercises a 5000-row list to verify only the visible window
hits the DOM. Auto-discovered by test/storybook.test.ts.

This primitive is the substrate for the upcoming GameGrid and
LetterGroupedGrid migrations — both will chunk their items into
rows of fixed-width cards and feed those rows here, so libraries
with thousands of ROMs no longer mount thousands of cards at once.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
zurdiandClaude Opus 4.7 committed 2026-04-28 13:21:52 +00:00
1 parent 49d01f65d6
commit 0d2bc1cfa3
4 files changed
+95

No files matched your search

+1
View File
@@ -36,6 +36,7 @@ export * from "./structural/RList";
export * from "./structural/RListItem";
export * from "./structural/RToolbar";
export * from "./structural/RTooltip";
export * from "./structural/RVirtualScroller";
// Menus
export * from "./menus/RMenu";
@@ -0,0 +1,44 @@
import type { Meta, StoryObj } from "@storybook/vue3-vite";
import RVirtualScroller from "./RVirtualScroller.vue";
const meta: Meta<typeof RVirtualScroller> = {
title: "Structural/RVirtualScroller",
component: RVirtualScroller,
argTypes: {
itemHeight: { control: "number" },
height: { control: "text" },
},
};
export default meta;
type Story = StoryObj<typeof RVirtualScroller>;
const longList = Array.from({ length: 5000 }, (_, i) => ({
id: i,
label: `Row ${i + 1}`,
}));
export const FiveThousandRows: Story = {
args: {
items: longList,
itemHeight: 44,
height: 480,
},
render: (args) => ({
components: { RVirtualScroller },
setup: () => ({ args }),
template: `
<div style="width: 320px; border: 1px solid var(--r-color-border); border-radius: var(--r-radius-md); background: var(--r-color-bg-elevated)">
<RVirtualScroller v-bind="args">
<template #default="{ item, index }">
<div style="display:flex;align-items:center;padding:0 var(--r-space-3);height:44px;border-bottom:1px solid var(--r-color-border);font-size:var(--r-font-size-sm);">
<span style="opacity:0.5;width:48px">#{{ index }}</span>
<span>{{ item.label }}</span>
</div>
</template>
</RVirtualScroller>
</div>
`,
}),
};
@@ -0,0 +1,49 @@
<script setup lang="ts">
import { VVirtualScroll } from "vuetify/components/VVirtualScroll";
defineOptions({ inheritAttrs: false });
interface Props {
/** Array of items to render. Only the visible window is in the DOM. */
items: readonly unknown[];
/** Fixed item height in pixels. Required for accurate windowing.
* Pass undefined for dynamic measurement (slower; use only if items vary). */
itemHeight?: number;
/** Viewport height. Numeric is pixels; string accepts any CSS length.
* Omit when the wrapper has its own size and should fill it. */
height?: number | string;
maxHeight?: number | string;
minHeight?: number | string;
/** Render a placeholder slot when items are not in the visible window. */
renderless?: boolean;
}
defineProps<Props>();
defineSlots<{
default(props: { item: unknown; index: number }): unknown;
}>();
</script>
<template>
<VVirtualScroll
v-bind="$attrs"
class="r-virtual-scroller"
:items="items as unknown[]"
:item-height="itemHeight"
:height="height"
:max-height="maxHeight"
:min-height="minHeight"
:renderless="renderless"
>
<template #default="slotProps">
<slot :item="slotProps.item" :index="slotProps.index" />
</template>
</VVirtualScroll>
</template>
<style scoped>
.r-virtual-scroller {
background-color: transparent;
}
</style>
@@ -0,0 +1 @@
export { default as RVirtualScroller } from "./RVirtualScroller.vue";