feat: add tile size prop to collection components for responsive layout

This commit is contained in:
zurdi committed 2026-04-24 23:24:20 +00:00
1 parent c8609dc62d
commit b418df06f5
4 files changed
+68 -14

No files matched your search

+17
View File
@@ -80,6 +80,23 @@ watch(
);
const isV2 = computed(() => uiVersion.value === "v2");
// Apply the v2 token scope to <html> when v2 is active. Vuetify teleports
// overlays (VDialog, VMenu) into `<body> > .v-overlay-container` — which
// sits OUTSIDE both the AppLayout `.r-v2` wrapper AND <v-app>. Putting the
// classes on <html> means the entire document inherits the v2 CSS custom
// properties so `var(--r-color-...)` resolves inside any teleported
// dialog/menu. v1 mode strips the classes, keeping v1 CSS unaffected.
watch(
[isV2, activeThemeName],
([v2, themeName]) => {
const root = document.documentElement;
root.classList.toggle("r-v2", v2);
root.classList.toggle("r-v2-dark", v2 && themeName === V2_THEME_DARK);
root.classList.toggle("r-v2-light", v2 && themeName === V2_THEME_LIGHT);
},
{ immediate: true },
);
</script>
<template>
@@ -4,6 +4,7 @@
// Click toggles; parent owns the pending/checked state and handles the
// API round-trip.
import { RIcon } from "@v2/lib";
import { computed } from "vue";
import CollectionMosaic from "@/v2/components/Collections/CollectionMosaic.vue";
defineOptions({ inheritAttrs: false });
@@ -14,15 +15,24 @@ interface Props {
covers: string[];
checked: boolean;
busy?: boolean;
// Thumb diameter in px. Drives both the grid first-column width and
// the CollectionMosaic width so the label column always lines up with
// the right edge of the thumb.
tileSize?: number;
}
withDefaults(defineProps<Props>(), {
const props = withDefaults(defineProps<Props>(), {
busy: false,
tileSize: 36,
});
defineEmits<{
(e: "toggle"): void;
}>();
const rowStyle = computed(() => ({
"--tile-w": `${props.tileSize}px`,
}));
</script>
<template>
@@ -33,6 +43,7 @@ defineEmits<{
'pick-row--checked': checked,
'pick-row--busy': busy,
}"
:style="rowStyle"
:aria-pressed="checked"
:disabled="busy"
@click="$emit('toggle')"
@@ -41,7 +52,7 @@ defineEmits<{
<span class="pick-row__name">{{ name }}</span>
<span class="pick-row__count">{{ count }}</span>
<span class="pick-row__tick" aria-hidden="true">
<RIcon v-if="checked" icon="mdi-check" size="14" color="primary" />
<RIcon v-if="checked" icon="mdi-check" size="14" />
</span>
</button>
</template>
@@ -53,7 +64,7 @@ defineEmits<{
background: transparent;
border: 0;
display: grid;
grid-template-columns: 36px 1fr auto 26px;
grid-template-columns: var(--tile-w, 36px) 1fr auto 26px;
align-items: center;
gap: 14px;
padding: 8px 30px;
@@ -79,10 +90,10 @@ defineEmits<{
cursor: progress;
}
/* Portrait thumb — width from the first grid column, height from the
CollectionMosaic aspectRatio. */
/* Portrait thumb — width tracks the configurable tile size; height is
computed by CollectionMosaic from its 140/188 aspectRatio. */
.pick-row__thumb {
width: 36px;
width: var(--tile-w, 36px);
}
.pick-row__name {
@@ -7,7 +7,7 @@
// `+` tile and row frame are shared between the two states so the
// expand animation reads as the same surface swapping its contents.
import { RBtn, RIcon } from "@v2/lib";
import { nextTick, ref, watch } from "vue";
import { computed, nextTick, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
defineOptions({ inheritAttrs: false });
@@ -16,9 +16,19 @@ interface Props {
expanded: boolean;
name: string;
creating: boolean;
// Tile diameter in px. Drives both the grid first-column width and the
// plus-tile width so the prepended slot stays flush with the label
// column regardless of size. Match the row's CollectionMosaic thumb.
tileSize?: number;
}
const props = defineProps<Props>();
const props = withDefaults(defineProps<Props>(), {
tileSize: 36,
});
const rowStyle = computed(() => ({
"--tile-w": `${props.tileSize}px`,
}));
const emit = defineEmits<{
(e: "update:expanded", value: boolean): void;
@@ -53,7 +63,13 @@ function onInput(e: Event) {
</script>
<template>
<button v-if="!expanded" type="button" class="new-row" @click="onExpand">
<button
v-if="!expanded"
type="button"
class="new-row"
:style="rowStyle"
@click="onExpand"
>
<span class="new-row__tile">
<RIcon icon="mdi-plus" size="22" />
</span>
@@ -61,7 +77,12 @@ function onInput(e: Event) {
{{ t("collection.new-collection", "New Collection") }}
</span>
</button>
<form v-else class="new-row new-row--editing" @submit.prevent="onSubmit">
<form
v-else
class="new-row new-row--editing"
:style="rowStyle"
@submit.prevent="onSubmit"
>
<span class="new-row__tile new-row__tile--active">
<RIcon icon="mdi-plus" size="22" />
</span>
@@ -81,7 +102,7 @@ function onInput(e: Event) {
<div class="new-row__actions">
<RBtn
variant="text"
size="x-small"
size="small"
:disabled="creating"
@click.prevent="onCancel"
>
@@ -90,7 +111,7 @@ function onInput(e: Event) {
<RBtn
variant="tonal"
color="primary"
size="x-small"
size="small"
type="submit"
:disabled="!name.trim() || creating"
:loading="creating"
@@ -107,7 +128,9 @@ function onInput(e: Event) {
.new-row {
appearance: none;
display: grid;
grid-template-columns: 36px 1fr auto;
/* First column tracks the configurable tile width so the label always
starts past the tile, even when the consumer makes the tile bigger. */
grid-template-columns: var(--tile-w, 36px) 1fr auto;
align-items: center;
gap: 14px;
width: calc(100% + 36px);
@@ -133,9 +156,10 @@ function onInput(e: Event) {
picker rows so the first column aligns whether you're looking at the
CTA or an existing collection thumb. */
.new-row__tile {
width: 36px;
width: var(--tile-w, 36px);
aspect-ratio: 140 / 188;
border-radius: 6px;
border: 1px solid var(--r-color-brand-primary);
background: rgba(139, 116, 232, 0.16);
color: var(--r-color-brand-primary);
display: grid;
@@ -217,6 +217,7 @@ function closeDialog() {
v-model:expanded="createExpanded"
v-model:name="newName"
:creating="creating"
:tile-size="46"
@create="createNewCollection"
@cancel="cancelCreate"
/>
@@ -232,6 +233,7 @@ function closeDialog() {
:covers="coversFor(collection)"
:checked="isChecked(collection)"
:busy="pendingCollections.has(collection.id)"
:tile-size="46"
@toggle="toggle(collection)"
/>
</li>