mirror of
https://github.com/rommapp/romm.git
synced 2026-12-05 05:07:31 +01:00
fix(v2): code-review pass on storybook viewport presets
Drop the manual data-bp pin in RTable MobileCardStack (it now uses the phone viewport global), give each RomM preset its own tier, remove the no-op install from storybook.test.ts, and correct the related docs. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -48,7 +48,7 @@ When a dialog opens, push a scope; when it closes, pop. This stops Escape from c
|
||||
|
||||
## Responsive layout (universal viewport)
|
||||
|
||||
- **Single breakpoint source: `useBreakpoint`** (`src/v2/composables/useBreakpoint/`). Material thresholds — `xs <600`, `sm 600–959`, `md 960–1279`, `lg 1280–1919`, `xl ≥1920`. `installBreakpointAttribute()` mirrors the active set onto `<html data-bp="…">` (once from `AppLayout` and `AuthLayout` in the app; also from `.storybook/preview.ts` and `frontend/test/storybook.test.ts` so Storybook and composed-story tests match production CSS).
|
||||
- **Single breakpoint source: `useBreakpoint`** (`src/v2/composables/useBreakpoint/`). Material thresholds: `xs <600`, `sm 600–959`, `md 960–1279`, `lg 1280–1919`, `xl ≥1920`. `installBreakpointAttribute()` mirrors the active set onto `<html data-bp="…">` (from `AppLayout` and `AuthLayout` in the app, and from `.storybook/preview.ts` so stories match production CSS).
|
||||
- **Layout switches live in CSS** via the attribute selector: `html[data-bp~="xs"] .foo { … }`, `html[data-bp~="sm-and-down"] .foo { … }`. **No raw `@media` for layout** — the only allowed `@media` are `prefers-reduced-motion` and print. The attribute is on `<html>` so it reaches teleported overlays.
|
||||
- **Conditional rendering** (mount/unmount a different component per tier) uses the `useBreakpoint()` refs in `<script>` — e.g. `v-if="xs"`. Prefer mount-gating over `display:none` for focusable chrome so hidden controls never sit in the tab/spatial-nav order.
|
||||
- **`--r-row-pad` is the global horizontal gutter**, already re-scoped responsive in `global.css` (36 → 20 → 14px). Consume `var(--r-row-pad)`; don't hard-code a smaller `xs` padding per component.
|
||||
@@ -57,4 +57,4 @@ When a dialog opens, push a scope; when it closes, pop. This stops Escape from c
|
||||
- **Label→icon collapse** (the AppNav precedent) is the canonical way to compress chrome; the four primary destinations relocate to `BottomNav` on `sm-and-down`.
|
||||
- **Grids** size via `useResponsiveColumns` (ResizeObserver), never a fixed column count.
|
||||
|
||||
Verification adds a breakpoint sweep; see `review-polish`. In Storybook, use the viewport toolbar presets in `.storybook/rommViewports.ts` (RomM tiers plus AYN Thor top/bottom screens, landscape). Layout that depends on `html[data-bp~="xs"]` needs a canvas **under 600px** wide (e.g. **390×844 · RomM phone**), not just `useBreakpoint()` switching subtabs at tablet widths.
|
||||
Verification adds a breakpoint sweep; see `review-polish`. In Storybook, use the viewport toolbar presets in `.storybook/rommViewports.ts` (RomM xs/sm/md tiers, Steam Deck for lg, AYN Thor top/bottom screens). A story that needs a tier sets `globals: { viewport: { value: "rommPhoneXs" } }` instead of writing `data-bp` itself. Layout that depends on `html[data-bp~="xs"]` needs a canvas **under 600px** wide (e.g. **390×844 · RomM phone**), not just `useBreakpoint()` switching subtabs at tablet widths.
|
||||
|
||||
@@ -1,44 +1,39 @@
|
||||
import { MINIMAL_VIEWPORTS, type ViewportMap } from "storybook/viewport";
|
||||
|
||||
/**
|
||||
* RomM v2 breakpoints match useBreakpoint (xs <600, sm-and-down ≤959.98, md ≥960).
|
||||
* CSS that targets html[data-bp~="xs"] only applies when the iframe is under 600px wide
|
||||
* (RomM phone preset, or Storybook Small mobile at 320×568).
|
||||
*/
|
||||
export const ROMM_DEVICE_VIEWPORTS = {
|
||||
/** One preset per useBreakpoint tier (xs <600, sm <960, md <1280), plus handhelds. */
|
||||
const ROMM_DEVICE_VIEWPORTS = {
|
||||
rommPhoneXs: {
|
||||
name: "390×844 · RomM phone (xs, <600)",
|
||||
styles: { width: "390px", height: "844px" },
|
||||
type: "mobile",
|
||||
},
|
||||
rommTabletSm: {
|
||||
name: "768×1024 · RomM tablet (sm-and-down, <960)",
|
||||
name: "768×1024 · RomM tablet (sm, 600–959)",
|
||||
styles: { width: "768px", height: "1024px" },
|
||||
type: "tablet",
|
||||
},
|
||||
rommDesktopMd: {
|
||||
name: "1280×800 · RomM desktop (md+, ≥960)",
|
||||
styles: { width: "1280px", height: "800px" },
|
||||
name: "1024×768 · RomM desktop (md, 960–1279)",
|
||||
styles: { width: "1024px", height: "768px" },
|
||||
type: "desktop",
|
||||
},
|
||||
steamDeck: {
|
||||
name: "1280×800 · Steam Deck (landscape)",
|
||||
name: "1280×800 · Steam Deck (lg, landscape)",
|
||||
styles: { width: "1280px", height: "800px" },
|
||||
type: "other",
|
||||
},
|
||||
aynThorTop: {
|
||||
name: "1920×1080 · AYN Thor top screen (landscape)",
|
||||
name: "1920×1080 · AYN Thor top screen (xl, landscape)",
|
||||
styles: { width: "1920px", height: "1080px" },
|
||||
type: "other",
|
||||
},
|
||||
aynThorBottom: {
|
||||
name: "1240×1080 · AYN Thor bottom screen (landscape)",
|
||||
name: "1240×1080 · AYN Thor bottom screen (md, landscape)",
|
||||
styles: { width: "1240px", height: "1080px" },
|
||||
type: "other",
|
||||
},
|
||||
} as const satisfies ViewportMap;
|
||||
} satisfies ViewportMap;
|
||||
|
||||
/** Storybook minimal presets plus RomM tiers, Steam Deck, and AYN Thor screens. */
|
||||
export const ROMM_STORYBOOK_VIEWPORTS: ViewportMap = {
|
||||
...MINIMAL_VIEWPORTS,
|
||||
...ROMM_DEVICE_VIEWPORTS,
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
// Module-level singletons — the media query listeners attach once and
|
||||
// every consumer shares them. Composable returns the refs by name.
|
||||
//
|
||||
// `installBreakpointAttribute()` (called once from the root layout)
|
||||
// mirrors the active breakpoints onto `data-bp` on `<html>` as a
|
||||
// `installBreakpointAttribute()` (called from the root layouts and the
|
||||
// Storybook preview) mirrors the active breakpoints onto `data-bp` on `<html>` as a
|
||||
// space-separated list — e.g. `data-bp="sm-and-up md-and-up"` at a
|
||||
// 1024px viewport. CSS consumes the attribute with `~=` selectors:
|
||||
// html[data-bp~="xs"] .my-class { … } // mobile only
|
||||
@@ -89,8 +89,7 @@ function applyAttribute() {
|
||||
* Called from every top-level layout (AppLayout AND AuthLayout) so the
|
||||
* attribute is present across the whole app, including the auth / setup
|
||||
* flow — otherwise the `html[data-bp~="…"]` rules silently no-op there.
|
||||
* Storybook and `frontend/test/storybook.test.ts` call this too so iframe
|
||||
* stories honor the same `html[data-bp~="…"]` CSS as the running app.
|
||||
* `.storybook/preview.ts` calls it too so stories get the same CSS.
|
||||
*
|
||||
* The watcher runs in a DETACHED effect scope, not bound to the calling
|
||||
* component, so it survives a layout swap (AuthLayout ↔ AppLayout) instead
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { onBeforeUnmount, onMounted } from "vue";
|
||||
import RTable from "./RTable.vue";
|
||||
import type { RTableColumn } from "./types";
|
||||
|
||||
@@ -152,12 +151,12 @@ export const Empty: Story = {
|
||||
}),
|
||||
};
|
||||
|
||||
// Mobile card-stack — on `xs` each row reflows into a stacked card with the
|
||||
// column label as a per-cell caption (no `minWidth` set). The reflow keys off
|
||||
// `<html data-bp~="xs">`, which Storybook doesn't install, so this story pins
|
||||
// the attribute for its lifetime and restores it on teardown. Framed at a
|
||||
// phone-ish width to mirror the real viewport.
|
||||
// Mobile card-stack: on `xs` each row reflows into a stacked card with the
|
||||
// column label as a per-cell caption. The reflow keys off `html[data-bp~="xs"]`,
|
||||
// so the story opens on the phone viewport preset.
|
||||
export const MobileCardStack: Story = {
|
||||
globals: { viewport: { value: "rommPhoneXs", isRotated: false } },
|
||||
parameters: { layout: "fullscreen" },
|
||||
args: {
|
||||
columns: COLUMNS,
|
||||
items: ITEMS,
|
||||
@@ -167,22 +166,9 @@ export const MobileCardStack: Story = {
|
||||
},
|
||||
render: (args) => ({
|
||||
components: { RTable },
|
||||
setup: () => {
|
||||
const prev = document.documentElement.dataset.bp;
|
||||
onMounted(() => {
|
||||
document.documentElement.dataset.bp = "xs sm-and-down md-and-down";
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
if (prev === undefined) delete document.documentElement.dataset.bp;
|
||||
else document.documentElement.dataset.bp = prev;
|
||||
});
|
||||
return { args };
|
||||
},
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div
|
||||
class="r-v2 r-v2-dark"
|
||||
style="padding: 24px; width: 380px; background: #07070f;"
|
||||
>
|
||||
<div class="r-v2 r-v2-dark" style="padding: 24px; background: #07070f;">
|
||||
<RTable v-bind="args" />
|
||||
</div>
|
||||
`,
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { composeStories } from "@storybook/vue3-vite";
|
||||
import axe from "axe-core";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { installBreakpointAttribute } from "@/v2/composables/useBreakpoint";
|
||||
|
||||
// Match `.storybook/preview.ts` so responsive CSS keyed on html[data-bp] applies in happy-dom.
|
||||
installBreakpointAttribute();
|
||||
|
||||
type StoryModule = Record<string, unknown>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user