mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 02:24:09 +01:00
feat: Refactor RList and RListItem components for improved accessibility and styling
- Enhanced RList component to provide a semantic outer wrapper for list items, supporting custom properties for density, color, and background color. - Updated RListItem to support polymorphic behavior with dynamic rendering based on props (to, href, click handlers). - Introduced new styling for RList and RListItem, including density variations and improved hover/active states. - Modified RToolbar to allow for customizable height, color, and rounded corners, enhancing its usability in various contexts. - Updated storybook examples for RList, RListItem, and RToolbar to demonstrate new features and styling options. - Changed button variants from 'tonal' to 'translucent' in various components for a more consistent design language.
This commit is contained in:
@@ -51,6 +51,25 @@ const preview: Preview = {
|
||||
date: /Date$/i,
|
||||
},
|
||||
},
|
||||
// Sidebar order: build up from atoms to compound surfaces. Primitives
|
||||
// are the foundation everything else composes from, then form
|
||||
// controls, structural layout pieces, data displays, and finally
|
||||
// positioned UI (menus + overlays). Media (domain-aware icons) is
|
||||
// last because it's the most specialised. Categories not listed
|
||||
// here fall through to Storybook's default alphabetical sort.
|
||||
options: {
|
||||
storySort: {
|
||||
order: [
|
||||
"Primitives",
|
||||
"Forms",
|
||||
"Structural",
|
||||
"Data",
|
||||
"Menus",
|
||||
"Overlays",
|
||||
"Media",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
decorators: [
|
||||
withThemeByClassName({
|
||||
|
||||
@@ -109,7 +109,7 @@ function onInput(e: Event) {
|
||||
{{ t("common.cancel") }}
|
||||
</RBtn>
|
||||
<RBtn
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
color="primary"
|
||||
size="small"
|
||||
type="submit"
|
||||
|
||||
@@ -118,7 +118,7 @@ function closeDialog() {
|
||||
</RBtn>
|
||||
<div style="flex: 1" />
|
||||
<RBtn
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
color="error"
|
||||
prepend-icon="mdi-delete"
|
||||
:loading="deleting"
|
||||
|
||||
@@ -239,7 +239,7 @@ function closeDialog() {
|
||||
</RBtn>
|
||||
<div style="flex: 1" />
|
||||
<RBtn
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
color="error"
|
||||
prepend-icon="mdi-delete"
|
||||
:loading="deleting"
|
||||
|
||||
@@ -526,7 +526,7 @@ function handleRomUpdateFromMetadata(updatedRom: UpdateRom) {
|
||||
</RBtn>
|
||||
<div style="flex: 1" />
|
||||
<RBtn
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
color="primary"
|
||||
prepend-icon="mdi-check"
|
||||
:disabled="!validForm"
|
||||
|
||||
@@ -511,7 +511,7 @@ function closeDialog() {
|
||||
<div style="flex: 1" />
|
||||
<RBtn
|
||||
v-if="showSelectSource"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
color="primary"
|
||||
prepend-icon="mdi-check"
|
||||
:disabled="!selectedMatchRom"
|
||||
|
||||
@@ -243,7 +243,7 @@ function closeDialog() {
|
||||
</RBtn>
|
||||
<div style="flex: 1" />
|
||||
<RBtn
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
color="primary"
|
||||
prepend-icon="mdi-magnify-scan"
|
||||
:disabled="metadataSources.length === 0"
|
||||
|
||||
@@ -215,7 +215,7 @@ onBeforeUnmount(() => {
|
||||
v-for="l in rom.languages?.slice(0, 3) ?? []"
|
||||
:key="`lang-${l}`"
|
||||
size="x-small"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
>
|
||||
{{ l }}
|
||||
</RChip>
|
||||
@@ -227,7 +227,7 @@ onBeforeUnmount(() => {
|
||||
v-for="r in rom.regions?.slice(0, 3) ?? []"
|
||||
:key="`reg-${r}`"
|
||||
size="x-small"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
>
|
||||
{{ r }}
|
||||
</RChip>
|
||||
|
||||
@@ -160,7 +160,6 @@ const morphStyle = computed(() => {
|
||||
icon
|
||||
size="x-small"
|
||||
variant="text"
|
||||
:ripple="false"
|
||||
class="r-gc__platform-icon"
|
||||
:aria-label="`Browse ${platformShort}`"
|
||||
@click="onPlatformClick"
|
||||
|
||||
@@ -369,7 +369,7 @@ function seekValueText(v: number): string {
|
||||
v-for="(c, i) in headerChips(activeMeta)"
|
||||
:key="`h-${i}`"
|
||||
size="small"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
:color="c.color"
|
||||
:prepend-icon="c.icon"
|
||||
>
|
||||
@@ -490,7 +490,7 @@ function seekValueText(v: number): string {
|
||||
v-for="(c, i) in rowChips(track.id)"
|
||||
:key="`r-${track.id}-${i}`"
|
||||
size="x-small"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
:color="c.color"
|
||||
:prepend-icon="c.icon"
|
||||
>
|
||||
|
||||
@@ -158,7 +158,7 @@ onBeforeUnmount(() => {
|
||||
<RBtn
|
||||
v-if="canLeft"
|
||||
icon="mdi-chevron-left"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
class="card-row__arrow card-row__arrow--left"
|
||||
aria-label="Scroll left"
|
||||
@click="scrollBy(-1)"
|
||||
@@ -166,7 +166,7 @@ onBeforeUnmount(() => {
|
||||
<RBtn
|
||||
v-if="canRight"
|
||||
icon="mdi-chevron-right"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
class="card-row__arrow card-row__arrow--right"
|
||||
aria-label="Scroll right"
|
||||
@click="scrollBy(1)"
|
||||
|
||||
@@ -64,7 +64,7 @@ function closeDialog() {
|
||||
</RBtn>
|
||||
<div style="flex: 1" />
|
||||
<RBtn
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
color="error"
|
||||
prepend-icon="mdi-database-remove"
|
||||
@click="clearIndexDB"
|
||||
|
||||
@@ -39,7 +39,7 @@ const scopeCount = computed(() => {
|
||||
<template #activator="{ props: menuProps }">
|
||||
<RBtn
|
||||
v-bind="menuProps"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
size="small"
|
||||
border
|
||||
class="r-v2-scope-cell__chip"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { ref } from "vue";
|
||||
import { computed, ref } from "vue";
|
||||
import RCheckbox from "./RCheckbox.vue";
|
||||
|
||||
const meta: Meta<typeof RCheckbox> = {
|
||||
@@ -7,13 +7,24 @@ const meta: Meta<typeof RCheckbox> = {
|
||||
component: RCheckbox,
|
||||
argTypes: {
|
||||
label: { control: "text" },
|
||||
size: { control: "inline-radio", options: ["sm", "md"] },
|
||||
density: {
|
||||
control: "select",
|
||||
options: ["default", "comfortable", "compact"],
|
||||
subtitle: { control: "text" },
|
||||
size: {
|
||||
control: "inline-radio",
|
||||
options: ["xs", "sm", "md", "lg"],
|
||||
},
|
||||
shape: {
|
||||
control: "inline-radio",
|
||||
options: ["square", "rounded", "circle"],
|
||||
},
|
||||
color: { control: "text" },
|
||||
variant: {
|
||||
control: "inline-radio",
|
||||
options: ["box", "card"],
|
||||
},
|
||||
disabled: { control: "boolean" },
|
||||
indeterminate: { control: "boolean" },
|
||||
error: { control: "boolean" },
|
||||
errorMessages: { control: "text" },
|
||||
},
|
||||
render: (args) => ({
|
||||
components: { RCheckbox },
|
||||
@@ -29,11 +40,14 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RCheckbox>;
|
||||
|
||||
// ── Defaults ────────────────────────────────────────────────────────
|
||||
|
||||
export const Default: Story = {
|
||||
args: { label: "Remember me" },
|
||||
};
|
||||
|
||||
export const Checked: Story = {
|
||||
args: { label: "Auto-login next time" },
|
||||
render: (args) => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
@@ -42,18 +56,101 @@ export const Checked: Story = {
|
||||
},
|
||||
template: `<RCheckbox v-model="value" v-bind="args" />`,
|
||||
}),
|
||||
args: { label: "Auto-login next time" },
|
||||
};
|
||||
|
||||
export const Indeterminate: Story = {
|
||||
args: { label: "Some items selected", indeterminate: true },
|
||||
};
|
||||
|
||||
export const NoLabel: Story = { args: {} };
|
||||
|
||||
// ── Sizes ───────────────────────────────────────────────────────────
|
||||
|
||||
export const SizeLadder: Story = {
|
||||
name: "Size ladder (xs / sm / md / lg)",
|
||||
render: () => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
const xs = ref(true);
|
||||
const sm = ref(true);
|
||||
const md = ref(true);
|
||||
const lg = ref(true);
|
||||
return { xs, sm, md, lg };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:10px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RCheckbox v-model="xs" size="xs" label="xs — 12 px" />
|
||||
<RCheckbox v-model="sm" size="sm" label="sm — 16 px" />
|
||||
<RCheckbox v-model="md" size="md" label="md — 18 px (default)" />
|
||||
<RCheckbox v-model="lg" size="lg" label="lg — 22 px" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Shapes ──────────────────────────────────────────────────────────
|
||||
|
||||
export const ShapeLadder: Story = {
|
||||
name: "Shape ladder (square / rounded / circle)",
|
||||
render: () => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
const a = ref(true);
|
||||
const b = ref(true);
|
||||
const c = ref(true);
|
||||
return { a, b, c };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:10px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RCheckbox v-model="a" shape="square" label="square (default · 4 px radius)" />
|
||||
<RCheckbox v-model="b" shape="rounded" label="rounded (8 px radius)" />
|
||||
<RCheckbox v-model="c" shape="circle" label="circle (50% — radio-button look)" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Colors ──────────────────────────────────────────────────────────
|
||||
|
||||
export const ColorLadder: Story = {
|
||||
name: "Color ladder",
|
||||
render: () => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
const states = ref([
|
||||
{ color: "primary", label: "primary (default)", checked: true },
|
||||
{ color: "secondary", label: "secondary", checked: true },
|
||||
{ color: "accent", label: "accent", checked: true },
|
||||
{ color: "success", label: "success", checked: true },
|
||||
{ color: "warning", label: "warning", checked: true },
|
||||
{ color: "danger", label: "danger", checked: true },
|
||||
{ color: "info", label: "info", checked: true },
|
||||
{ color: "romm-gold", label: "romm-gold (legacy)", checked: true },
|
||||
]);
|
||||
return { states };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:10px">
|
||||
<RCheckbox
|
||||
v-for="s in states"
|
||||
:key="s.color"
|
||||
v-model="s.checked"
|
||||
:color="s.color"
|
||||
:label="s.label"
|
||||
/>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── States ──────────────────────────────────────────────────────────
|
||||
|
||||
export const Disabled: Story = {
|
||||
args: { label: "Disabled checkbox", disabled: true },
|
||||
};
|
||||
|
||||
export const DisabledChecked: Story = {
|
||||
args: { label: "Disabled and checked", disabled: true },
|
||||
render: (args) => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
@@ -62,18 +159,10 @@ export const DisabledChecked: Story = {
|
||||
},
|
||||
template: `<RCheckbox v-model="value" v-bind="args" />`,
|
||||
}),
|
||||
args: { label: "Disabled and checked", disabled: true },
|
||||
};
|
||||
|
||||
export const Small: Story = {
|
||||
args: { label: "Small checkbox", size: "sm" },
|
||||
};
|
||||
|
||||
export const NoLabel: Story = {
|
||||
args: {},
|
||||
};
|
||||
|
||||
export const Error: Story = {
|
||||
args: { label: "I agree to the terms" },
|
||||
render: (args) => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
@@ -82,9 +171,114 @@ export const Error: Story = {
|
||||
},
|
||||
template: `<RCheckbox v-model="value" v-bind="args" :error="true" error-messages="This field is required" />`,
|
||||
}),
|
||||
args: { label: "I agree to the terms" },
|
||||
};
|
||||
|
||||
// ── Subtitle ────────────────────────────────────────────────────────
|
||||
|
||||
export const WithSubtitle: Story = {
|
||||
name: "With subtitle",
|
||||
args: {
|
||||
label: "Send weekly digest",
|
||||
subtitle: "We'll email you a Friday recap of new ROMs and scans.",
|
||||
},
|
||||
render: (args) => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
const value = ref(false);
|
||||
return { args, value };
|
||||
},
|
||||
template: `<RCheckbox v-model="value" v-bind="args" />`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Card variant ────────────────────────────────────────────────────
|
||||
|
||||
export const CardVariant: Story = {
|
||||
name: "Card variant",
|
||||
render: () => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
const a = ref(true);
|
||||
const b = ref(false);
|
||||
const c = ref(false);
|
||||
return { a, b, c };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:10px;width:360px">
|
||||
<RCheckbox
|
||||
v-model="a"
|
||||
variant="card"
|
||||
label="Copy token to clipboard"
|
||||
subtitle="Shown once — keep it safe."
|
||||
/>
|
||||
<RCheckbox
|
||||
v-model="b"
|
||||
variant="card"
|
||||
label="Pair device"
|
||||
subtitle="Scan a QR code with your phone."
|
||||
/>
|
||||
<RCheckbox
|
||||
v-model="c"
|
||||
variant="card"
|
||||
label="Email me the link"
|
||||
subtitle="Sent to your registered address."
|
||||
/>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const CardVariantColored: Story = {
|
||||
name: "Card variant · success tone",
|
||||
render: () => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
const a = ref(true);
|
||||
const b = ref(false);
|
||||
return { a, b };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:10px;width:360px">
|
||||
<RCheckbox
|
||||
v-model="a"
|
||||
variant="card"
|
||||
color="success"
|
||||
label="Verified email"
|
||||
subtitle="Required to recover your account."
|
||||
/>
|
||||
<RCheckbox
|
||||
v-model="b"
|
||||
variant="card"
|
||||
color="success"
|
||||
label="Two-factor enabled"
|
||||
subtitle="Adds a one-time code at sign-in."
|
||||
/>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Motion ──────────────────────────────────────────────────────────
|
||||
|
||||
export const Toggle: Story = {
|
||||
name: "Toggle animation",
|
||||
render: () => ({
|
||||
components: { RCheckbox },
|
||||
setup: () => {
|
||||
const value = ref(false);
|
||||
return { value };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;align-items:flex-start;gap:14px;font:12px/1.4 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RCheckbox v-model="value" label="Click me — watch the glyph spring in" />
|
||||
<span>The check icon scales 0 → 1 with the same RSwitch overshoot easing.</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Group ───────────────────────────────────────────────────────────
|
||||
|
||||
export const Group: Story = {
|
||||
render: () => ({
|
||||
components: { RCheckbox },
|
||||
@@ -95,7 +289,7 @@ export const Group: Story = {
|
||||
return { a, b, c };
|
||||
},
|
||||
template: `
|
||||
<div style="display: flex; flex-direction: column; gap: 4px;">
|
||||
<div style="display:flex;flex-direction:column;gap:4px">
|
||||
<RCheckbox v-model="a" label="Option A" hide-details />
|
||||
<RCheckbox v-model="b" label="Option B" hide-details />
|
||||
<RCheckbox v-model="c" label="Option C (longer label that wraps to test alignment)" hide-details />
|
||||
@@ -103,3 +297,54 @@ export const Group: Story = {
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world — "select all" indeterminate ─────────────────────────
|
||||
|
||||
export const SelectAll: Story = {
|
||||
name: "Select-all (indeterminate header)",
|
||||
render: () => ({
|
||||
components: { RCheckbox },
|
||||
setup() {
|
||||
const items = ref([
|
||||
{ id: 1, name: "platforms.read", checked: true },
|
||||
{ id: 2, name: "platforms.write", checked: false },
|
||||
{ id: 3, name: "roms.read", checked: true },
|
||||
{ id: 4, name: "roms.write", checked: false },
|
||||
{ id: 5, name: "users.read", checked: false },
|
||||
]);
|
||||
|
||||
const allChecked = computed(() => items.value.every((i) => i.checked));
|
||||
const anyChecked = computed(() => items.value.some((i) => i.checked));
|
||||
const headerIndeterminate = computed(
|
||||
() => anyChecked.value && !allChecked.value,
|
||||
);
|
||||
|
||||
function toggleAll(v: boolean) {
|
||||
items.value.forEach((i) => {
|
||||
i.checked = v;
|
||||
});
|
||||
}
|
||||
|
||||
return { items, allChecked, headerIndeterminate, toggleAll };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:8px;width:320px;padding:16px;background:var(--r-color-bg-elevated);border:1px solid var(--r-color-border);border-radius:10px">
|
||||
<RCheckbox
|
||||
:model-value="allChecked"
|
||||
:indeterminate="headerIndeterminate"
|
||||
label="Select all scopes"
|
||||
hide-details
|
||||
@update:model-value="toggleAll"
|
||||
/>
|
||||
<div style="height:1px;background:var(--r-color-border);margin:4px 0"></div>
|
||||
<RCheckbox
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
v-model="item.checked"
|
||||
:label="item.name"
|
||||
hide-details
|
||||
/>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,206 +1,555 @@
|
||||
<script setup lang="ts">
|
||||
// RCheckbox — wraps v-checkbox with the v2 visual language: a small
|
||||
// rounded square that fills with brand-primary on check, with a white
|
||||
// tick on top. The 36×36 click target is preserved (good for touch and
|
||||
// pad); the 18×18 visible box is drawn as a pseudo-element so the hit
|
||||
// area never shrinks below comfortable.
|
||||
// RCheckbox — Vuetify-free. Native `<input type="checkbox">` hidden
|
||||
// inside a `<label>` so the whole row is the click target — no
|
||||
// "ghost tap area" around the box needed. The visible box renders at
|
||||
// its true size and the `gap` between box and label reads as a real
|
||||
// margin, not a centring artefact.
|
||||
//
|
||||
// Indeterminate renders mdi-minus; error tints the box with --r-color-danger.
|
||||
// Focus is modality-gated (visible only on key/pad).
|
||||
import { VCheckbox } from "vuetify/components/VCheckbox";
|
||||
// Variants:
|
||||
// • `size` — `xs / sm / md / lg` ladder driven by CSS vars.
|
||||
// • `shape` — `square / rounded / circle` (overrides the radius).
|
||||
// • `color` — TONE_MAP across the lib; drives the check fill +
|
||||
// active border + ring.
|
||||
// • `variant` — `box` (default) or `card`. Card wraps box + body
|
||||
// in a bordered surface that flips to a brand-tinted background
|
||||
// when checked. Designed for "pick one" choices with subtitles.
|
||||
//
|
||||
// `subtitle` lives under the label in the body — handy in card
|
||||
// variant, optional in box variant. Slots `#default` (label) and
|
||||
// `#subtitle` win over the props.
|
||||
//
|
||||
// Indeterminate is a DOM-only state (no HTML attribute) — synced
|
||||
// via a ref on every prop change.
|
||||
import { computed, onMounted, ref, useSlots, watch } from "vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface Props {
|
||||
modelValue?: boolean | null;
|
||||
label?: string;
|
||||
density?: "default" | "comfortable" | "compact";
|
||||
/** Secondary line under the label — most useful in `variant="card"`. */
|
||||
subtitle?: string;
|
||||
disabled?: boolean;
|
||||
indeterminate?: boolean;
|
||||
/** Reserve vertical space for error messages. */
|
||||
hideDetails?: boolean | "auto";
|
||||
size?: "sm" | "md";
|
||||
size?: "xs" | "sm" | "md" | "lg";
|
||||
shape?: "square" | "rounded" | "circle";
|
||||
/** Tone for the check fill + active border. */
|
||||
color?: string;
|
||||
variant?: "box" | "card";
|
||||
/** Error tone — red box + red label. */
|
||||
error?: boolean;
|
||||
errorMessages?: string | string[];
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false,
|
||||
label: undefined,
|
||||
density: "comfortable",
|
||||
subtitle: undefined,
|
||||
disabled: false,
|
||||
indeterminate: false,
|
||||
hideDetails: "auto",
|
||||
size: "md",
|
||||
shape: "square",
|
||||
color: "primary",
|
||||
variant: "box",
|
||||
error: false,
|
||||
errorMessages: () => [],
|
||||
});
|
||||
|
||||
defineEmits<{
|
||||
(e: "update:modelValue", value: boolean | null): void;
|
||||
const emit = defineEmits<{
|
||||
(e: "update:modelValue", value: boolean): void;
|
||||
}>();
|
||||
|
||||
const slots = useSlots();
|
||||
const inputRef = ref<HTMLInputElement | null>(null);
|
||||
|
||||
// `indeterminate` has no HTML attribute — must be set via the DOM
|
||||
// property on the input. Sync on mount + whenever the prop flips.
|
||||
function syncIndeterminate() {
|
||||
if (inputRef.value) inputRef.value.indeterminate = !!props.indeterminate;
|
||||
}
|
||||
onMounted(syncIndeterminate);
|
||||
watch(() => props.indeterminate, syncIndeterminate);
|
||||
|
||||
function onChange(evt: Event) {
|
||||
const target = evt.target as HTMLInputElement;
|
||||
emit("update:modelValue", target.checked);
|
||||
}
|
||||
|
||||
const isChecked = computed(() => props.modelValue === true);
|
||||
|
||||
// ── Tone resolver ──────────────────────────────────────────────
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
const resolvedColor = computed<string>(
|
||||
() => TONE_MAP[props.color] ?? props.color ?? TONE_MAP.primary,
|
||||
);
|
||||
|
||||
// ── Error message normalisation ───────────────────────────────
|
||||
const messages = computed<string[]>(() => {
|
||||
if (!props.error) return [];
|
||||
const m = props.errorMessages;
|
||||
if (Array.isArray(m)) return m;
|
||||
return m ? [m] : [];
|
||||
});
|
||||
|
||||
const showDetailsRow = computed(() => {
|
||||
if (props.hideDetails === true) return false;
|
||||
if (props.hideDetails === "auto") return messages.value.length > 0;
|
||||
return true;
|
||||
});
|
||||
|
||||
const hasSubtitle = computed(() => !!(props.subtitle || slots.subtitle));
|
||||
const hasLabel = computed(
|
||||
() => !!(props.label || slots.default || hasSubtitle.value),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VCheckbox
|
||||
<div
|
||||
v-bind="$attrs"
|
||||
class="r-checkbox"
|
||||
:class="`r-checkbox--${size}`"
|
||||
:model-value="modelValue"
|
||||
:label="label"
|
||||
:density="density"
|
||||
:disabled="disabled"
|
||||
:indeterminate="indeterminate"
|
||||
:hide-details="hideDetails"
|
||||
false-icon=""
|
||||
true-icon="mdi-check"
|
||||
indeterminate-icon="mdi-minus"
|
||||
@update:model-value="(v) => $emit('update:modelValue', v)"
|
||||
class="r-checkbox-wrap"
|
||||
:class="[
|
||||
`r-checkbox--size-${size}`,
|
||||
`r-checkbox--shape-${shape}`,
|
||||
`r-checkbox--variant-${variant}`,
|
||||
{
|
||||
'r-checkbox--checked': isChecked,
|
||||
'r-checkbox--indeterminate': indeterminate,
|
||||
'r-checkbox--disabled': disabled,
|
||||
'r-checkbox--error': error,
|
||||
'r-checkbox--has-subtitle': hasSubtitle,
|
||||
},
|
||||
]"
|
||||
:style="{ '--r-cb-color': resolvedColor }"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VCheckbox>
|
||||
<label class="r-checkbox">
|
||||
<!-- Native input — visually hidden but kept in the layout for
|
||||
form submission, keyboard, and screen reader support. -->
|
||||
<input
|
||||
ref="inputRef"
|
||||
type="checkbox"
|
||||
class="r-checkbox__input"
|
||||
:checked="isChecked"
|
||||
:disabled="disabled"
|
||||
@change="onChange"
|
||||
/>
|
||||
<span class="r-checkbox__box" aria-hidden="true">
|
||||
<!-- Inline SVG so we can animate the actual `stroke-dashoffset`
|
||||
and "draw" the check tick / minus instead of just scaling
|
||||
a glyph. Always mounted — the parent's `--checked` /
|
||||
`--indeterminate` classes drive opacity + dashoffset so
|
||||
the transition actually has a "from" state to ease out of.
|
||||
We mount BOTH the polyline and the line and toggle which
|
||||
one is visible with their own classes — swapping
|
||||
elements via `v-if` would reset the dashoffset and kill
|
||||
the animation. -->
|
||||
<svg
|
||||
class="r-checkbox__icon"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="3"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<polyline
|
||||
points="5,12 10,17 19,7"
|
||||
class="r-checkbox__path r-checkbox__path--check"
|
||||
/>
|
||||
<line
|
||||
x1="6"
|
||||
y1="12"
|
||||
x2="18"
|
||||
y2="12"
|
||||
class="r-checkbox__path r-checkbox__path--minus"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
<span v-if="hasLabel" class="r-checkbox__body">
|
||||
<span v-if="label || slots.default" class="r-checkbox__label">
|
||||
<slot>{{ label }}</slot>
|
||||
</span>
|
||||
<span v-if="hasSubtitle" class="r-checkbox__subtitle">
|
||||
<slot name="subtitle">{{ subtitle }}</slot>
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div v-if="showDetailsRow" class="r-checkbox__details">
|
||||
<span v-for="(m, i) in messages" :key="i" class="r-checkbox__message">
|
||||
{{ m }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-checkbox :deep(.v-selection-control) {
|
||||
min-height: 36px;
|
||||
}
|
||||
.r-checkbox :deep(.v-selection-control__wrapper),
|
||||
.r-checkbox :deep(.v-selection-control__input) {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
/* ── Sizing tokens (per-size CSS vars) ─────────────────────────── */
|
||||
.r-checkbox-wrap {
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
/* md defaults */
|
||||
--r-cb-box: 18px;
|
||||
--r-cb-icon: 14px;
|
||||
--r-cb-radius: 4px;
|
||||
--r-cb-border: 1.5px;
|
||||
--r-cb-color: var(--r-color-brand-primary);
|
||||
}
|
||||
|
||||
/* Visible 18×18 box drawn as a pseudo-element so the click target
|
||||
stays 36×36 (touch / pad friendly). */
|
||||
.r-checkbox :deep(.v-selection-control__input) {
|
||||
position: relative;
|
||||
border-radius: 8px;
|
||||
.r-checkbox--size-xs {
|
||||
--r-cb-box: 12px;
|
||||
--r-cb-icon: 10px;
|
||||
--r-cb-radius: 3px;
|
||||
--r-cb-border: 1.25px;
|
||||
}
|
||||
.r-checkbox :deep(.v-selection-control__input)::before {
|
||||
content: "";
|
||||
.r-checkbox--size-sm {
|
||||
--r-cb-box: 16px;
|
||||
--r-cb-icon: 12px;
|
||||
--r-cb-radius: 3px;
|
||||
}
|
||||
.r-checkbox--size-md {
|
||||
--r-cb-box: 18px;
|
||||
--r-cb-icon: 14px;
|
||||
--r-cb-radius: 4px;
|
||||
}
|
||||
.r-checkbox--size-lg {
|
||||
--r-cb-box: 22px;
|
||||
--r-cb-icon: 16px;
|
||||
--r-cb-radius: 5px;
|
||||
--r-cb-border: 2px;
|
||||
}
|
||||
|
||||
/* Shape — overrides the size's default radius. */
|
||||
.r-checkbox--shape-rounded {
|
||||
--r-cb-radius: 8px;
|
||||
}
|
||||
.r-checkbox--shape-circle {
|
||||
--r-cb-radius: 50%;
|
||||
}
|
||||
|
||||
/* ── Label wrap — clickable region ───────────────────────────── */
|
||||
.r-checkbox {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
/* Real gap between visible box and label — no tap-area illusion. */
|
||||
gap: 10px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
/* Slight vertical breathing room so a row of checkboxes is
|
||||
touch-comfortable even without extra padding from the consumer. */
|
||||
padding: 4px 0;
|
||||
}
|
||||
.r-checkbox--disabled .r-checkbox {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* ── Native input — visually hidden, keyboard-reachable ──────── */
|
||||
.r-checkbox__input {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
margin-top: -9px;
|
||||
margin-left: -9px;
|
||||
border-radius: 4px;
|
||||
border: 1.5px solid var(--r-color-border-strong);
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
/* ── Visible box ─────────────────────────────────────────────── */
|
||||
.r-checkbox__box {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: var(--r-cb-box);
|
||||
height: var(--r-cb-box);
|
||||
flex-shrink: 0;
|
||||
border: var(--r-cb-border) solid var(--r-color-border-strong);
|
||||
border-radius: var(--r-cb-radius);
|
||||
background: transparent;
|
||||
pointer-events: none;
|
||||
/* `transform` springs back from the press-squash via the same
|
||||
overshoot easing the icon uses. `box-shadow` carries the hover
|
||||
halo and the checked-state glow. */
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
box-shadow var(--r-motion-base) var(--r-motion-ease-out),
|
||||
transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1);
|
||||
}
|
||||
|
||||
/* Hover (only when interactive). */
|
||||
.r-checkbox
|
||||
:deep(.v-selection-control:not(.v-selection-control--disabled))
|
||||
.v-selection-control__input:hover::before {
|
||||
/* Hover — border darkens, faint fill, soft currentColor halo around
|
||||
the box so the user feels the affordance at a glance (same idiom
|
||||
RBtn / RSwitch use). */
|
||||
.r-checkbox:hover:not(.r-checkbox--disabled) .r-checkbox__box {
|
||||
border-color: var(--r-color-fg-secondary);
|
||||
background: var(--r-color-surface-hover);
|
||||
box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 10%, transparent);
|
||||
}
|
||||
|
||||
/* Vuetify ripple — off; we own the visual feedback. */
|
||||
.r-checkbox :deep(.v-selection-control__input .v-ripple__container) {
|
||||
display: none;
|
||||
/* Press squash — momentarily shrink the box on click. The shorter
|
||||
transition lets the squash feel crisp on press-down; releasing the
|
||||
click lets the longer spring above bounce it back. */
|
||||
.r-checkbox:active:not(.r-checkbox--disabled) .r-checkbox__box {
|
||||
transform: scale(0.88);
|
||||
transition: transform 110ms var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
/* Checked / indeterminate fill. */
|
||||
.r-checkbox
|
||||
:deep(.v-selection-control--dirty .v-selection-control__input)::before,
|
||||
.r-checkbox
|
||||
:deep(
|
||||
.v-selection-control--indeterminate .v-selection-control__input
|
||||
)::before {
|
||||
background: var(--r-color-brand-primary);
|
||||
border-color: var(--r-color-brand-primary);
|
||||
/* Checked / indeterminate — solid colour fill + outer glow + inner
|
||||
top highlight. The glow extends past the box edges so a checked
|
||||
box "pops" off the page (RSwitch's on-track glow vocabulary). The
|
||||
inset highlight gives the fill a touch of dimensionality without
|
||||
committing to skeuomorphism. */
|
||||
.r-checkbox--checked .r-checkbox__box,
|
||||
.r-checkbox--indeterminate .r-checkbox__box {
|
||||
background: var(--r-cb-color);
|
||||
border-color: var(--r-cb-color);
|
||||
box-shadow:
|
||||
inset 0 1px 0 color-mix(in srgb, white 18%, transparent),
|
||||
0 0 12px color-mix(in srgb, var(--r-cb-color) 32%, transparent);
|
||||
}
|
||||
.r-checkbox
|
||||
:deep(.v-selection-control--dirty:not(.v-selection-control--disabled))
|
||||
.v-selection-control__input:hover::before,
|
||||
.r-checkbox
|
||||
:deep(.v-selection-control--indeterminate:not(.v-selection-control--disabled))
|
||||
.v-selection-control__input:hover::before {
|
||||
background: var(--r-color-brand-primary-hover);
|
||||
border-color: var(--r-color-brand-primary-hover);
|
||||
.r-checkbox--checked:not(.r-checkbox--disabled):hover .r-checkbox__box,
|
||||
.r-checkbox--indeterminate:not(.r-checkbox--disabled):hover .r-checkbox__box {
|
||||
background: color-mix(in srgb, var(--r-cb-color) 88%, white);
|
||||
border-color: color-mix(in srgb, var(--r-cb-color) 88%, white);
|
||||
box-shadow:
|
||||
inset 0 1px 0 color-mix(in srgb, white 22%, transparent),
|
||||
0 0 16px color-mix(in srgb, var(--r-cb-color) 40%, transparent);
|
||||
}
|
||||
|
||||
/* The mdi-check / mdi-minus glyph sits on top of the filled box. */
|
||||
.r-checkbox :deep(.v-selection-control__input .v-icon) {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
color: var(--r-color-overlay-fg);
|
||||
font-size: 16px;
|
||||
/* ── Glyph (check / minus) — drawn-in stroke ──────────────────── */
|
||||
/* SVG icon — sized to the per-size --r-cb-icon var, color inherits
|
||||
white from the box. Always mounted (so the path animations have a
|
||||
"from" state). A scale + opacity pop wraps the per-path draw. */
|
||||
.r-checkbox__icon {
|
||||
width: var(--r-cb-icon);
|
||||
height: var(--r-cb-icon);
|
||||
color: white;
|
||||
pointer-events: none;
|
||||
transform: scale(0.6);
|
||||
opacity: 0;
|
||||
transition:
|
||||
transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1),
|
||||
opacity 120ms var(--r-motion-ease-out);
|
||||
}
|
||||
.r-checkbox--checked .r-checkbox__icon,
|
||||
.r-checkbox--indeterminate .r-checkbox__icon {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Modality-gated focus on the visible box. The native <input> is
|
||||
visually hidden so :focus-within on the wrapper is the right hook. */
|
||||
html[data-input="key"]
|
||||
.r-checkbox
|
||||
:deep(.v-selection-control__input:focus-within)::before,
|
||||
html[data-input="pad"]
|
||||
.r-checkbox
|
||||
:deep(.v-selection-control__input:focus-within)::before {
|
||||
outline: var(--r-focus-ring-width) solid var(--r-color-focus);
|
||||
outline-offset: 2px;
|
||||
/* Both paths exist in the DOM all the time; we toggle which one is
|
||||
visible with opacity so swapping check ↔ minus doesn't unmount the
|
||||
element (which would reset stroke-dashoffset and kill the draw).
|
||||
Default: hidden (opacity 0 + stroke fully offset). */
|
||||
.r-checkbox__path {
|
||||
opacity: 0;
|
||||
transition:
|
||||
stroke-dashoffset 360ms cubic-bezier(0.65, 0, 0.35, 1) 80ms,
|
||||
opacity 0ms linear 0ms;
|
||||
}
|
||||
html[data-input="pad"]
|
||||
.r-checkbox
|
||||
:deep(.v-selection-control__input:focus-within)::before {
|
||||
box-shadow: 0 0 0 5px
|
||||
color-mix(in srgb, var(--r-color-brand-primary) 20%, transparent);
|
||||
/* Check polyline (5,12)→(10,17)→(19,7) ≈ 20.5 units of length. */
|
||||
.r-checkbox__path--check {
|
||||
stroke-dasharray: 22;
|
||||
stroke-dashoffset: 22;
|
||||
}
|
||||
/* Minus (6,12)→(18,12) = 12 units of length. */
|
||||
.r-checkbox__path--minus {
|
||||
stroke-dasharray: 14;
|
||||
stroke-dashoffset: 14;
|
||||
}
|
||||
/* Reveal the right glyph and animate its dashoffset to 0 ("draw"). */
|
||||
.r-checkbox--checked:not(.r-checkbox--indeterminate) .r-checkbox__path--check {
|
||||
opacity: 1;
|
||||
stroke-dashoffset: 0;
|
||||
}
|
||||
.r-checkbox--indeterminate .r-checkbox__path--minus {
|
||||
opacity: 1;
|
||||
stroke-dashoffset: 0;
|
||||
}
|
||||
|
||||
/* Disabled. */
|
||||
.r-checkbox :deep(.v-selection-control--disabled) {
|
||||
opacity: 0.45;
|
||||
/* ── Body (label + subtitle) ─────────────────────────────────── */
|
||||
.r-checkbox__body {
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* Label. */
|
||||
.r-checkbox :deep(.v-label) {
|
||||
color: var(--r-color-fg-secondary);
|
||||
.r-checkbox__label {
|
||||
font-size: var(--r-font-size-md);
|
||||
opacity: 1;
|
||||
color: var(--r-color-fg-secondary);
|
||||
line-height: 1.4;
|
||||
}
|
||||
.r-checkbox :deep(.v-selection-control--disabled .v-label) {
|
||||
.r-checkbox__subtitle {
|
||||
font-size: var(--r-font-size-xs);
|
||||
color: var(--r-color-fg-muted);
|
||||
line-height: 1.4;
|
||||
}
|
||||
.r-checkbox--size-xs .r-checkbox__label,
|
||||
.r-checkbox--size-sm .r-checkbox__label {
|
||||
font-size: var(--r-font-size-sm);
|
||||
}
|
||||
.r-checkbox--size-lg .r-checkbox__label {
|
||||
font-size: var(--r-font-size-lg);
|
||||
}
|
||||
|
||||
/* When a subtitle is present the row reads as multi-line — align the
|
||||
box to the top of the body so it sits next to the label, not
|
||||
centred between label and subtitle. */
|
||||
.r-checkbox--has-subtitle .r-checkbox {
|
||||
align-items: flex-start;
|
||||
}
|
||||
.r-checkbox--has-subtitle .r-checkbox__box {
|
||||
/* Tiny optical nudge so the box's centre lines up with the label's
|
||||
first text line, not the line-box top. */
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* ── Disabled ────────────────────────────────────────────────── */
|
||||
.r-checkbox--disabled {
|
||||
opacity: 0.45;
|
||||
pointer-events: none;
|
||||
}
|
||||
.r-checkbox--disabled .r-checkbox__label {
|
||||
color: var(--r-color-fg-faint);
|
||||
}
|
||||
|
||||
/* Error state — red box + label. Vuetify adds .v-input--error to the
|
||||
outer wrapper when the field's rules fail or :error is true. */
|
||||
.r-checkbox :deep(.v-input--error .v-selection-control__input)::before {
|
||||
/* ── Error state ─────────────────────────────────────────────── */
|
||||
.r-checkbox--error .r-checkbox__box {
|
||||
border-color: var(--r-color-danger) !important;
|
||||
}
|
||||
.r-checkbox
|
||||
:deep(
|
||||
.v-input--error.v-selection-control--dirty .v-selection-control__input
|
||||
)::before {
|
||||
background: var(--r-color-danger);
|
||||
.r-checkbox--error.r-checkbox--checked .r-checkbox__box,
|
||||
.r-checkbox--error.r-checkbox--indeterminate .r-checkbox__box {
|
||||
background: var(--r-color-danger) !important;
|
||||
}
|
||||
.r-checkbox :deep(.v-input--error .v-label),
|
||||
.r-checkbox :deep(.v-input--error .v-messages) {
|
||||
.r-checkbox--error .r-checkbox__label,
|
||||
.r-checkbox--error .r-checkbox__message {
|
||||
color: var(--r-color-danger);
|
||||
}
|
||||
|
||||
/* ── Small variant ── */
|
||||
.r-checkbox--sm :deep(.v-selection-control) {
|
||||
min-height: 28px;
|
||||
/* ── Details row (error messages) ───────────────────────────── */
|
||||
.r-checkbox__details {
|
||||
margin-top: 2px;
|
||||
font-size: var(--r-font-size-xs);
|
||||
color: var(--r-color-fg-muted);
|
||||
padding-inline-start: calc(var(--r-cb-box) + 10px);
|
||||
}
|
||||
.r-checkbox--sm :deep(.v-selection-control__wrapper),
|
||||
.r-checkbox--sm :deep(.v-selection-control__input) {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
.r-checkbox__message {
|
||||
display: block;
|
||||
}
|
||||
.r-checkbox--sm :deep(.v-selection-control__input)::before {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin-top: -8px;
|
||||
margin-left: -8px;
|
||||
border-radius: 3px;
|
||||
|
||||
/* ── Focus ring — modality-gated ────────────────────────────── */
|
||||
html[data-input="key"]
|
||||
.r-checkbox:has(.r-checkbox__input:focus)
|
||||
.r-checkbox__box,
|
||||
html[data-input="pad"]
|
||||
.r-checkbox:has(.r-checkbox__input:focus)
|
||||
.r-checkbox__box {
|
||||
outline: 2px solid var(--r-color-focus, var(--r-cb-color));
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.r-checkbox--sm :deep(.v-selection-control__input .v-icon) {
|
||||
font-size: 13px;
|
||||
html[data-input="pad"]
|
||||
.r-checkbox:has(.r-checkbox__input:focus)
|
||||
.r-checkbox__box {
|
||||
box-shadow: 0 0 0 5px color-mix(in srgb, var(--r-cb-color) 20%, transparent);
|
||||
}
|
||||
.r-checkbox--sm :deep(.v-label) {
|
||||
font-size: var(--r-font-size-sm);
|
||||
|
||||
/* ── Variant: card — whole row clickable card ────────────────── */
|
||||
.r-checkbox--variant-card .r-checkbox {
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--r-color-border);
|
||||
border-radius: 10px;
|
||||
background: var(--r-color-bg-elevated);
|
||||
/* `transform` for the hover lift; `box-shadow` for the lift's
|
||||
drop shadow + the checked-state ring. */
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
box-shadow var(--r-motion-base) var(--r-motion-ease-out),
|
||||
transform var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
/* Hover lift — the card rises 1 px and gains a soft drop shadow so
|
||||
it reads as physical / pickable. */
|
||||
.r-checkbox--variant-card:not(.r-checkbox--disabled) .r-checkbox:hover {
|
||||
background: var(--r-color-surface);
|
||||
border-color: var(--r-color-border-strong);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 6px 14px color-mix(in srgb, black 18%, transparent);
|
||||
}
|
||||
/* Press cue — settle the card back down briefly when the user
|
||||
commits the click. */
|
||||
.r-checkbox--variant-card:not(.r-checkbox--disabled) .r-checkbox:active {
|
||||
transform: translateY(0);
|
||||
box-shadow: 0 2px 6px color-mix(in srgb, black 18%, transparent);
|
||||
transition:
|
||||
transform 90ms var(--r-motion-ease-out),
|
||||
box-shadow 90ms var(--r-motion-ease-out);
|
||||
}
|
||||
/* Checked card — brand-tinted fill + a 1 px brand ring that hugs the
|
||||
border, giving the card a "selected" outline glow. */
|
||||
.r-checkbox--variant-card.r-checkbox--checked .r-checkbox {
|
||||
background: color-mix(in srgb, var(--r-cb-color) 12%, transparent);
|
||||
border-color: color-mix(in srgb, var(--r-cb-color) 60%, transparent);
|
||||
box-shadow: 0 0 0 1px color-mix(in srgb, var(--r-cb-color) 35%, transparent);
|
||||
}
|
||||
.r-checkbox--variant-card.r-checkbox--checked:not(.r-checkbox--disabled)
|
||||
.r-checkbox:hover {
|
||||
background: color-mix(in srgb, var(--r-cb-color) 18%, transparent);
|
||||
box-shadow:
|
||||
0 0 0 1px color-mix(in srgb, var(--r-cb-color) 50%, transparent),
|
||||
0 6px 14px color-mix(in srgb, var(--r-cb-color) 20%, transparent);
|
||||
}
|
||||
.r-checkbox--variant-card .r-checkbox__body {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
.r-checkbox--variant-card .r-checkbox__label {
|
||||
color: var(--r-color-fg);
|
||||
font-weight: var(--r-font-weight-medium);
|
||||
}
|
||||
.r-checkbox--variant-card.r-checkbox--checked .r-checkbox__label {
|
||||
color: var(--r-cb-color);
|
||||
}
|
||||
|
||||
/* ── Reduced motion ───────────────────────────────────────────── */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.r-checkbox__icon,
|
||||
.r-checkbox__box,
|
||||
.r-checkbox--variant-card .r-checkbox {
|
||||
transition: opacity 100ms linear;
|
||||
}
|
||||
.r-checkbox__icon {
|
||||
transform: scale(1);
|
||||
}
|
||||
/* Drop the stroke-draw — keep the glyph instantly visible so
|
||||
motion-sensitive users still see the state. */
|
||||
.r-checkbox__path {
|
||||
transition: none;
|
||||
stroke-dashoffset: 0 !important;
|
||||
}
|
||||
/* Drop the press squash and card lift — motion-sensitive users
|
||||
keep the colour swap, lose the kinetic feedback. */
|
||||
.r-checkbox:active:not(.r-checkbox--disabled) .r-checkbox__box,
|
||||
.r-checkbox--variant-card:not(.r-checkbox--disabled) .r-checkbox:hover,
|
||||
.r-checkbox--variant-card:not(.r-checkbox--disabled) .r-checkbox:active {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -365,7 +365,7 @@ function onBackdropClick(event: MouseEvent) {
|
||||
<RBtn
|
||||
v-if="showArrowsResolved"
|
||||
icon="mdi-chevron-left"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
size="small"
|
||||
class="r-carousel__nav r-carousel__nav--prev"
|
||||
:aria-label="prevLabel"
|
||||
@@ -375,7 +375,7 @@ function onBackdropClick(event: MouseEvent) {
|
||||
<RBtn
|
||||
v-if="showArrowsResolved"
|
||||
icon="mdi-chevron-right"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
size="small"
|
||||
class="r-carousel__nav r-carousel__nav--next"
|
||||
:aria-label="nextLabel"
|
||||
|
||||
17
frontend/src/v2/lib/primitives/RAlert/RAlert.stories.css
Normal file
17
frontend/src/v2/lib/primitives/RAlert/RAlert.stories.css
Normal file
@@ -0,0 +1,17 @@
|
||||
/* Demo-only styles for RAlert stories. Imported by RAlert.stories.ts.
|
||||
Inline <style> blocks inside template strings get parsed
|
||||
inconsistently — keep demo CSS in a real file. */
|
||||
|
||||
@keyframes r-alert-story-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
.r-alert-story-spinner {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
|
||||
border-top-color: currentColor;
|
||||
border-radius: 50%;
|
||||
animation: r-alert-story-spin 0.9s linear infinite;
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { ref } from "vue";
|
||||
import "./RAlert.stories.css";
|
||||
import RAlert from "./RAlert.vue";
|
||||
|
||||
const meta: Meta<typeof RAlert> = {
|
||||
@@ -11,7 +13,7 @@ const meta: Meta<typeof RAlert> = {
|
||||
},
|
||||
variant: {
|
||||
control: "select",
|
||||
options: ["flat", "elevated", "tonal", "outlined", "text"],
|
||||
options: ["flat", "elevated", "translucent", "outlined", "text"],
|
||||
},
|
||||
density: {
|
||||
control: "select",
|
||||
@@ -21,6 +23,7 @@ const meta: Meta<typeof RAlert> = {
|
||||
closable: { control: "boolean" },
|
||||
title: { control: "text" },
|
||||
text: { control: "text" },
|
||||
icon: { control: "text" },
|
||||
},
|
||||
render: (args) => ({
|
||||
components: { RAlert },
|
||||
@@ -33,6 +36,8 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RAlert>;
|
||||
|
||||
// ── Tones ───────────────────────────────────────────────────────────
|
||||
|
||||
export const Success: Story = {
|
||||
args: { type: "success", text: "Reset link sent to your email." },
|
||||
};
|
||||
@@ -53,6 +58,179 @@ export const Error: Story = {
|
||||
args: { type: "error", text: "Unable to reach the server." },
|
||||
};
|
||||
|
||||
export const Closable: Story = {
|
||||
args: { type: "info", text: "You can dismiss me.", closable: true },
|
||||
export const AllTypes: Story = {
|
||||
name: "All types · translucent",
|
||||
render: () => ({
|
||||
components: { RAlert },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:12px;width:480px">
|
||||
<RAlert type="success" text="Reset link sent to your email." />
|
||||
<RAlert type="info" text="Library scan is in progress." />
|
||||
<RAlert type="warning" text="Hash calculation is disabled — ROMs won't be fingerprinted." />
|
||||
<RAlert type="error" text="Unable to reach the server." />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Variants ────────────────────────────────────────────────────────
|
||||
|
||||
export const Variants: Story = {
|
||||
name: "Variants · same type",
|
||||
render: () => ({
|
||||
components: { RAlert },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:12px;width:480px">
|
||||
<RAlert type="warning" variant="translucent" text="translucent — default · soft tint" />
|
||||
<RAlert type="warning" variant="flat" text="flat — solid colour fill, white text" />
|
||||
<RAlert type="warning" variant="elevated" text="elevated — flat + drop shadow" />
|
||||
<RAlert type="warning" variant="outlined" text="outlined — border only" />
|
||||
<RAlert type="warning" variant="text" text="text — no chrome, coloured text only" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Density ────────────────────────────────────────────────────────
|
||||
|
||||
export const Density: Story = {
|
||||
name: "Density compression",
|
||||
render: () => ({
|
||||
components: { RAlert },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:12px;width:480px">
|
||||
<RAlert type="info" density="default" text="default — generous padding for prominent alerts" />
|
||||
<RAlert type="info" density="comfortable" text="comfortable — middle ground" />
|
||||
<RAlert type="info" density="compact" text="compact — inline form-validation feel" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Title + body ────────────────────────────────────────────────────
|
||||
|
||||
export const TitleAndBody: Story = {
|
||||
name: "Title + body slot",
|
||||
render: () => ({
|
||||
components: { RAlert },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:12px;width:480px">
|
||||
<RAlert type="error">
|
||||
<template #title>Config file not mounted</template>
|
||||
The RomM container couldn't read its config file. Settings changes
|
||||
made here won't persist until the volume is mounted.
|
||||
</RAlert>
|
||||
<RAlert type="warning">
|
||||
<template #title>Config file not writable</template>
|
||||
The config file is mounted but read-only. Changes here will apply
|
||||
for this session only.
|
||||
</RAlert>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Icon ───────────────────────────────────────────────────────────
|
||||
|
||||
export const CustomIcon: Story = {
|
||||
name: "Icon override / suppress",
|
||||
render: () => ({
|
||||
components: { RAlert },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:12px;width:480px;font:12px/1.4 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RAlert type="info" text="Default — auto-picks mdi-information." />
|
||||
<RAlert type="info" icon="mdi-rocket-launch" text="Custom icon override." />
|
||||
<RAlert type="info" :icon="false" text="Icon suppressed — text-only banner." />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const PrependSlot: Story = {
|
||||
name: "Prepend slot (custom prepend)",
|
||||
render: () => ({
|
||||
components: { RAlert },
|
||||
template: `
|
||||
<RAlert type="info" density="compact" style="width:420px">
|
||||
<template #prepend>
|
||||
<div class="r-alert-story-spinner" />
|
||||
</template>
|
||||
Scanning Nintendo 64… 42 / 128 ROMs
|
||||
</RAlert>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Closable ───────────────────────────────────────────────────────
|
||||
|
||||
export const Closable: Story = {
|
||||
name: "Closable (interactive)",
|
||||
render: () => ({
|
||||
components: { RAlert },
|
||||
setup() {
|
||||
const visible = ref(true);
|
||||
function reset() {
|
||||
visible.value = false;
|
||||
setTimeout(() => {
|
||||
visible.value = true;
|
||||
}, 250);
|
||||
}
|
||||
return { visible, reset };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:14px;width:480px;align-items:flex-start">
|
||||
<RAlert
|
||||
v-model="visible"
|
||||
type="success"
|
||||
title="Token created"
|
||||
text="Make sure to copy it now — you won't see it again."
|
||||
closable
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
style="padding:6px 12px;background:var(--r-color-brand-primary);color:white;border:none;border-radius:6px;font:12px/1 sans-serif;cursor:pointer"
|
||||
@click="reset"
|
||||
>
|
||||
Show again
|
||||
</button>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world ──────────────────────────────────────────────────────
|
||||
|
||||
export const PatcherStatus: Story = {
|
||||
name: "Patcher status (real-world)",
|
||||
render: () => ({
|
||||
components: { RAlert },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:12px;width:480px">
|
||||
<RAlert type="error" density="compact" text="Unable to load patch file: invalid format." />
|
||||
<RAlert type="info" density="compact" text="Applying patch — patience.xdelta to Game.bin" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const FormValidation: Story = {
|
||||
name: "Form validation (inline)",
|
||||
render: () => ({
|
||||
components: { RAlert },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:10px;width:380px;padding:18px;background:var(--r-color-bg-elevated);border-radius:12px">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="New password"
|
||||
style="padding:8px 12px;background:var(--r-color-surface);border:1px solid var(--r-color-border);border-radius:6px;color:var(--r-color-fg);font:13px/1 sans-serif"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Confirm password"
|
||||
style="padding:8px 12px;background:var(--r-color-surface);border:1px solid var(--r-color-danger);border-radius:6px;color:var(--r-color-fg);font:13px/1 sans-serif"
|
||||
/>
|
||||
<RAlert type="error" density="compact" :icon="false" text="Passwords do not match" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,52 +1,387 @@
|
||||
<script setup lang="ts">
|
||||
import { VAlert } from "vuetify/components/VAlert";
|
||||
// RAlert — Vuetify-free. Banner with an auto-picked tone icon, title +
|
||||
// body, optional close button, and a `<Transition>` mount that fades
|
||||
// in / out so toggling visibility doesn't pop.
|
||||
//
|
||||
// `type` (`success | info | warning | error`) drives the colour and
|
||||
// the default icon. `variant` controls the paint:
|
||||
// • translucent (default) — soft tinted fill, coloured text
|
||||
// • flat — solid colour fill, white text
|
||||
// • elevated — flat + drop shadow
|
||||
// • outlined — coloured border + transparent fill
|
||||
// • text — no chrome, just coloured text
|
||||
//
|
||||
// Slots:
|
||||
// • default — body (alternatively `text` prop)
|
||||
// • title — header (alternatively `title` prop)
|
||||
// • prepend — replaces the auto-picked icon
|
||||
// • append — extra content on the trailing edge
|
||||
//
|
||||
// v-model controls visibility. When `closable` is set, clicking the
|
||||
// X emits `click:close` and flips `modelValue` to false; the leave
|
||||
// transition runs before the DOM is removed.
|
||||
import { computed, useSlots } from "vue";
|
||||
import RIcon from "../RIcon/RIcon.vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface Props {
|
||||
/** Tone keyword — drives colour + default icon. */
|
||||
type?: "success" | "info" | "warning" | "error";
|
||||
variant?: "flat" | "elevated" | "tonal" | "outlined" | "text";
|
||||
variant?: "flat" | "elevated" | "translucent" | "outlined" | "text";
|
||||
closable?: boolean;
|
||||
/** MDI icon override, or `false` to suppress the auto-icon. */
|
||||
icon?: string | false;
|
||||
density?: "default" | "comfortable" | "compact";
|
||||
title?: string;
|
||||
/** Shortcut for the default slot. */
|
||||
text?: string;
|
||||
rounded?: string | number | boolean;
|
||||
/** v-model visibility. */
|
||||
modelValue?: boolean;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
type: undefined,
|
||||
variant: "tonal",
|
||||
variant: "translucent",
|
||||
closable: false,
|
||||
icon: undefined,
|
||||
density: "default",
|
||||
title: undefined,
|
||||
text: undefined,
|
||||
rounded: "md",
|
||||
modelValue: true,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "update:modelValue", value: boolean): void;
|
||||
(e: "click:close", evt: MouseEvent): void;
|
||||
}>();
|
||||
|
||||
const slots = useSlots();
|
||||
|
||||
// Auto icon per type — the alert reads the alert tone at a glance.
|
||||
const TYPE_ICON: Record<string, string> = {
|
||||
success: "mdi-check-circle",
|
||||
info: "mdi-information",
|
||||
warning: "mdi-alert",
|
||||
error: "mdi-alert-octagon",
|
||||
};
|
||||
|
||||
const TYPE_COLOR: Record<string, string> = {
|
||||
success: "var(--r-color-success)",
|
||||
info: "var(--r-color-info)",
|
||||
warning: "var(--r-color-warning)",
|
||||
error: "var(--r-color-danger)",
|
||||
};
|
||||
|
||||
const resolvedColor = computed<string | undefined>(() =>
|
||||
props.type ? TYPE_COLOR[props.type] : undefined,
|
||||
);
|
||||
|
||||
const resolvedIcon = computed<string | undefined>(() => {
|
||||
// Explicit `false` suppresses the icon. Explicit string overrides.
|
||||
if (props.icon === false) return undefined;
|
||||
if (typeof props.icon === "string") return props.icon;
|
||||
if (props.type) return TYPE_ICON[props.type];
|
||||
return undefined;
|
||||
});
|
||||
|
||||
const ROUNDED_MAP: Record<string, string> = {
|
||||
"0": "0",
|
||||
sm: "4px",
|
||||
md: "8px",
|
||||
lg: "12px",
|
||||
xl: "16px",
|
||||
full: "999px",
|
||||
};
|
||||
const resolvedRounded = computed<string>(() => {
|
||||
const r = props.rounded;
|
||||
if (r === undefined || r === null || r === "") return "8px";
|
||||
if (r === true) return "999px";
|
||||
if (r === false) return "0";
|
||||
if (typeof r === "number") return `${r}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(r as string)) return `${r}px`;
|
||||
return ROUNDED_MAP[r as string] ?? String(r);
|
||||
});
|
||||
|
||||
// Role hint per type — error stays `alert` (assertive), the rest read
|
||||
// as `status` (polite). Matches WAI-ARIA semantics so screen readers
|
||||
// don't interrupt for a success banner.
|
||||
const ariaRole = computed(() => (props.type === "error" ? "alert" : "status"));
|
||||
|
||||
function close(evt: MouseEvent) {
|
||||
emit("click:close", evt);
|
||||
emit("update:modelValue", false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VAlert
|
||||
v-bind="$attrs"
|
||||
class="r-alert"
|
||||
:type="type"
|
||||
:variant="variant"
|
||||
:closable="closable"
|
||||
:icon="icon"
|
||||
:density="density"
|
||||
:title="title"
|
||||
:text="text"
|
||||
:rounded="rounded"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VAlert>
|
||||
<Transition name="r-alert">
|
||||
<div
|
||||
v-if="modelValue"
|
||||
v-bind="$attrs"
|
||||
class="r-alert"
|
||||
:class="[
|
||||
`r-alert--${variant}`,
|
||||
`r-alert--density-${density}`,
|
||||
{
|
||||
'r-alert--has-color': !!resolvedColor,
|
||||
'r-alert--has-title': !!(title || slots.title),
|
||||
},
|
||||
]"
|
||||
:style="{
|
||||
borderRadius: resolvedRounded,
|
||||
'--r-alert-color': resolvedColor,
|
||||
}"
|
||||
:role="ariaRole"
|
||||
>
|
||||
<!-- Prepend zone — slot wins over auto-icon. -->
|
||||
<span v-if="slots.prepend || resolvedIcon" class="r-alert__prepend">
|
||||
<slot name="prepend">
|
||||
<RIcon
|
||||
v-if="resolvedIcon"
|
||||
:icon="resolvedIcon"
|
||||
class="r-alert__icon"
|
||||
/>
|
||||
</slot>
|
||||
</span>
|
||||
|
||||
<!-- Body — title + body text. Each is optional. -->
|
||||
<div class="r-alert__body">
|
||||
<div v-if="title || slots.title" class="r-alert__title">
|
||||
<slot name="title">{{ title }}</slot>
|
||||
</div>
|
||||
<div v-if="text || slots.default" class="r-alert__content">
|
||||
<slot>{{ text }}</slot>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Append zone — caller-provided actions / links. -->
|
||||
<span v-if="slots.append" class="r-alert__append">
|
||||
<slot name="append" />
|
||||
</span>
|
||||
|
||||
<!-- Close button — only rendered when `closable`. -->
|
||||
<button
|
||||
v-if="closable"
|
||||
type="button"
|
||||
class="r-alert__close"
|
||||
:aria-label="'Close'"
|
||||
@click="close"
|
||||
>
|
||||
<RIcon icon="mdi-close" class="r-alert__close-icon" />
|
||||
</button>
|
||||
</div>
|
||||
</Transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-alert {
|
||||
display: flex;
|
||||
/* Default: single-line alert — icon vertical centre = text vertical
|
||||
centre, which reads as "aligned". When a title pushes the body
|
||||
to 2+ lines, `r-alert--has-title` overrides to `flex-start` so
|
||||
the icon hugs the top of the title rather than floating between
|
||||
title and body. */
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid transparent;
|
||||
font-size: var(--r-font-size-sm);
|
||||
line-height: var(--r-line-height-normal);
|
||||
line-height: 1.45;
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
box-shadow var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
.r-alert--has-title {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
/* ── Density compression ──────────────────────────────────────── */
|
||||
.r-alert--density-comfortable {
|
||||
padding: 10px 14px;
|
||||
gap: 10px;
|
||||
}
|
||||
.r-alert--density-compact {
|
||||
padding: 8px 12px;
|
||||
gap: 8px;
|
||||
font-size: var(--r-font-size-xs);
|
||||
}
|
||||
|
||||
/* ── Layout regions ──────────────────────────────────────────── */
|
||||
.r-alert__prepend,
|
||||
.r-alert__append {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
/* In the multi-line / title case the alert is top-aligned — nudge
|
||||
the icon down 1px so its optical centre matches the title's first
|
||||
line baseline (otherwise mixed-case glyphs sit slightly low). */
|
||||
.r-alert--has-title .r-alert__prepend {
|
||||
margin-top: 1px;
|
||||
}
|
||||
.r-alert__icon {
|
||||
font-size: 1.25em;
|
||||
color: var(--r-alert-color, currentColor);
|
||||
}
|
||||
|
||||
.r-alert__body {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.r-alert__title {
|
||||
font-weight: var(--r-font-weight-semibold);
|
||||
color: var(--r-alert-color, currentColor);
|
||||
}
|
||||
.r-alert__content {
|
||||
color: inherit;
|
||||
/* Slight tone-down on body text vs title so the hierarchy reads. */
|
||||
opacity: 0.92;
|
||||
}
|
||||
|
||||
/* ── Close button — own hover halo so it reads as separate ────── */
|
||||
.r-alert__close {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
margin-right: -4px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
border-radius: 50%;
|
||||
opacity: 0.7;
|
||||
transition:
|
||||
opacity var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
transform var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-alert__close:hover {
|
||||
opacity: 1;
|
||||
background: color-mix(in srgb, currentColor 12%, transparent);
|
||||
}
|
||||
.r-alert__close:active {
|
||||
transform: scale(0.9);
|
||||
}
|
||||
/* In the title (top-aligned) case the close button needs a nudge so
|
||||
it lines up with the title row instead of floating below it. */
|
||||
.r-alert--has-title .r-alert__close {
|
||||
margin-top: -2px;
|
||||
}
|
||||
.r-alert__close-icon {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* ── Variant: translucent (default) — soft tinted fill ────────── */
|
||||
.r-alert--translucent.r-alert--has-color {
|
||||
background: color-mix(in srgb, var(--r-alert-color) 14%, transparent);
|
||||
color: var(--r-alert-color);
|
||||
border-color: color-mix(in srgb, var(--r-alert-color) 28%, transparent);
|
||||
}
|
||||
.r-alert--translucent:not(.r-alert--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
border-color: var(--r-color-border);
|
||||
}
|
||||
|
||||
/* ── Variant: flat — solid colour fill ───────────────────────── */
|
||||
.r-alert--flat.r-alert--has-color {
|
||||
background: var(--r-alert-color);
|
||||
color: white;
|
||||
}
|
||||
.r-alert--flat.r-alert--has-color .r-alert__icon,
|
||||
.r-alert--flat.r-alert--has-color .r-alert__title {
|
||||
color: white;
|
||||
}
|
||||
.r-alert--flat:not(.r-alert--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Variant: elevated — flat + shadow ───────────────────────── */
|
||||
.r-alert--elevated.r-alert--has-color {
|
||||
background: var(--r-alert-color);
|
||||
color: white;
|
||||
box-shadow: 0 4px 12px
|
||||
color-mix(in srgb, var(--r-alert-color) 35%, transparent);
|
||||
}
|
||||
.r-alert--elevated.r-alert--has-color .r-alert__icon,
|
||||
.r-alert--elevated.r-alert--has-color .r-alert__title {
|
||||
color: white;
|
||||
}
|
||||
.r-alert--elevated:not(.r-alert--has-color) {
|
||||
background: var(--r-color-bg-elevated);
|
||||
color: var(--r-color-fg);
|
||||
box-shadow: 0 4px 12px color-mix(in srgb, black 22%, transparent);
|
||||
}
|
||||
|
||||
/* ── Variant: outlined — border + transparent fill ───────────── */
|
||||
.r-alert--outlined {
|
||||
background: transparent;
|
||||
}
|
||||
.r-alert--outlined.r-alert--has-color {
|
||||
color: var(--r-alert-color);
|
||||
border-color: color-mix(in srgb, var(--r-alert-color) 50%, transparent);
|
||||
}
|
||||
.r-alert--outlined:not(.r-alert--has-color) {
|
||||
color: var(--r-color-fg);
|
||||
border-color: var(--r-color-border);
|
||||
}
|
||||
|
||||
/* ── Variant: text — no chrome, coloured text only ───────────── */
|
||||
.r-alert--text {
|
||||
background: transparent;
|
||||
border-color: transparent;
|
||||
}
|
||||
.r-alert--text.r-alert--has-color {
|
||||
color: var(--r-alert-color);
|
||||
}
|
||||
.r-alert--text:not(.r-alert--has-color) {
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Mount / unmount transition ──────────────────────────────── */
|
||||
/* Slides + fades when toggled — keeps closing alerts from popping out
|
||||
of the document. The 8px slide is subtle enough to read as motion
|
||||
without being a "drawer". */
|
||||
.r-alert-enter-active {
|
||||
transition:
|
||||
opacity 200ms var(--r-motion-ease-out),
|
||||
transform 200ms var(--r-motion-ease-out);
|
||||
}
|
||||
.r-alert-leave-active {
|
||||
transition:
|
||||
opacity 160ms var(--r-motion-ease-out),
|
||||
transform 160ms var(--r-motion-ease-out);
|
||||
}
|
||||
.r-alert-enter-from {
|
||||
opacity: 0;
|
||||
transform: translateY(-8px);
|
||||
}
|
||||
.r-alert-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(-4px);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.r-alert-enter-active,
|
||||
.r-alert-leave-active {
|
||||
transition: opacity 100ms linear;
|
||||
}
|
||||
.r-alert-enter-from,
|
||||
.r-alert-leave-to {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -12,7 +12,7 @@ const meta: Meta<typeof RAvatar> = {
|
||||
rounded: { control: "text" },
|
||||
variant: {
|
||||
control: "select",
|
||||
options: ["flat", "elevated", "tonal", "outlined", "text", "plain"],
|
||||
options: ["flat", "elevated", "translucent", "outlined", "text", "plain"],
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -21,6 +21,8 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RAvatar>;
|
||||
|
||||
// ── Content modes ───────────────────────────────────────────────────
|
||||
|
||||
export const Initial: Story = {
|
||||
args: { color: "primary", size: 40 },
|
||||
render: (args) => ({
|
||||
@@ -38,11 +40,252 @@ export const Image: Story = {
|
||||
args: { image: "/assets/isotipo.svg", size: 48 },
|
||||
};
|
||||
|
||||
export const Rounded: Story = {
|
||||
args: { color: "accent", rounded: "lg", size: 40 },
|
||||
render: (args) => ({
|
||||
// ── Size ladder ─────────────────────────────────────────────────────
|
||||
|
||||
export const SizeLadder: Story = {
|
||||
name: "Size ladder",
|
||||
render: () => ({
|
||||
components: { RAvatar },
|
||||
setup: () => ({ args }),
|
||||
template: `<RAvatar v-bind="args">R</RAvatar>`,
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar size="x-small" color="primary">A</RAvatar>
|
||||
<span>x-small · 24px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar size="small" color="primary">A</RAvatar>
|
||||
<span>small · 32px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar size="default" color="primary">A</RAvatar>
|
||||
<span>default · 40px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar size="large" color="primary">A</RAvatar>
|
||||
<span>large · 48px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar size="x-large" color="primary">A</RAvatar>
|
||||
<span>x-large · 56px</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const NumericSizes: Story = {
|
||||
name: "Numeric sizes",
|
||||
render: () => ({
|
||||
components: { RAvatar },
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar :size="20" color="accent" icon="mdi-account" />
|
||||
<span>20</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar :size="32" color="accent" icon="mdi-account" />
|
||||
<span>32</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar :size="64" color="accent" icon="mdi-account" />
|
||||
<span>64</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar :size="96" color="accent" icon="mdi-account" />
|
||||
<span>96</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar :size="128" color="accent" icon="mdi-account" />
|
||||
<span>128</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Variants ────────────────────────────────────────────────────────
|
||||
|
||||
export const Variants: Story = {
|
||||
render: () => ({
|
||||
components: { RAvatar },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:18px 24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar variant="flat" color="primary" size="48">YZ</RAvatar>
|
||||
<span>flat</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar variant="elevated" color="primary" size="48">YZ</RAvatar>
|
||||
<span>elevated</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar variant="translucent" color="primary" size="48">YZ</RAvatar>
|
||||
<span>translucent</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar variant="outlined" color="primary" size="48">YZ</RAvatar>
|
||||
<span>outlined</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar variant="text" color="primary" size="48">YZ</RAvatar>
|
||||
<span>text</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar variant="plain" color="primary" size="48">YZ</RAvatar>
|
||||
<span>plain</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Tones ───────────────────────────────────────────────────────────
|
||||
|
||||
export const Tones: Story = {
|
||||
name: "Tones · flat",
|
||||
render: () => ({
|
||||
components: { RAvatar },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(4,auto);gap:16px 18px;align-items:center;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RAvatar color="primary" size="40" icon="mdi-account" />
|
||||
<span>primary</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RAvatar color="secondary" size="40" icon="mdi-account" />
|
||||
<span>secondary</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RAvatar color="accent" size="40" icon="mdi-account" />
|
||||
<span>accent</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RAvatar color="success" size="40" icon="mdi-check" />
|
||||
<span>success</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RAvatar color="warning" size="40" icon="mdi-alert" />
|
||||
<span>warning</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RAvatar color="danger" size="40" icon="mdi-close" />
|
||||
<span>danger</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RAvatar color="info" size="40" icon="mdi-information" />
|
||||
<span>info</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RAvatar size="40" icon="mdi-account" />
|
||||
<span>no colour</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const TonesTranslucent: Story = {
|
||||
name: "Tones · translucent",
|
||||
render: () => ({
|
||||
components: { RAvatar },
|
||||
template: `
|
||||
<div style="display:flex;gap:16px;align-items:center">
|
||||
<RAvatar variant="translucent" color="primary" size="40" icon="mdi-account" />
|
||||
<RAvatar variant="translucent" color="secondary" size="40" icon="mdi-account" />
|
||||
<RAvatar variant="translucent" color="accent" size="40" icon="mdi-account" />
|
||||
<RAvatar variant="translucent" color="success" size="40" icon="mdi-check" />
|
||||
<RAvatar variant="translucent" color="warning" size="40" icon="mdi-alert" />
|
||||
<RAvatar variant="translucent" color="danger" size="40" icon="mdi-close" />
|
||||
<RAvatar variant="translucent" color="info" size="40" icon="mdi-information" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Shapes ──────────────────────────────────────────────────────────
|
||||
|
||||
export const Rounded: Story = {
|
||||
name: "Rounded ladder",
|
||||
render: () => ({
|
||||
components: { RAvatar },
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar :rounded="false" color="primary" size="48">R</RAvatar>
|
||||
<span>false / "0"</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar rounded="sm" color="primary" size="48">R</RAvatar>
|
||||
<span>sm · 4</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar rounded="md" color="primary" size="48">R</RAvatar>
|
||||
<span>md · 8</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar rounded="lg" color="primary" size="48">R</RAvatar>
|
||||
<span>lg · 12</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar rounded="xl" color="primary" size="48">R</RAvatar>
|
||||
<span>xl · 16</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RAvatar rounded="circle" color="primary" size="48">R</RAvatar>
|
||||
<span>circle (default)</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world ──────────────────────────────────────────────────────
|
||||
|
||||
export const UserRow: Story = {
|
||||
name: "Inside a user row",
|
||||
render: () => ({
|
||||
components: { RAvatar },
|
||||
template: `
|
||||
<div style="width:340px;background:var(--r-color-bg-elevated);border:1px solid var(--r-color-border);border-radius:12px;overflow:hidden;font:13px/1.4 sans-serif;color:var(--r-color-fg)">
|
||||
<div style="display:flex;align-items:center;gap:12px;padding:12px 16px">
|
||||
<RAvatar image="/assets/isotipo.svg" size="36" />
|
||||
<div style="display:flex;flex-direction:column;gap:2px">
|
||||
<span style="font-weight:600">RomM Admin</span>
|
||||
<span style="color:var(--r-color-fg-muted);font-size:11px">admin · last seen 3 min ago</span>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex;align-items:center;gap:12px;padding:12px 16px;border-top:1px solid var(--r-color-border)">
|
||||
<RAvatar color="accent" size="36">EM</RAvatar>
|
||||
<div style="display:flex;flex-direction:column;gap:2px">
|
||||
<span style="font-weight:600">Emma</span>
|
||||
<span style="color:var(--r-color-fg-muted);font-size:11px">editor</span>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex;align-items:center;gap:12px;padding:12px 16px;border-top:1px solid var(--r-color-border)">
|
||||
<RAvatar variant="translucent" color="info" size="36" icon="mdi-account-question" />
|
||||
<div style="display:flex;flex-direction:column;gap:2px">
|
||||
<span style="font-weight:600">Guest</span>
|
||||
<span style="color:var(--r-color-fg-muted);font-size:11px">viewer · pending</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const StackedGroup: Story = {
|
||||
name: "Stacked group (avatar group)",
|
||||
render: () => ({
|
||||
components: { RAvatar },
|
||||
template: `
|
||||
<div style="display:flex;align-items:center">
|
||||
<RAvatar color="primary" size="36" style="border:2px solid var(--r-color-bg);position:relative;z-index:5">AB</RAvatar>
|
||||
<RAvatar color="accent" size="36" style="margin-left:-12px;border:2px solid var(--r-color-bg);position:relative;z-index:4">CD</RAvatar>
|
||||
<RAvatar color="success" size="36" style="margin-left:-12px;border:2px solid var(--r-color-bg);position:relative;z-index:3">EF</RAvatar>
|
||||
<RAvatar color="warning" size="36" style="margin-left:-12px;border:2px solid var(--r-color-bg);position:relative;z-index:2">GH</RAvatar>
|
||||
<RAvatar variant="translucent" color="info" size="36" style="margin-left:-12px;border:2px solid var(--r-color-bg);position:relative;z-index:1">+5</RAvatar>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { VAvatar } from "vuetify/components/VAvatar";
|
||||
// RAvatar — Vuetify-free. Inline-flex container holding one of three
|
||||
// contents in priority order: `image` (renders an <img>), `icon`
|
||||
// (renders an RIcon), or the default slot (initials / arbitrary
|
||||
// content). `overflow: hidden` + the rounded radius clips the image to
|
||||
// the avatar shape automatically — no per-image border-radius needed.
|
||||
//
|
||||
// `color` resolves through the same tone map RIcon uses (`"primary"` →
|
||||
// `var(--r-color-brand-primary)` etc., legacy `romm-*` and CSS colours
|
||||
// pass through). Pair with `variant` to control how the colour paints:
|
||||
// solid fill, translucent, outlined, or text-only.
|
||||
//
|
||||
// `size` keyword ladder mirrors Vuetify's so call sites that pass
|
||||
// `"small"` / `"large"` keep working. The font-size of any text slot
|
||||
// scales to ~40% of the avatar height — initials stay legible at every
|
||||
// size without a per-size override.
|
||||
import { computed } from "vue";
|
||||
import RIcon from "../RIcon/RIcon.vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
@@ -8,11 +24,14 @@ interface Props {
|
||||
color?: string;
|
||||
image?: string;
|
||||
icon?: string;
|
||||
/** `false | "0"` → square; `"sm" | "md" | "lg" | "xl"` → token radii;
|
||||
* `"pill"` → fully pilled; `"circle" | true | undefined` → circle;
|
||||
* number / px-length → raw value. */
|
||||
rounded?: string | number | boolean;
|
||||
variant?: "flat" | "elevated" | "tonal" | "outlined" | "text" | "plain";
|
||||
variant?: "flat" | "elevated" | "translucent" | "outlined" | "text" | "plain";
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
size: "default",
|
||||
color: undefined,
|
||||
image: undefined,
|
||||
@@ -20,21 +39,196 @@ withDefaults(defineProps<Props>(), {
|
||||
rounded: undefined,
|
||||
variant: "flat",
|
||||
});
|
||||
|
||||
const SIZE_MAP: Record<string, string> = {
|
||||
"x-small": "24px",
|
||||
small: "32px",
|
||||
default: "40px",
|
||||
large: "48px",
|
||||
"x-large": "56px",
|
||||
};
|
||||
|
||||
const resolvedSize = computed<string>(() => {
|
||||
const s = props.size;
|
||||
if (s === undefined || s === null || s === "") return SIZE_MAP.default;
|
||||
if (typeof s === "number") return `${s}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(s)) return `${s}px`;
|
||||
return SIZE_MAP[s] ?? s;
|
||||
});
|
||||
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
|
||||
const resolvedColor = computed<string | undefined>(() => {
|
||||
const c = props.color;
|
||||
if (!c) return undefined;
|
||||
return TONE_MAP[c] ?? c;
|
||||
});
|
||||
|
||||
const ROUNDED_MAP: Record<string, string> = {
|
||||
"0": "0",
|
||||
sm: "4px",
|
||||
md: "8px",
|
||||
lg: "12px",
|
||||
xl: "16px",
|
||||
pill: "999px",
|
||||
circle: "50%",
|
||||
};
|
||||
|
||||
const resolvedRounded = computed<string>(() => {
|
||||
const r = props.rounded;
|
||||
// Default is circle — matches Vuetify's VAvatar.
|
||||
if (r === undefined || r === null) return "50%";
|
||||
if (r === true) return "50%";
|
||||
if (r === false) return "0";
|
||||
if (typeof r === "number") return `${r}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(r)) return `${r}px`;
|
||||
return ROUNDED_MAP[r] ?? r;
|
||||
});
|
||||
|
||||
// Font-size scales proportionally to the avatar's pixel height so the
|
||||
// default slot (initials) stays legible at every size without callers
|
||||
// computing per-size CSS. 40% of height is the sweet spot — matches
|
||||
// the visual mass of v1's user avatars.
|
||||
const fontSize = computed(() => {
|
||||
const px = parseFloat(resolvedSize.value);
|
||||
return Number.isFinite(px) ? `${Math.round(px * 0.4)}px` : "14px";
|
||||
});
|
||||
|
||||
const styleObj = computed(() => ({
|
||||
width: resolvedSize.value,
|
||||
height: resolvedSize.value,
|
||||
borderRadius: resolvedRounded.value,
|
||||
fontSize: fontSize.value,
|
||||
// Variants read this var for their fills / borders / text colours.
|
||||
// Stays `undefined` when no `color` prop is set, falling through to
|
||||
// the variant's neutral defaults below.
|
||||
"--r-avatar-color": resolvedColor.value,
|
||||
}));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VAvatar
|
||||
<div
|
||||
v-bind="$attrs"
|
||||
class="r-avatar"
|
||||
:size="size"
|
||||
:color="color"
|
||||
:image="image"
|
||||
:icon="icon"
|
||||
:rounded="rounded"
|
||||
:variant="variant"
|
||||
:class="[
|
||||
`r-avatar--${variant}`,
|
||||
{ 'r-avatar--has-color': !!resolvedColor },
|
||||
]"
|
||||
:style="styleObj"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VAvatar>
|
||||
<img v-if="image" :src="image" alt="" class="r-avatar__image" />
|
||||
<RIcon v-else-if="icon" :icon="icon" class="r-avatar__icon" />
|
||||
<slot v-else />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-avatar {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
position: relative;
|
||||
line-height: 1;
|
||||
font-weight: var(--r-font-weight-semibold);
|
||||
user-select: none;
|
||||
/* Smooth tone / theme swaps so the avatar pops in without flicker. */
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
box-shadow var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
/* Image fills the container; `overflow: hidden` on the parent clips
|
||||
it to the rounded shape, no per-image radius needed. */
|
||||
.r-avatar__image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Icon scales to the avatar's font-size so a 24px avatar renders a
|
||||
small icon and a 56px avatar renders a big one — no caller maths. */
|
||||
.r-avatar__icon {
|
||||
font-size: 1.2em;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* ── Variant: flat — solid colour fill ─────────────────────────── */
|
||||
.r-avatar--flat.r-avatar--has-color {
|
||||
background: var(--r-avatar-color);
|
||||
color: white;
|
||||
}
|
||||
.r-avatar--flat:not(.r-avatar--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Variant: elevated — solid fill + soft shadow ──────────────── */
|
||||
.r-avatar--elevated.r-avatar--has-color {
|
||||
background: var(--r-avatar-color);
|
||||
color: white;
|
||||
box-shadow: 0 2px 8px color-mix(in srgb, black 30%, transparent);
|
||||
}
|
||||
.r-avatar--elevated:not(.r-avatar--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
box-shadow: 0 2px 8px color-mix(in srgb, black 20%, transparent);
|
||||
}
|
||||
|
||||
/* ── Variant: translucent — soft tinted fill, coloured text ────── */
|
||||
.r-avatar--translucent.r-avatar--has-color {
|
||||
background: color-mix(in srgb, var(--r-avatar-color) 18%, transparent);
|
||||
color: var(--r-avatar-color);
|
||||
}
|
||||
.r-avatar--translucent:not(.r-avatar--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Variant: outlined — border + coloured text ────────────────── */
|
||||
.r-avatar--outlined {
|
||||
background: transparent;
|
||||
}
|
||||
.r-avatar--outlined.r-avatar--has-color {
|
||||
color: var(--r-avatar-color);
|
||||
border: 1px solid var(--r-avatar-color);
|
||||
}
|
||||
.r-avatar--outlined:not(.r-avatar--has-color) {
|
||||
color: var(--r-color-fg);
|
||||
border: 1px solid var(--r-color-border);
|
||||
}
|
||||
|
||||
/* ── Variant: text — no fill, just coloured glyph/initial ──────── */
|
||||
.r-avatar--text {
|
||||
background: transparent;
|
||||
}
|
||||
.r-avatar--text.r-avatar--has-color {
|
||||
color: var(--r-avatar-color);
|
||||
}
|
||||
.r-avatar--text:not(.r-avatar--has-color) {
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Variant: plain — fully unstyled (inherit everything) ──────── */
|
||||
.r-avatar--plain {
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { ref } from "vue";
|
||||
import RAvatar from "../RAvatar/RAvatar.vue";
|
||||
import RIcon from "../RIcon/RIcon.vue";
|
||||
import RBadge from "./RBadge.vue";
|
||||
@@ -26,6 +27,9 @@ const meta: Meta<typeof RBadge> = {
|
||||
dot: { control: "boolean" },
|
||||
inline: { control: "boolean" },
|
||||
bordered: { control: "boolean" },
|
||||
floating: { control: "boolean" },
|
||||
modelValue: { control: "boolean" },
|
||||
max: { control: "number" },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -33,8 +37,10 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RBadge>;
|
||||
|
||||
// ── Content modes ───────────────────────────────────────────────────
|
||||
|
||||
export const Count: Story = {
|
||||
args: { content: "7", color: "error" },
|
||||
args: { content: "7" },
|
||||
render: (args) => ({
|
||||
components: { RBadge, RIcon },
|
||||
setup: () => ({ args }),
|
||||
@@ -47,11 +53,7 @@ export const Count: Story = {
|
||||
};
|
||||
|
||||
export const Dot: Story = {
|
||||
args: {
|
||||
dot: true,
|
||||
color: "success",
|
||||
content: "test",
|
||||
},
|
||||
args: { dot: true, color: "success" },
|
||||
render: (args) => ({
|
||||
components: { RBadge, RAvatar },
|
||||
setup: () => ({ args }),
|
||||
@@ -62,3 +64,233 @@ export const Dot: Story = {
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const IconBadge: Story = {
|
||||
name: "Icon content",
|
||||
args: { icon: "mdi-check", color: "success" },
|
||||
render: (args) => ({
|
||||
components: { RBadge, RAvatar },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<RBadge v-bind="args">
|
||||
<RAvatar color="primary" size="48">YZ</RAvatar>
|
||||
</RBadge>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Max / clamping ──────────────────────────────────────────────────
|
||||
|
||||
export const MaxClamp: Story = {
|
||||
name: "max clamping",
|
||||
render: () => ({
|
||||
components: { RBadge, RIcon },
|
||||
template: `
|
||||
<div style="display:flex;gap:36px;align-items:center;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge :content="3" :max="99"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>3</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge :content="42" :max="99"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>42</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge :content="100" :max="99"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>100 (clamped → 99+)</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge :content="999" :max="999"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>999 (max raised)</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Locations ───────────────────────────────────────────────────────
|
||||
|
||||
export const Locations: Story = {
|
||||
name: "All 8 locations",
|
||||
render: () => ({
|
||||
components: { RBadge, RAvatar },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(4,auto);gap:32px 36px;align-items:center;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="7" location="top start"><RAvatar color="primary" size="48">YZ</RAvatar></RBadge>
|
||||
<span>top start</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="7" location="top"><RAvatar color="primary" size="48">YZ</RAvatar></RBadge>
|
||||
<span>top</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="7" location="top end"><RAvatar color="primary" size="48">YZ</RAvatar></RBadge>
|
||||
<span>top end</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="7" location="end"><RAvatar color="primary" size="48">YZ</RAvatar></RBadge>
|
||||
<span>end</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="7" location="bottom end"><RAvatar color="primary" size="48">YZ</RAvatar></RBadge>
|
||||
<span>bottom end</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="7" location="bottom"><RAvatar color="primary" size="48">YZ</RAvatar></RBadge>
|
||||
<span>bottom</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="7" location="bottom start"><RAvatar color="primary" size="48">YZ</RAvatar></RBadge>
|
||||
<span>bottom start</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="7" location="start"><RAvatar color="primary" size="48">YZ</RAvatar></RBadge>
|
||||
<span>start</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Modifiers ───────────────────────────────────────────────────────
|
||||
|
||||
export const Bordered: Story = {
|
||||
name: "Bordered (contrast ring)",
|
||||
render: () => ({
|
||||
components: { RBadge, RAvatar },
|
||||
template: `
|
||||
<div style="display:flex;gap:36px;align-items:center;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge dot color="success" location="bottom end">
|
||||
<RAvatar color="primary" size="48">YZ</RAvatar>
|
||||
</RBadge>
|
||||
<span>plain</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge dot color="success" bordered location="bottom end">
|
||||
<RAvatar color="primary" size="48">YZ</RAvatar>
|
||||
</RBadge>
|
||||
<span>bordered</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="5" bordered location="top end">
|
||||
<RAvatar color="accent" size="48">EM</RAvatar>
|
||||
</RBadge>
|
||||
<span>count + bordered</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Floating: Story = {
|
||||
name: "Floating (pushed further out)",
|
||||
render: () => ({
|
||||
components: { RBadge, RIcon },
|
||||
template: `
|
||||
<div style="display:flex;gap:36px;align-items:center;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="3"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>default</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="3" floating><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>floating</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Inline: Story = {
|
||||
name: "Inline (next to label)",
|
||||
render: () => ({
|
||||
components: { RBadge },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:8px;font:13px/1.4 sans-serif;color:var(--r-color-fg)">
|
||||
<RBadge inline content="4" color="primary">
|
||||
<span>Inbox</span>
|
||||
</RBadge>
|
||||
<RBadge inline content="12" color="info">
|
||||
<span>Drafts</span>
|
||||
</RBadge>
|
||||
<RBadge inline content="142" :max="99" color="danger">
|
||||
<span>Spam</span>
|
||||
</RBadge>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Tones ───────────────────────────────────────────────────────────
|
||||
|
||||
export const Tones: Story = {
|
||||
render: () => ({
|
||||
components: { RBadge, RIcon },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(4,auto);gap:24px 28px;align-items:center;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="9" color="primary"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>primary</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="9" color="secondary"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>secondary</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="9" color="accent"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>accent</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="9" color="success"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>success</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="9" color="warning"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>warning</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="9" color="danger"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>danger</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="9" color="info"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>info</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RBadge content="9"><RIcon icon="mdi-bell" size="28" /></RBadge>
|
||||
<span>default (error)</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Motion ──────────────────────────────────────────────────────────
|
||||
|
||||
export const PopAnimation: Story = {
|
||||
name: "Pop animation (toggle modelValue)",
|
||||
render: () => ({
|
||||
components: { RBadge, RAvatar },
|
||||
setup() {
|
||||
const show = ref(true);
|
||||
return { show };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:18px;font:12px/1.4 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RBadge :model-value="show" content="3" color="primary">
|
||||
<RAvatar color="accent" size="56">EM</RAvatar>
|
||||
</RBadge>
|
||||
<button
|
||||
type="button"
|
||||
style="padding:8px 16px;background:var(--r-color-brand-primary);color:white;border:none;border-radius:8px;font-weight:600;cursor:pointer"
|
||||
@click="show = !show"
|
||||
>
|
||||
{{ show ? "Hide badge" : "Show badge" }}
|
||||
</button>
|
||||
<span>Toggle to see the spring pop-in / quick fade-out.</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,48 +1,289 @@
|
||||
<script setup lang="ts">
|
||||
import type { Anchor } from "vuetify";
|
||||
import { VBadge } from "vuetify/components/VBadge";
|
||||
// RBadge — Vuetify-free. Wraps a default slot (the anchor element) and
|
||||
// floats a small pill / dot / icon in one of eight positions (`top end`,
|
||||
// `bottom start`, side anchors). Built for the unread-counter, status,
|
||||
// favorite, online-indicator patterns.
|
||||
//
|
||||
// Pop-in spring animation reuses the RSwitch cubic-bezier so the
|
||||
// vocabulary matches across the library. `pointer-events: none` on the
|
||||
// pill so clicks pass through to the anchor.
|
||||
//
|
||||
// `content` accepts a string or number; numeric values past `max` get
|
||||
// clamped with a `+` suffix ("99+"). `dot` renders a small bare circle
|
||||
// (no content/icon). `bordered` adds a `--r-color-bg`-coloured ring so
|
||||
// the badge reads cleanly on coloured anchors (avatars, etc).
|
||||
//
|
||||
// `inline` flips the badge from absolute-positioned floater to inline
|
||||
// sibling — useful when you want a list badge that reads like "Inbox
|
||||
// (4)" rather than an overlay.
|
||||
import { computed } from "vue";
|
||||
import RIcon from "../RIcon/RIcon.vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
type Anchor =
|
||||
| "top start"
|
||||
| "top end"
|
||||
| "bottom start"
|
||||
| "bottom end"
|
||||
| "top"
|
||||
| "bottom"
|
||||
| "start"
|
||||
| "end";
|
||||
|
||||
interface Props {
|
||||
content?: string | number;
|
||||
/** Tone keyword / legacy `romm-*` / any CSS colour. Default `"error"`
|
||||
* matches Vuetify's default (red unread-count look). */
|
||||
color?: string;
|
||||
/** Bare dot — ignores `content` / `icon`. */
|
||||
dot?: boolean;
|
||||
/** Adds a 2px ring in the page bg colour so the badge contrasts on
|
||||
* coloured anchors. */
|
||||
bordered?: boolean;
|
||||
/** Renders inline next to the slot content instead of floating over
|
||||
* it. Useful for list-style "Item (3)" rows. */
|
||||
inline?: boolean;
|
||||
location?: Anchor;
|
||||
/** Show / hide the badge with a pop transition. */
|
||||
modelValue?: boolean;
|
||||
/** Pushes the badge further out of the anchor's corner — handy when
|
||||
* the badge would otherwise sit too close to the content. */
|
||||
floating?: boolean;
|
||||
/** Numeric content > `max` is clamped: `max + "+"`. */
|
||||
max?: number;
|
||||
/** MDI icon shown inside the badge instead of text. */
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
content: undefined,
|
||||
color: "error",
|
||||
dot: false,
|
||||
bordered: false,
|
||||
inline: false,
|
||||
location: "top end",
|
||||
modelValue: true,
|
||||
floating: false,
|
||||
max: 99,
|
||||
icon: undefined,
|
||||
});
|
||||
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
|
||||
const resolvedColor = computed<string>(() => {
|
||||
const c = props.color;
|
||||
if (!c) return TONE_MAP.error;
|
||||
return TONE_MAP[c] ?? c;
|
||||
});
|
||||
|
||||
const displayContent = computed<string>(() => {
|
||||
const c = props.content;
|
||||
if (c === undefined || c === null || c === "") return "";
|
||||
const num = typeof c === "number" ? c : Number(c);
|
||||
if (!Number.isNaN(num) && Number.isFinite(num) && num > props.max) {
|
||||
return `${props.max}+`;
|
||||
}
|
||||
return String(c);
|
||||
});
|
||||
|
||||
// Location → CSS class. `top end` becomes `r-badge--at-top-end`, etc.
|
||||
const locationClass = computed(
|
||||
() => `r-badge--at-${props.location.replace(/\s+/g, "-")}`,
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VBadge
|
||||
<span
|
||||
v-bind="$attrs"
|
||||
:content="content"
|
||||
:color="color"
|
||||
:dot="dot"
|
||||
:bordered="bordered"
|
||||
:inline="inline"
|
||||
:location="location"
|
||||
:model-value="modelValue"
|
||||
:floating="floating"
|
||||
:max="max"
|
||||
:icon="icon"
|
||||
class="r-badge-wrap"
|
||||
:class="{ 'r-badge-wrap--inline': inline }"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VBadge>
|
||||
<slot />
|
||||
<Transition name="r-badge-pop">
|
||||
<span
|
||||
v-if="modelValue"
|
||||
class="r-badge"
|
||||
:class="[
|
||||
locationClass,
|
||||
{
|
||||
'r-badge--dot': dot,
|
||||
'r-badge--bordered': bordered,
|
||||
'r-badge--floating': floating,
|
||||
'r-badge--inline': inline,
|
||||
},
|
||||
]"
|
||||
:style="{ '--r-badge-color': resolvedColor }"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<template v-if="!dot">
|
||||
<RIcon v-if="icon" :icon="icon" size="12" class="r-badge__icon" />
|
||||
<span v-else class="r-badge__content">{{ displayContent }}</span>
|
||||
</template>
|
||||
</span>
|
||||
</Transition>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* ── Wrap (the anchor's positioning context) ───────────────────── */
|
||||
.r-badge-wrap {
|
||||
display: inline-flex;
|
||||
position: relative;
|
||||
/* `align-items: center` keeps the slot content vertically centered
|
||||
when the wrapper is used inline next to text. */
|
||||
align-items: center;
|
||||
}
|
||||
.r-badge-wrap--inline {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
/* ── Badge pill ────────────────────────────────────────────────── */
|
||||
.r-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--r-badge-color);
|
||||
color: white;
|
||||
font-size: 10px;
|
||||
font-weight: var(--r-font-weight-bold);
|
||||
line-height: 1;
|
||||
border-radius: 999px;
|
||||
white-space: nowrap;
|
||||
padding: 2px 6px;
|
||||
min-width: 16px;
|
||||
height: 16px;
|
||||
pointer-events: none;
|
||||
/* Smooth tone / theme swaps + transform spring during the corner-pop
|
||||
animation below. */
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
box-shadow var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
.r-badge__icon {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* ── Dot variant ──────────────────────────────────────────────── */
|
||||
.r-badge--dot {
|
||||
width: 10px;
|
||||
min-width: 10px;
|
||||
height: 10px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* ── Bordered — a soft page-bg ring so the badge pops on coloured
|
||||
anchors (avatars). ─────────────────────────────────────────── */
|
||||
.r-badge--bordered {
|
||||
box-shadow: 0 0 0 2px var(--r-color-bg);
|
||||
}
|
||||
|
||||
/* ── Inline — no absolute positioning, sits next to the anchor ─── */
|
||||
.r-badge--inline {
|
||||
position: static;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
/* ── Floating positioning ─────────────────────────────────────── */
|
||||
/* Each anchor sets its corner + a `translate` that centers the badge
|
||||
on the corner so the visible mass sits half inside / half outside
|
||||
the anchor. `scale` (from the enter/leave transition below) composes
|
||||
on top via the CSS `scale` property — keeps the translate untouched
|
||||
during the pop. */
|
||||
.r-badge:not(.r-badge--inline) {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.r-badge--at-top-start {
|
||||
top: 0;
|
||||
left: 0;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
.r-badge--at-top-end {
|
||||
top: 0;
|
||||
right: 0;
|
||||
transform: translate(50%, -50%);
|
||||
}
|
||||
.r-badge--at-bottom-start {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
transform: translate(-50%, 50%);
|
||||
}
|
||||
.r-badge--at-bottom-end {
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
transform: translate(50%, 50%);
|
||||
}
|
||||
|
||||
/* Side anchors — center along the edge. */
|
||||
.r-badge--at-top {
|
||||
top: 0;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
.r-badge--at-bottom {
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
transform: translate(-50%, 50%);
|
||||
}
|
||||
.r-badge--at-start {
|
||||
top: 50%;
|
||||
left: 0;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
.r-badge--at-end {
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translate(50%, -50%);
|
||||
}
|
||||
|
||||
/* Floating bumps the translate further out so the badge sits clearly
|
||||
outside the anchor — useful for icons inside dense toolbars where
|
||||
the default half-overlap would crowd the glyph. */
|
||||
.r-badge--floating.r-badge--at-top-end {
|
||||
transform: translate(75%, -75%);
|
||||
}
|
||||
.r-badge--floating.r-badge--at-top-start {
|
||||
transform: translate(-75%, -75%);
|
||||
}
|
||||
.r-badge--floating.r-badge--at-bottom-end {
|
||||
transform: translate(75%, 75%);
|
||||
}
|
||||
.r-badge--floating.r-badge--at-bottom-start {
|
||||
transform: translate(-75%, 75%);
|
||||
}
|
||||
|
||||
/* ── Pop animation — spring overshoot in / quick fade out ──────── */
|
||||
.r-badge-pop-enter-active {
|
||||
transition:
|
||||
scale 320ms cubic-bezier(0.34, 1.56, 0.64, 1),
|
||||
opacity 200ms var(--r-motion-ease-out);
|
||||
}
|
||||
.r-badge-pop-leave-active {
|
||||
transition:
|
||||
scale 180ms var(--r-motion-ease-out),
|
||||
opacity 180ms var(--r-motion-ease-out);
|
||||
}
|
||||
/* `scale` is a separate property from `transform` (CSS Transforms L2),
|
||||
so animating it doesn't clobber the location-class `translate(...)` —
|
||||
the two compose: final transform = translate ∘ scale. */
|
||||
.r-badge-pop-enter-from,
|
||||
.r-badge-pop-leave-to {
|
||||
opacity: 0;
|
||||
scale: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { ref } from "vue";
|
||||
import RBtn from "./RBtn.vue";
|
||||
|
||||
const meta: Meta<typeof RBtn> = {
|
||||
@@ -7,7 +8,7 @@ const meta: Meta<typeof RBtn> = {
|
||||
argTypes: {
|
||||
variant: {
|
||||
control: "select",
|
||||
options: ["flat", "text", "elevated", "tonal", "outlined", "plain"],
|
||||
options: ["flat", "text", "elevated", "translucent", "outlined", "plain"],
|
||||
},
|
||||
color: { control: "text" },
|
||||
size: {
|
||||
@@ -27,62 +28,313 @@ const meta: Meta<typeof RBtn> = {
|
||||
loading: { control: "boolean" },
|
||||
disabled: { control: "boolean" },
|
||||
block: { control: "boolean" },
|
||||
ripple: { control: "boolean" },
|
||||
border: { control: "boolean" },
|
||||
prependIcon: { control: "text" },
|
||||
appendIcon: { control: "text" },
|
||||
},
|
||||
render: (args) => ({
|
||||
components: { RBtn },
|
||||
setup: () => ({ args }),
|
||||
template: `<RBtn v-bind="args">{{ args.default ?? 'Click me' }}</RBtn>`,
|
||||
}),
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RBtn>;
|
||||
|
||||
export const Default: Story = {};
|
||||
// ── Defaults ────────────────────────────────────────────────────────
|
||||
|
||||
export const Primary: Story = {
|
||||
args: { color: "primary", variant: "flat" },
|
||||
};
|
||||
|
||||
export const Outlined: Story = {
|
||||
args: { variant: "outlined" },
|
||||
};
|
||||
|
||||
export const Text: Story = {
|
||||
args: { variant: "text" },
|
||||
};
|
||||
|
||||
export const WithPrependIcon: Story = {
|
||||
args: { prependIcon: "mdi-login" },
|
||||
export const Default: Story = {
|
||||
render: (args) => ({
|
||||
components: { RBtn },
|
||||
setup: () => ({ args }),
|
||||
template: `<RBtn v-bind="args">Log in</RBtn>`,
|
||||
template: `<RBtn v-bind="args">Click me</RBtn>`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Loading: Story = {
|
||||
args: { loading: true },
|
||||
export const Primary: Story = {
|
||||
args: { color: "primary" },
|
||||
render: (args) => ({
|
||||
components: { RBtn },
|
||||
setup: () => ({ args }),
|
||||
template: `<RBtn v-bind="args">Working…</RBtn>`,
|
||||
template: `<RBtn v-bind="args">Primary action</RBtn>`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Variants ────────────────────────────────────────────────────────
|
||||
|
||||
export const Variants: Story = {
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(3,auto);gap:14px 18px;justify-items:start">
|
||||
<RBtn variant="flat" color="primary">flat</RBtn>
|
||||
<RBtn variant="elevated" color="primary">elevated</RBtn>
|
||||
<RBtn variant="translucent" color="primary">translucent</RBtn>
|
||||
<RBtn variant="outlined" color="primary">outlined</RBtn>
|
||||
<RBtn variant="text" color="primary">text</RBtn>
|
||||
<RBtn variant="plain" color="primary">plain</RBtn>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Size ladder ─────────────────────────────────────────────────────
|
||||
|
||||
export const SizeLadder: Story = {
|
||||
name: "Size ladder",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:14px">
|
||||
<RBtn size="x-small" color="primary">x-small</RBtn>
|
||||
<RBtn size="small" color="primary">small</RBtn>
|
||||
<RBtn size="default" color="primary">default</RBtn>
|
||||
<RBtn size="large" color="primary">large</RBtn>
|
||||
<RBtn size="x-large" color="primary">x-large</RBtn>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Density: Story = {
|
||||
name: "Density compression",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;align-items:center;gap:14px">
|
||||
<RBtn density="default" color="primary">default</RBtn>
|
||||
<RBtn density="comfortable" color="primary">comfortable</RBtn>
|
||||
<RBtn density="compact" color="primary">compact</RBtn>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Tones ───────────────────────────────────────────────────────────
|
||||
|
||||
export const Tones: Story = {
|
||||
name: "Tones · flat",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:10px">
|
||||
<RBtn color="primary">primary</RBtn>
|
||||
<RBtn color="secondary">secondary</RBtn>
|
||||
<RBtn color="accent">accent</RBtn>
|
||||
<RBtn color="success">success</RBtn>
|
||||
<RBtn color="warning">warning</RBtn>
|
||||
<RBtn color="danger">danger</RBtn>
|
||||
<RBtn color="info">info</RBtn>
|
||||
<RBtn>neutral</RBtn>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const TonesTranslucent: Story = {
|
||||
name: "Tones · translucent",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:10px">
|
||||
<RBtn variant="translucent" color="primary">primary</RBtn>
|
||||
<RBtn variant="translucent" color="secondary">secondary</RBtn>
|
||||
<RBtn variant="translucent" color="accent">accent</RBtn>
|
||||
<RBtn variant="translucent" color="success">success</RBtn>
|
||||
<RBtn variant="translucent" color="warning">warning</RBtn>
|
||||
<RBtn variant="translucent" color="danger">danger</RBtn>
|
||||
<RBtn variant="translucent" color="info">info</RBtn>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Icons ───────────────────────────────────────────────────────────
|
||||
|
||||
export const WithIcons: Story = {
|
||||
name: "Prepend / append icons",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:10px">
|
||||
<RBtn color="primary" prepend-icon="mdi-login">Sign in</RBtn>
|
||||
<RBtn color="success" prepend-icon="mdi-content-save">Save</RBtn>
|
||||
<RBtn variant="outlined" append-icon="mdi-open-in-new">Open docs</RBtn>
|
||||
<RBtn variant="translucent" color="primary" prepend-icon="mdi-filter" append-icon="mdi-menu-down">Filter</RBtn>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const IconOnly: Story = {
|
||||
name: "Icon-only buttons",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;align-items:center;gap:10px">
|
||||
<RBtn icon="mdi-pencil" variant="text" aria-label="Edit" />
|
||||
<RBtn icon="mdi-delete" variant="text" color="danger" aria-label="Delete" />
|
||||
<RBtn icon="mdi-heart" variant="translucent" color="primary" aria-label="Favorite" />
|
||||
<RBtn icon="mdi-refresh" variant="outlined" aria-label="Refresh" />
|
||||
<RBtn icon="mdi-plus" color="primary" aria-label="Add" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const IconSizeLadder: Story = {
|
||||
name: "Icon-only · size ladder",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;align-items:center;gap:10px">
|
||||
<RBtn icon="mdi-star" size="x-small" color="primary" aria-label="x-small" />
|
||||
<RBtn icon="mdi-star" size="small" color="primary" aria-label="small" />
|
||||
<RBtn icon="mdi-star" size="default" color="primary" aria-label="default" />
|
||||
<RBtn icon="mdi-star" size="large" color="primary" aria-label="large" />
|
||||
<RBtn icon="mdi-star" size="x-large" color="primary" aria-label="x-large" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Rounded ─────────────────────────────────────────────────────────
|
||||
|
||||
export const Rounded: Story = {
|
||||
name: "Rounded ladder",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:10px;align-items:center">
|
||||
<RBtn :rounded="0" color="primary">0</RBtn>
|
||||
<RBtn rounded="sm" color="primary">sm</RBtn>
|
||||
<RBtn rounded="md" color="primary">md (default)</RBtn>
|
||||
<RBtn rounded="lg" color="primary">lg</RBtn>
|
||||
<RBtn rounded="xl" color="primary">xl</RBtn>
|
||||
<RBtn rounded="full" color="primary">full / pill</RBtn>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Loading ─────────────────────────────────────────────────────────
|
||||
|
||||
export const LoadingState: Story = {
|
||||
name: "Loading (interactive)",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
setup() {
|
||||
const loading = ref(false);
|
||||
function run() {
|
||||
loading.value = true;
|
||||
setTimeout(() => {
|
||||
loading.value = false;
|
||||
}, 1800);
|
||||
}
|
||||
return { loading, run };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:14px;align-items:flex-start">
|
||||
<RBtn color="primary" :loading="loading" prepend-icon="mdi-content-save" @click="run">
|
||||
Save changes
|
||||
</RBtn>
|
||||
<RBtn variant="outlined" :loading="loading" @click="run">Submit</RBtn>
|
||||
<span style="font:12px/1.4 sans-serif;color:var(--r-color-fg-muted)">
|
||||
Click — spinner appears after the 200ms debounce; layout doesn't shift.
|
||||
</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Block / disabled ────────────────────────────────────────────────
|
||||
|
||||
export const Block: Story = {
|
||||
args: { block: true, prependIcon: "mdi-send", color: "primary" },
|
||||
render: (args) => ({
|
||||
components: { RBtn },
|
||||
setup: () => ({ args }),
|
||||
template: `<div style="width:360px"><RBtn v-bind="args">Submit</RBtn></div>`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Disabled: Story = {
|
||||
args: { disabled: true },
|
||||
};
|
||||
|
||||
export const Block: Story = {
|
||||
args: { block: true, prependIcon: "mdi-send" },
|
||||
render: (args) => ({
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
setup: () => ({ args }),
|
||||
template: `<div style="width: 360px"><RBtn v-bind="args">Submit</RBtn></div>`,
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:10px">
|
||||
<RBtn disabled>disabled flat</RBtn>
|
||||
<RBtn variant="outlined" disabled>disabled outlined</RBtn>
|
||||
<RBtn variant="translucent" color="primary" disabled>disabled translucent</RBtn>
|
||||
<RBtn variant="text" color="danger" disabled>disabled text</RBtn>
|
||||
<RBtn icon="mdi-delete" variant="text" disabled aria-label="disabled icon" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Border modifier ─────────────────────────────────────────────────
|
||||
|
||||
export const BorderModifier: Story = {
|
||||
name: "Border modifier (chip-style activator)",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:10px;align-items:center">
|
||||
<RBtn variant="translucent" color="primary" border>translucent + border</RBtn>
|
||||
<RBtn variant="text" color="primary" border>text + border</RBtn>
|
||||
<RBtn variant="translucent" color="accent" border rounded="full">activator pill</RBtn>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Polymorphic root ────────────────────────────────────────────────
|
||||
|
||||
export const AsLink: Story = {
|
||||
name: "Polymorphic (href / to)",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:12px;align-items:flex-start">
|
||||
<RBtn href="https://romm.app" target="_blank" append-icon="mdi-open-in-new" color="primary">
|
||||
External link (<a>)
|
||||
</RBtn>
|
||||
<span style="font:12px/1.4 sans-serif;color:var(--r-color-fg-muted)">
|
||||
With <code>to</code>, RBtn renders <code><router-link></code> — invisible in this story without a router, but the prop is accepted.
|
||||
</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world stacks ───────────────────────────────────────────────
|
||||
|
||||
export const Toolbar: Story = {
|
||||
name: "Toolbar row",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:inline-flex;align-items:center;gap:6px;padding:6px 8px;background:var(--r-color-surface);border-radius:10px">
|
||||
<RBtn icon="mdi-format-bold" variant="text" size="small" aria-label="Bold" />
|
||||
<RBtn icon="mdi-format-italic" variant="text" size="small" aria-label="Italic" />
|
||||
<RBtn icon="mdi-format-underline" variant="text" size="small" aria-label="Underline" />
|
||||
<span style="width:1px;height:18px;background:var(--r-color-border);margin:0 4px"></span>
|
||||
<RBtn icon="mdi-format-list-bulleted" variant="text" size="small" aria-label="List" />
|
||||
<RBtn icon="mdi-format-quote-close" variant="text" size="small" aria-label="Quote" />
|
||||
<RBtn icon="mdi-link-variant" variant="text" size="small" aria-label="Link" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const FormActions: Story = {
|
||||
name: "Form actions row",
|
||||
render: () => ({
|
||||
components: { RBtn },
|
||||
template: `
|
||||
<div style="display:flex;gap:10px;justify-content:flex-end;padding:14px;background:var(--r-color-bg-elevated);border-radius:10px;width:420px">
|
||||
<RBtn variant="text">Cancel</RBtn>
|
||||
<RBtn variant="outlined">Save draft</RBtn>
|
||||
<RBtn color="primary" prepend-icon="mdi-send">Publish</RBtn>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,46 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref, watch } from "vue";
|
||||
import { VBtn } from "vuetify/components/VBtn";
|
||||
// RBtn — Vuetify-free. The workhorse of the v2 library.
|
||||
//
|
||||
// Polymorphic root via `<component :is>`:
|
||||
// • `to` set → renders RouterLink
|
||||
// • `href` set → renders <a>
|
||||
// • otherwise → renders <button>
|
||||
// This matches Vuetify's VBtn auto-detection so call sites that use
|
||||
// `to="/foo"` or `href="https://…"` keep working unchanged.
|
||||
//
|
||||
// Variants `flat / elevated / translucent / outlined / text / plain`
|
||||
// — same shape across the lib. `border` adds a translucent
|
||||
// currentColor border on top of any variant (used to recreate the
|
||||
// RTag chip activator look). `block` stretches to 100% width.
|
||||
//
|
||||
// `icon` accepts a string (MDI class) or `true`. When set, the button
|
||||
// collapses to a square hit target (width = height). Pair with
|
||||
// `prepend-icon` / `append-icon` to get icon + label without icon-only
|
||||
// styling.
|
||||
//
|
||||
// `loading` swaps the content for an inline spinner. The flip is
|
||||
// debounced by `loadingDebounce` (default 200ms) so quick actions
|
||||
// don't paint a spinner-flash; the hide step is immediate.
|
||||
//
|
||||
// Hover / active feedback comes from a `::before` overlay tinted by
|
||||
// `currentColor` so all six variants share the same vocabulary —
|
||||
// no per-variant `:hover` rules. Active state scales down 3% for
|
||||
// a haptic press cue (RSwitch motion language).
|
||||
import { computed, onBeforeUnmount, ref, useSlots, watch } from "vue";
|
||||
import { RouterLink, type RouteLocationRaw } from "vue-router";
|
||||
import RIcon from "../RIcon/RIcon.vue";
|
||||
import RProgressCircular from "../RProgressCircular/RProgressCircular.vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
// RBtn — thin wrapper around v-btn with RomM v2 defaults:
|
||||
// - variant="flat" (our primary visual style)
|
||||
// - color undefined (neutral) — `primary` is reserved for primary
|
||||
// actions (Login, Add note, etc.). Pass `color="primary"`
|
||||
// explicitly when the button is THE primary action of its surface.
|
||||
// - rounded="md"
|
||||
// - font-weight medium, no uppercase (Vuetify's default)
|
||||
// - debounced spinner: when `loading` flips true, the spinner only
|
||||
// appears after `loadingDebounce` ms (default 200). Actions that
|
||||
// resolve quicker than that flash never paint a spinner. Going from
|
||||
// loading → not-loading is immediate.
|
||||
// - `border` modifier — adds a translucent border in the current
|
||||
// text colour. Pair with `variant="tonal"` + a `color` to get the
|
||||
// RTag pill recipe (translucent bg + coloured border + coloured
|
||||
// text) for chip-style activators (e.g. the Type cell in folder
|
||||
// mappings).
|
||||
// Every Vuetify prop remains available via $attrs.
|
||||
interface Props {
|
||||
variant?: "flat" | "text" | "elevated" | "tonal" | "outlined" | "plain";
|
||||
variant?: "flat" | "text" | "elevated" | "translucent" | "outlined" | "plain";
|
||||
color?: string;
|
||||
rounded?: string | number | boolean;
|
||||
loading?: boolean;
|
||||
/** ms before the spinner appears after `loading` becomes true. */
|
||||
/** ms before the spinner appears after `loading` flips true. */
|
||||
loadingDebounce?: number;
|
||||
disabled?: boolean;
|
||||
block?: boolean;
|
||||
size?: "x-small" | "small" | "default" | "large" | "x-large";
|
||||
density?: "default" | "comfortable" | "compact";
|
||||
/** `true` → square icon-only button. `string` → MDI icon rendered as
|
||||
* the button's sole content (icon-only). */
|
||||
icon?: string | boolean;
|
||||
ripple?: boolean;
|
||||
prependIcon?: string;
|
||||
appendIcon?: string;
|
||||
type?: "button" | "submit" | "reset";
|
||||
/** Adds a translucent border in the current text colour. Pairs
|
||||
* cleanly with `variant="tonal"` to produce an RTag-style chip
|
||||
* activator. */
|
||||
/** Translucent currentColor border on top of the chosen variant. */
|
||||
border?: boolean;
|
||||
/** Renders the button as a router-link to this route. */
|
||||
to?: RouteLocationRaw;
|
||||
/** Renders the button as an `<a>` href. */
|
||||
href?: string;
|
||||
/** Target for `<a>` mode. */
|
||||
target?: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -49,16 +66,107 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
rounded: "md",
|
||||
loading: false,
|
||||
loadingDebounce: 200,
|
||||
disabled: false,
|
||||
block: false,
|
||||
size: "default",
|
||||
density: "default",
|
||||
type: "button",
|
||||
icon: undefined,
|
||||
prependIcon: undefined,
|
||||
appendIcon: undefined,
|
||||
icon: undefined,
|
||||
ripple: undefined,
|
||||
type: "button",
|
||||
border: false,
|
||||
to: undefined,
|
||||
href: undefined,
|
||||
target: undefined,
|
||||
});
|
||||
|
||||
const slots = useSlots();
|
||||
|
||||
// ── Polymorphic root ─────────────────────────────────────────────
|
||||
const elementType = computed(() => {
|
||||
if (props.to !== undefined && props.to !== null) return RouterLink;
|
||||
if (props.href !== undefined && props.href !== null) return "a";
|
||||
return "button";
|
||||
});
|
||||
|
||||
const dynamicAttrs = computed<Record<string, unknown>>(() => {
|
||||
// For `<a>` and RouterLink, `disabled` isn't a real HTML attribute —
|
||||
// we apply aria-disabled + pointer-events: none via CSS. For
|
||||
// <button>, the native `disabled` attribute is the right tool.
|
||||
if (props.to !== undefined && props.to !== null) {
|
||||
return {
|
||||
to: props.to,
|
||||
ariaDisabled: props.disabled ? "true" : undefined,
|
||||
};
|
||||
}
|
||||
if (props.href !== undefined && props.href !== null) {
|
||||
return {
|
||||
// Strip the href entirely when disabled so keyboard activation
|
||||
// doesn't fire — links can't be `disabled` natively.
|
||||
href: props.disabled ? undefined : props.href,
|
||||
target: props.target,
|
||||
ariaDisabled: props.disabled ? "true" : undefined,
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: props.type,
|
||||
disabled: props.disabled,
|
||||
};
|
||||
});
|
||||
|
||||
// ── Tone resolver ────────────────────────────────────────────────
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
const resolvedColor = computed<string | undefined>(() => {
|
||||
const c = props.color;
|
||||
if (!c) return undefined;
|
||||
return TONE_MAP[c] ?? c;
|
||||
});
|
||||
|
||||
// ── Rounded resolver ─────────────────────────────────────────────
|
||||
const ROUNDED_MAP: Record<string, string> = {
|
||||
"0": "0",
|
||||
sm: "4px",
|
||||
md: "8px",
|
||||
lg: "12px",
|
||||
xl: "16px",
|
||||
full: "999px",
|
||||
pill: "999px",
|
||||
circle: "50%",
|
||||
};
|
||||
const resolvedRounded = computed<string>(() => {
|
||||
const r = props.rounded;
|
||||
if (r === undefined || r === null || r === "") return "8px";
|
||||
if (r === true) return "999px";
|
||||
if (r === false) return "0";
|
||||
if (typeof r === "number") return `${r}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(r as string)) return `${r}px`;
|
||||
return ROUNDED_MAP[r as string] ?? String(r);
|
||||
});
|
||||
|
||||
// ── Icon-only detection ──────────────────────────────────────────
|
||||
const iconString = computed<string | undefined>(() =>
|
||||
typeof props.icon === "string" ? props.icon : undefined,
|
||||
);
|
||||
const isIconBtn = computed(
|
||||
() =>
|
||||
props.icon === true ||
|
||||
(typeof props.icon === "string" && props.icon.length > 0),
|
||||
);
|
||||
|
||||
// ── Debounced loading ────────────────────────────────────────────
|
||||
const debouncedLoading = ref(false);
|
||||
let pendingTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
@@ -90,80 +198,361 @@ watch(
|
||||
);
|
||||
|
||||
onBeforeUnmount(clearTimer);
|
||||
|
||||
// Spinner size scales with the button — readable across the ladder.
|
||||
const spinnerSize = computed(() => {
|
||||
switch (props.size) {
|
||||
case "x-small":
|
||||
return 12;
|
||||
case "small":
|
||||
return 14;
|
||||
case "large":
|
||||
return 18;
|
||||
case "x-large":
|
||||
return 20;
|
||||
default:
|
||||
return 16;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VBtn
|
||||
v-bind="$attrs"
|
||||
<component
|
||||
:is="elementType"
|
||||
v-bind="{ ...$attrs, ...dynamicAttrs }"
|
||||
class="r-btn"
|
||||
:class="{ 'r-btn--border': border }"
|
||||
:variant="variant"
|
||||
:color="color"
|
||||
:rounded="rounded"
|
||||
:loading="debouncedLoading"
|
||||
:disabled="disabled"
|
||||
:block="block"
|
||||
:size="size"
|
||||
:density="density"
|
||||
:icon="icon"
|
||||
:ripple="ripple"
|
||||
:prepend-icon="prependIcon"
|
||||
:append-icon="appendIcon"
|
||||
:type="type"
|
||||
:class="[
|
||||
`r-btn--${variant}`,
|
||||
`r-btn--${size}`,
|
||||
`r-btn--density-${density}`,
|
||||
{
|
||||
'r-btn--has-color': !!resolvedColor,
|
||||
'r-btn--icon': isIconBtn,
|
||||
'r-btn--block': block,
|
||||
'r-btn--loading': debouncedLoading,
|
||||
'r-btn--disabled': disabled,
|
||||
'r-btn--border': border,
|
||||
},
|
||||
]"
|
||||
:style="{
|
||||
borderRadius: resolvedRounded,
|
||||
'--r-btn-color': resolvedColor,
|
||||
}"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VBtn>
|
||||
<!-- Loading spinner — overlays content while debouncedLoading is on.
|
||||
Lives in absolute positioning so the button's intrinsic width
|
||||
doesn't change between loading and idle states (no layout
|
||||
shift mid-action). -->
|
||||
<span v-if="debouncedLoading" class="r-btn__loader" aria-hidden="true">
|
||||
<RProgressCircular indeterminate :size="spinnerSize" :width="2" />
|
||||
</span>
|
||||
|
||||
<span
|
||||
class="r-btn__content"
|
||||
:class="{ 'r-btn__content--hidden': debouncedLoading }"
|
||||
>
|
||||
<!-- Prepend zone — slot wins over prop. -->
|
||||
<span
|
||||
v-if="slots.prepend || (prependIcon && !isIconBtn)"
|
||||
class="r-btn__prepend"
|
||||
>
|
||||
<slot name="prepend">
|
||||
<RIcon v-if="prependIcon" :icon="prependIcon" />
|
||||
</slot>
|
||||
</span>
|
||||
|
||||
<!-- Icon-only mode: icon takes the spot of the label. -->
|
||||
<RIcon
|
||||
v-if="isIconBtn && iconString"
|
||||
:icon="iconString"
|
||||
class="r-btn__icon"
|
||||
/>
|
||||
|
||||
<!-- Default label slot — hidden in icon-only mode. -->
|
||||
<span v-if="!isIconBtn && slots.default" class="r-btn__label">
|
||||
<slot />
|
||||
</span>
|
||||
|
||||
<!-- Append zone. -->
|
||||
<span
|
||||
v-if="slots.append || (appendIcon && !isIconBtn)"
|
||||
class="r-btn__append"
|
||||
>
|
||||
<slot name="append">
|
||||
<RIcon v-if="appendIcon" :icon="appendIcon" />
|
||||
</slot>
|
||||
</span>
|
||||
</span>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* ── Base ──────────────────────────────────────────────────────── */
|
||||
.r-btn {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
border: 1px solid transparent;
|
||||
font-family: inherit;
|
||||
font-weight: var(--r-font-weight-medium);
|
||||
letter-spacing: 0;
|
||||
text-transform: none;
|
||||
/* Slightly muted at rest, fully illuminated on hover — same feel as
|
||||
GameActionBtn over cover art. Applied via opacity so it composes
|
||||
with any color (default/primary/error/...): the whole button —
|
||||
text, border, icon, background — brightens together on hover.
|
||||
Vuetify's own hover overlay still adds the bg lift on top. */
|
||||
opacity: 0.8;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
user-select: none;
|
||||
cursor: pointer;
|
||||
/* Suppress native button defaults. */
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
outline: none;
|
||||
/* Smooth tone / theme / state changes — RSwitch motion language. */
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
box-shadow var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
transform 100ms var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
/* Hover / active overlay — single `::before` painted in currentColor
|
||||
so it composes cleanly with any variant. No per-variant :hover
|
||||
rules; the overlay does the work. */
|
||||
.r-btn::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: currentColor;
|
||||
opacity: 0;
|
||||
border-radius: inherit;
|
||||
pointer-events: none;
|
||||
transition: opacity var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-btn:hover:not(.v-btn--disabled) {
|
||||
opacity: 1;
|
||||
.r-btn:hover:not(.r-btn--disabled, :disabled)::before {
|
||||
opacity: 0.1;
|
||||
}
|
||||
.r-btn:active:not(.r-btn--disabled, :disabled)::before {
|
||||
opacity: 0.18;
|
||||
}
|
||||
|
||||
/* Optical alignment for prepend/append icons.
|
||||
Three things stack to push the icon above the text's optical centre:
|
||||
1. Vuetify scales icons inside v-btn down to ~85% of text size
|
||||
(`.v-btn .v-icon { --v-icon-size-multiplier: 0.857 }`), so the
|
||||
icon sits in a smaller box centred on the line-box.
|
||||
2. The Material Design Icons font draws glyphs slightly above the
|
||||
em-square's geometric centre.
|
||||
3. We render labels in Title Case (text-transform: none, overriding
|
||||
Vuetify's default uppercase), so the visual mass of the label
|
||||
lives in the x-height band — below the line-box centre — while
|
||||
the icon stays at the geometric centre.
|
||||
A stock v-btn hides this because uppercase text shifts the optical
|
||||
centre back up to the cap-height. Nudging prepend/append slots 3px
|
||||
down lines the icon up with the x-height optical centre across our
|
||||
sizes. */
|
||||
.r-btn :deep(.v-btn__prepend),
|
||||
.r-btn :deep(.v-btn__append) {
|
||||
margin-block-start: 3px;
|
||||
/* Press cue — subtle haptic squash. */
|
||||
.r-btn:active:not(.r-btn--disabled, :disabled) {
|
||||
transform: scale(0.97);
|
||||
}
|
||||
|
||||
/* `border` modifier — adds a translucent border in the current text
|
||||
colour. `currentColor` picks up VBtn's text colour, which Vuetify
|
||||
has already painted from the `color` prop, so the border tints in
|
||||
lock-step. Paired with `variant="tonal"` it produces the RTag
|
||||
pill recipe (translucent bg + coloured border + coloured text)
|
||||
for chip-style activators. */
|
||||
/* ── Content / loader layout ──────────────────────────────────── */
|
||||
.r-btn__content {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: inherit;
|
||||
min-width: 0;
|
||||
}
|
||||
.r-btn__content--hidden {
|
||||
/* Keep layout, hide visually so spinner can overlay without shift. */
|
||||
visibility: hidden;
|
||||
}
|
||||
.r-btn__loader {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.r-btn__label {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.r-btn__prepend,
|
||||
.r-btn__append,
|
||||
.r-btn__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* ── Size ladder ───────────────────────────────────────────────── */
|
||||
.r-btn--x-small {
|
||||
height: 20px;
|
||||
padding: 0 8px;
|
||||
font-size: 11px;
|
||||
gap: 4px;
|
||||
}
|
||||
.r-btn--small {
|
||||
height: 28px;
|
||||
padding: 0 12px;
|
||||
font-size: 13px;
|
||||
gap: 6px;
|
||||
}
|
||||
.r-btn--default {
|
||||
height: 36px;
|
||||
padding: 0 16px;
|
||||
font-size: 14px;
|
||||
gap: 8px;
|
||||
}
|
||||
.r-btn--large {
|
||||
height: 44px;
|
||||
padding: 0 20px;
|
||||
font-size: 15px;
|
||||
gap: 10px;
|
||||
}
|
||||
.r-btn--x-large {
|
||||
height: 52px;
|
||||
padding: 0 24px;
|
||||
font-size: 16px;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
/* Icon size scales with text — same 1.2em ratio RIcon uses. */
|
||||
.r-btn .r-btn__prepend > .r-icon,
|
||||
.r-btn .r-btn__append > .r-icon,
|
||||
.r-btn .r-btn__icon {
|
||||
font-size: 1.25em;
|
||||
}
|
||||
|
||||
/* ── Density — slight height compression per Vuetify spec ──────── */
|
||||
.r-btn--density-comfortable {
|
||||
/* -4px from default — keeps the size ladder visually predictable. */
|
||||
height: calc(var(--r-btn-rest-h, auto) - 4px);
|
||||
}
|
||||
.r-btn--density-compact {
|
||||
height: calc(var(--r-btn-rest-h, auto) - 8px);
|
||||
}
|
||||
/* Map each size's rest height for the density calc. */
|
||||
.r-btn--x-small {
|
||||
--r-btn-rest-h: 20px;
|
||||
}
|
||||
.r-btn--small {
|
||||
--r-btn-rest-h: 28px;
|
||||
}
|
||||
.r-btn--default {
|
||||
--r-btn-rest-h: 36px;
|
||||
}
|
||||
.r-btn--large {
|
||||
--r-btn-rest-h: 44px;
|
||||
}
|
||||
.r-btn--x-large {
|
||||
--r-btn-rest-h: 52px;
|
||||
}
|
||||
.r-btn--density-comfortable {
|
||||
height: calc(var(--r-btn-rest-h) - 4px);
|
||||
}
|
||||
.r-btn--density-compact {
|
||||
height: calc(var(--r-btn-rest-h) - 8px);
|
||||
}
|
||||
|
||||
/* ── Icon-only — square hit area ──────────────────────────────── */
|
||||
.r-btn--icon {
|
||||
padding: 0;
|
||||
width: var(--r-btn-rest-h);
|
||||
}
|
||||
.r-btn--icon.r-btn--density-comfortable {
|
||||
width: calc(var(--r-btn-rest-h) - 4px);
|
||||
}
|
||||
.r-btn--icon.r-btn--density-compact {
|
||||
width: calc(var(--r-btn-rest-h) - 8px);
|
||||
}
|
||||
|
||||
/* ── Block — full width ────────────────────────────────────────── */
|
||||
.r-btn--block {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
/* ── Variant: flat — solid fill ────────────────────────────────── */
|
||||
.r-btn--flat.r-btn--has-color {
|
||||
background: var(--r-btn-color);
|
||||
color: white;
|
||||
}
|
||||
.r-btn--flat:not(.r-btn--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Variant: elevated — solid + shadow ────────────────────────── */
|
||||
.r-btn--elevated.r-btn--has-color {
|
||||
background: var(--r-btn-color);
|
||||
color: white;
|
||||
box-shadow: 0 2px 6px color-mix(in srgb, black 22%, transparent);
|
||||
}
|
||||
.r-btn--elevated:not(.r-btn--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
box-shadow: 0 2px 6px color-mix(in srgb, black 18%, transparent);
|
||||
}
|
||||
.r-btn--elevated:hover:not(.r-btn--disabled, :disabled) {
|
||||
box-shadow: 0 4px 10px color-mix(in srgb, black 26%, transparent);
|
||||
}
|
||||
|
||||
/* ── Variant: translucent — color-mix bg, coloured text ────────── */
|
||||
.r-btn--translucent.r-btn--has-color {
|
||||
background: color-mix(in srgb, var(--r-btn-color) 16%, transparent);
|
||||
color: var(--r-btn-color);
|
||||
}
|
||||
.r-btn--translucent:not(.r-btn--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Variant: outlined — border + text in tone ─────────────────── */
|
||||
.r-btn--outlined {
|
||||
background: transparent;
|
||||
}
|
||||
.r-btn--outlined.r-btn--has-color {
|
||||
color: var(--r-btn-color);
|
||||
border-color: color-mix(in srgb, var(--r-btn-color) 50%, transparent);
|
||||
}
|
||||
.r-btn--outlined:not(.r-btn--has-color) {
|
||||
color: var(--r-color-fg);
|
||||
border-color: var(--r-color-border);
|
||||
}
|
||||
|
||||
/* ── Variant: text — transparent, coloured text only ───────────── */
|
||||
.r-btn--text {
|
||||
background: transparent;
|
||||
}
|
||||
.r-btn--text.r-btn--has-color {
|
||||
color: var(--r-btn-color);
|
||||
}
|
||||
.r-btn--text:not(.r-btn--has-color) {
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Variant: plain — zero chrome, inherit ─────────────────────── */
|
||||
.r-btn--plain {
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* ── `border` modifier — translucent currentColor border ───────── */
|
||||
.r-btn--border {
|
||||
border: 1px solid color-mix(in srgb, currentColor 40%, transparent) !important;
|
||||
border-color: color-mix(in srgb, currentColor 40%, transparent);
|
||||
}
|
||||
.r-btn--border:hover:not(.v-btn--disabled) {
|
||||
border-color: color-mix(in srgb, currentColor 65%, transparent) !important;
|
||||
.r-btn--border:hover:not(.r-btn--disabled, :disabled) {
|
||||
border-color: color-mix(in srgb, currentColor 65%, transparent);
|
||||
}
|
||||
|
||||
/* ── Disabled ──────────────────────────────────────────────────── */
|
||||
.r-btn:disabled,
|
||||
.r-btn--disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.45;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* ── Reduced motion — drop the press scale + hover overlay fade ── */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.r-btn,
|
||||
.r-btn::before {
|
||||
transition: none;
|
||||
}
|
||||
.r-btn:active:not(.r-btn--disabled, :disabled) {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -7,8 +7,10 @@ const meta: Meta<typeof RCard> = {
|
||||
argTypes: {
|
||||
variant: {
|
||||
control: "select",
|
||||
options: ["flat", "elevated", "tonal", "outlined", "text", "plain"],
|
||||
options: ["flat", "elevated", "translucent", "outlined", "text", "plain"],
|
||||
},
|
||||
color: { control: "text" },
|
||||
elevation: { control: "number" },
|
||||
rounded: { control: "text" },
|
||||
title: { control: "text" },
|
||||
subtitle: { control: "text" },
|
||||
@@ -20,14 +22,16 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RCard>;
|
||||
|
||||
// ── Defaults ────────────────────────────────────────────────────────
|
||||
|
||||
export const Default: Story = {
|
||||
render: (args) => ({
|
||||
components: { RCard },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<RCard v-bind="args" style="width: 360px; padding: var(--r-space-5);">
|
||||
Content goes here. RCard has a muted border and elevated background
|
||||
from the v2 tokens.
|
||||
Content goes here. RCard has a muted border and an elevated
|
||||
background from the v2 tokens.
|
||||
</RCard>
|
||||
`,
|
||||
}),
|
||||
@@ -40,17 +44,191 @@ export const WithTitle: Story = {
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<RCard v-bind="args" style="width: 360px;">
|
||||
<div style="padding: var(--r-space-5);">Card body</div>
|
||||
<div style="padding: 12px 20px 18px; color: var(--r-color-fg-muted); font: 13px/1.4 sans-serif;">
|
||||
3 platforms scanned · 18 new ROMs · 4 missing.
|
||||
</div>
|
||||
</RCard>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Outlined: Story = {
|
||||
args: { variant: "outlined" },
|
||||
render: (args) => ({
|
||||
// ── Variants ────────────────────────────────────────────────────────
|
||||
|
||||
export const Variants: Story = {
|
||||
render: () => ({
|
||||
components: { RCard },
|
||||
setup: () => ({ args }),
|
||||
template: `<RCard v-bind="args" style="width: 360px; padding: var(--r-space-5);">Outlined card</RCard>`,
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:16px;width:720px">
|
||||
<RCard variant="flat" style="padding:18px"><strong>flat</strong> · default surface + border</RCard>
|
||||
<RCard variant="elevated" style="padding:18px"><strong>elevated</strong> · surface + shadow</RCard>
|
||||
<RCard variant="translucent" color="primary" style="padding:18px"><strong>translucent</strong> · tinted</RCard>
|
||||
<RCard variant="outlined" style="padding:18px"><strong>outlined</strong> · border-only</RCard>
|
||||
<RCard variant="text" color="primary" style="padding:18px"><strong>text</strong> · just coloured text</RCard>
|
||||
<RCard variant="plain" style="padding:18px"><strong>plain</strong> · zero chrome</RCard>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Tones ───────────────────────────────────────────────────────────
|
||||
|
||||
export const Tones: Story = {
|
||||
name: "Tones · translucent",
|
||||
render: () => ({
|
||||
components: { RCard },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:12px;width:720px">
|
||||
<RCard variant="translucent" color="primary" style="padding:14px">primary</RCard>
|
||||
<RCard variant="translucent" color="secondary" style="padding:14px">secondary</RCard>
|
||||
<RCard variant="translucent" color="accent" style="padding:14px">accent</RCard>
|
||||
<RCard variant="translucent" color="success" style="padding:14px">success</RCard>
|
||||
<RCard variant="translucent" color="warning" style="padding:14px">warning</RCard>
|
||||
<RCard variant="translucent" color="danger" style="padding:14px">danger</RCard>
|
||||
<RCard variant="translucent" color="info" style="padding:14px">info</RCard>
|
||||
<RCard variant="translucent" style="padding:14px">neutral</RCard>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Elevation ───────────────────────────────────────────────────────
|
||||
|
||||
export const ElevationLadder: Story = {
|
||||
name: "Elevation ladder",
|
||||
render: () => ({
|
||||
components: { RCard },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:36px;width:720px;padding:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:10px">
|
||||
<RCard variant="elevated" :elevation="0" style="width:160px;padding:18px">e=0</RCard>
|
||||
<span>0 (none)</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:10px">
|
||||
<RCard variant="elevated" :elevation="1" style="width:160px;padding:18px">e=1</RCard>
|
||||
<span>1</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:10px">
|
||||
<RCard variant="elevated" :elevation="2" style="width:160px;padding:18px">e=2</RCard>
|
||||
<span>2</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:10px">
|
||||
<RCard variant="elevated" :elevation="4" style="width:160px;padding:18px">e=4</RCard>
|
||||
<span>4</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:10px">
|
||||
<RCard variant="elevated" :elevation="8" style="width:160px;padding:18px">e=8</RCard>
|
||||
<span>8</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:10px">
|
||||
<RCard variant="elevated" :elevation="16" style="width:160px;padding:18px">e=16</RCard>
|
||||
<span>16</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:10px">
|
||||
<RCard variant="elevated" :elevation="24" style="width:160px;padding:18px">e=24</RCard>
|
||||
<span>24</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Rounded ─────────────────────────────────────────────────────────
|
||||
|
||||
export const RoundedLadder: Story = {
|
||||
name: "Rounded ladder",
|
||||
render: () => ({
|
||||
components: { RCard },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:16px;width:720px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RCard :rounded="0" style="width:160px;padding:18px">rounded 0</RCard>
|
||||
<span>0</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RCard rounded="sm" style="width:160px;padding:18px">rounded sm</RCard>
|
||||
<span>sm · 4</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RCard rounded="md" style="width:160px;padding:18px">rounded md</RCard>
|
||||
<span>md · 8</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RCard rounded="lg" style="width:160px;padding:18px">rounded lg</RCard>
|
||||
<span>lg · 12 (default)</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RCard rounded="xl" style="width:160px;padding:18px">rounded xl</RCard>
|
||||
<span>xl · 16</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RCard :rounded="24" style="width:160px;padding:18px">rounded 24</RCard>
|
||||
<span>24px</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Loading ─────────────────────────────────────────────────────────
|
||||
|
||||
export const Loading: Story = {
|
||||
name: "Loading bar",
|
||||
render: () => ({
|
||||
components: { RCard },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:18px;width:360px">
|
||||
<RCard loading title="Fetching metadata" subtitle="Connecting to IGDB…">
|
||||
<div style="padding:8px 20px 18px;color:var(--r-color-fg-muted);font:12px/1.4 sans-serif">
|
||||
Card content stays visible while the bar slides at the top.
|
||||
</div>
|
||||
</RCard>
|
||||
<RCard loading variant="elevated" :elevation="4" color="primary">
|
||||
<div style="padding:18px 20px;font:12px/1.4 sans-serif">
|
||||
Loading bar adapts to the card's tone (uses <code>--r-card-color</code> when present).
|
||||
</div>
|
||||
</RCard>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world ──────────────────────────────────────────────────────
|
||||
|
||||
export const AuthCardSim: Story = {
|
||||
name: "AuthCard reproduction",
|
||||
render: () => ({
|
||||
components: { RCard },
|
||||
template: `
|
||||
<RCard variant="elevated" :elevation="4" style="width:320px">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:18px;padding:24px">
|
||||
<div style="width:80px;height:80px;border-radius:18px;background:var(--r-color-brand-primary);display:flex;align-items:center;justify-content:center;color:white;font:700 22px/1 sans-serif">R</div>
|
||||
<h2 style="margin:0;font:600 18px/1.2 sans-serif">Welcome back</h2>
|
||||
<p style="margin:0;color:var(--r-color-fg-muted);font:13px/1.4 sans-serif;text-align:center">Sign in to your RomM library</p>
|
||||
</div>
|
||||
</RCard>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const SettingsPanel: Story = {
|
||||
name: "Settings panel (Player usage)",
|
||||
render: () => ({
|
||||
components: { RCard },
|
||||
template: `
|
||||
<RCard variant="flat" style="width:320px">
|
||||
<div style="display:flex;align-items:center;gap:8px;padding:12px 16px;color:var(--r-color-fg-muted);font:11px/1 sans-serif;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;border-bottom:1px solid var(--r-color-border)">
|
||||
Settings
|
||||
</div>
|
||||
<div style="padding:14px 16px;font:13px/1.5 sans-serif;color:var(--r-color-fg)">
|
||||
<div style="margin-bottom:6px;color:var(--r-color-fg-muted)">Background color</div>
|
||||
<div style="display:flex;gap:8px">
|
||||
<div style="width:28px;height:28px;border-radius:6px;background:var(--r-color-brand-primary);cursor:pointer"></div>
|
||||
<div style="width:28px;height:28px;border-radius:6px;background:var(--r-color-success);cursor:pointer"></div>
|
||||
<div style="width:28px;height:28px;border-radius:6px;background:var(--r-color-warning);cursor:pointer"></div>
|
||||
<div style="width:28px;height:28px;border-radius:6px;background:var(--r-color-danger);cursor:pointer"></div>
|
||||
</div>
|
||||
</div>
|
||||
</RCard>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,47 +1,312 @@
|
||||
<script setup lang="ts">
|
||||
import { VCard } from "vuetify/components/VCard";
|
||||
// RCard — Vuetify-free. Plain surface container with six variants, a
|
||||
// thin loading bar, optional title / subtitle header, and the shared
|
||||
// rounded / tone / elevation resolvers from the rest of the lib.
|
||||
//
|
||||
// No default padding — Vuetify added body padding implicitly and every
|
||||
// consumer fought it back out. RCard keeps its body slot raw; pad
|
||||
// from outside or wrap an inner `<div>` (the `auth-card__inner` /
|
||||
// `r-v2-ejs__panel-head` patterns already do this).
|
||||
//
|
||||
// Variants:
|
||||
// • flat — surface fill + 1px border. The default — matches
|
||||
// the existing v2 card paint.
|
||||
// • elevated — surface fill + box-shadow (no border).
|
||||
// • translucent — `color-mix` of the resolved colour over transparent.
|
||||
// • outlined — transparent fill + 1px coloured border.
|
||||
// • text — transparent fill, just a tone colour for the text.
|
||||
// • plain — zero chrome; inherit everything.
|
||||
//
|
||||
// `elevation` (0–24) maps to discrete box-shadow steps. Off-key values
|
||||
// snap down to the nearest tabulated step so a card stays in the
|
||||
// design system even if a consumer passes 5 or 9.
|
||||
import { computed, useSlots } from "vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface Props {
|
||||
variant?: "flat" | "elevated" | "tonal" | "outlined" | "text" | "plain";
|
||||
variant?: "flat" | "elevated" | "translucent" | "outlined" | "text" | "plain";
|
||||
color?: string;
|
||||
elevation?: number | string;
|
||||
rounded?: string | number | boolean;
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
/** Thin animated bar at the top of the card — indicator that the
|
||||
* card's content is updating in place. */
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
variant: "flat",
|
||||
color: undefined,
|
||||
elevation: undefined,
|
||||
rounded: "lg",
|
||||
title: undefined,
|
||||
subtitle: undefined,
|
||||
loading: false,
|
||||
});
|
||||
|
||||
const slots = useSlots();
|
||||
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
|
||||
const resolvedColor = computed<string | undefined>(() => {
|
||||
const c = props.color;
|
||||
if (!c) return undefined;
|
||||
return TONE_MAP[c] ?? c;
|
||||
});
|
||||
|
||||
const ROUNDED_MAP: Record<string, string> = {
|
||||
"0": "0",
|
||||
sm: "4px",
|
||||
md: "8px",
|
||||
lg: "12px",
|
||||
xl: "16px",
|
||||
full: "999px",
|
||||
pill: "999px",
|
||||
circle: "50%",
|
||||
};
|
||||
|
||||
const resolvedRounded = computed<string>(() => {
|
||||
const r = props.rounded;
|
||||
if (r === undefined || r === null || r === "") return "12px";
|
||||
if (r === true) return "999px";
|
||||
if (r === false) return "0";
|
||||
if (typeof r === "number") return `${r}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(r as string)) return `${r}px`;
|
||||
return ROUNDED_MAP[r as string] ?? String(r);
|
||||
});
|
||||
|
||||
// Elevation map — discrete shadow steps. Off-key values snap down to
|
||||
// the nearest tabulated step so a stray `elevation=5` still lands on
|
||||
// a system-approved shadow instead of a unique one-off.
|
||||
const ELEVATION_MAP: Record<number, string> = {
|
||||
0: "none",
|
||||
1: "0 1px 2px color-mix(in srgb, black 14%, transparent)",
|
||||
2: "0 2px 4px color-mix(in srgb, black 16%, transparent)",
|
||||
4: "0 4px 10px color-mix(in srgb, black 20%, transparent)",
|
||||
6: "0 6px 14px color-mix(in srgb, black 22%, transparent)",
|
||||
8: "0 8px 18px color-mix(in srgb, black 26%, transparent)",
|
||||
12: "0 12px 26px color-mix(in srgb, black 28%, transparent)",
|
||||
16: "0 14px 30px color-mix(in srgb, black 30%, transparent)",
|
||||
24: "0 18px 36px color-mix(in srgb, black 35%, transparent)",
|
||||
};
|
||||
const ELEVATION_KEYS = Object.keys(ELEVATION_MAP)
|
||||
.map(Number)
|
||||
.sort((a, b) => a - b);
|
||||
|
||||
const resolvedElevation = computed<string | undefined>(() => {
|
||||
const e = props.elevation;
|
||||
if (e === undefined || e === null) return undefined;
|
||||
const n = typeof e === "number" ? e : Number(e);
|
||||
if (!Number.isFinite(n)) return undefined;
|
||||
if (n <= 0) return ELEVATION_MAP[0];
|
||||
// Snap down to the largest tabulated key ≤ n.
|
||||
let best = ELEVATION_KEYS[0];
|
||||
for (const k of ELEVATION_KEYS) {
|
||||
if (k <= n) best = k;
|
||||
}
|
||||
return ELEVATION_MAP[best];
|
||||
});
|
||||
|
||||
const hasHeader = computed(
|
||||
() => !!props.title || !!props.subtitle || !!slots.title || !!slots.subtitle,
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VCard
|
||||
<div
|
||||
v-bind="$attrs"
|
||||
class="r-card"
|
||||
:variant="variant"
|
||||
:elevation="elevation"
|
||||
:rounded="rounded"
|
||||
:title="title"
|
||||
:subtitle="subtitle"
|
||||
:loading="loading"
|
||||
:class="[
|
||||
`r-card--${variant}`,
|
||||
{
|
||||
'r-card--has-color': !!resolvedColor,
|
||||
'r-card--loading': loading,
|
||||
},
|
||||
]"
|
||||
:style="{
|
||||
borderRadius: resolvedRounded,
|
||||
boxShadow: resolvedElevation,
|
||||
'--r-card-color': resolvedColor,
|
||||
}"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VCard>
|
||||
<!-- Loading bar at the top. The bar lives inside the card so it
|
||||
clips to the rounded corners cleanly. -->
|
||||
<div v-if="loading" class="r-card__loading" aria-hidden="true">
|
||||
<span class="r-card__loading-bar" />
|
||||
</div>
|
||||
|
||||
<!-- Optional title / subtitle header. Slots win over props when
|
||||
the consumer wants richer content. -->
|
||||
<div v-if="hasHeader" class="r-card__header">
|
||||
<div v-if="title || slots.title" class="r-card__title">
|
||||
<slot name="title">{{ title }}</slot>
|
||||
</div>
|
||||
<div v-if="subtitle || slots.subtitle" class="r-card__subtitle">
|
||||
<slot name="subtitle">{{ subtitle }}</slot>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-card {
|
||||
background-color: var(--r-color-bg-elevated);
|
||||
position: relative;
|
||||
display: block;
|
||||
color: var(--r-color-fg);
|
||||
overflow: hidden;
|
||||
/* Smooth tone / theme / elevation changes so a swap doesn't pop. */
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
box-shadow var(--r-motion-base) var(--r-motion-ease-out),
|
||||
color var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
/* ── Variant: flat — surface + 1px border (the v2 default look) ── */
|
||||
.r-card--flat {
|
||||
background: var(--r-color-bg-elevated);
|
||||
border: 1px solid var(--r-color-border);
|
||||
}
|
||||
.r-card--flat.r-card--has-color {
|
||||
background: var(--r-card-color);
|
||||
color: white;
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
/* ── Variant: elevated — surface + drop shadow, no border ─────── */
|
||||
.r-card--elevated {
|
||||
background: var(--r-color-bg-elevated);
|
||||
border: 1px solid transparent;
|
||||
/* When `elevation` prop is unset we still want a baseline shadow so
|
||||
`elevated` reads different from `flat`. Inline `boxShadow` from
|
||||
the prop overrides this. */
|
||||
box-shadow: 0 4px 10px color-mix(in srgb, black 20%, transparent);
|
||||
}
|
||||
.r-card--elevated.r-card--has-color {
|
||||
background: var(--r-card-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* ── Variant: translucent — color-mix tint, coloured text ─────── */
|
||||
.r-card--translucent {
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
.r-card--translucent.r-card--has-color {
|
||||
background: color-mix(in srgb, var(--r-card-color) 14%, transparent);
|
||||
color: var(--r-card-color);
|
||||
}
|
||||
.r-card--translucent:not(.r-card--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Variant: outlined — transparent + border ──────────────────── */
|
||||
.r-card--outlined {
|
||||
background: transparent;
|
||||
}
|
||||
.r-card--outlined.r-card--has-color {
|
||||
color: var(--r-card-color);
|
||||
border: 1px solid color-mix(in srgb, var(--r-card-color) 50%, transparent);
|
||||
}
|
||||
.r-card--outlined:not(.r-card--has-color) {
|
||||
border: 1px solid var(--r-color-border);
|
||||
}
|
||||
|
||||
/* ── Variant: text — no chrome, just coloured text ─────────────── */
|
||||
.r-card--text {
|
||||
background: transparent;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
.r-card--text.r-card--has-color {
|
||||
color: var(--r-card-color);
|
||||
}
|
||||
|
||||
/* ── Variant: plain — fully unstyled ───────────────────────────── */
|
||||
.r-card--plain {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* ── Loading bar ───────────────────────────────────────────────── */
|
||||
.r-card__loading {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 2px;
|
||||
overflow: hidden;
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--r-card-color, var(--r-color-brand-primary)) 22%,
|
||||
transparent
|
||||
);
|
||||
z-index: 1;
|
||||
}
|
||||
.r-card__loading-bar {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: var(--r-card-color, var(--r-color-brand-primary));
|
||||
/* Sliding bar from off-left to off-right. The 30% width keeps the
|
||||
bar readable without filling the whole track. */
|
||||
width: 30%;
|
||||
animation: r-card-loading 1.4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes r-card-loading {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(400%);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Header (title / subtitle) ─────────────────────────────────── */
|
||||
.r-card__header {
|
||||
padding: 16px 20px 8px;
|
||||
}
|
||||
.r-card__title {
|
||||
font-size: var(--r-font-size-md, 15px);
|
||||
font-weight: var(--r-font-weight-semibold);
|
||||
line-height: 1.3;
|
||||
}
|
||||
.r-card__subtitle {
|
||||
margin-top: 4px;
|
||||
font-size: var(--r-font-size-sm, 12px);
|
||||
color: var(--r-color-fg-muted);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* When loading is on, push the header down a hair so the bar isn't
|
||||
pressed against the title — only when there's actually a header. */
|
||||
.r-card--loading .r-card__header {
|
||||
padding-top: 18px;
|
||||
}
|
||||
|
||||
/* ── Reduced motion — drop the loading slide ──────────────────── */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.r-card__loading-bar {
|
||||
animation: none;
|
||||
width: 100%;
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { ref } from "vue";
|
||||
import RChip from "./RChip.vue";
|
||||
|
||||
const meta: Meta<typeof RChip> = {
|
||||
@@ -7,40 +8,257 @@ const meta: Meta<typeof RChip> = {
|
||||
argTypes: {
|
||||
variant: {
|
||||
control: "select",
|
||||
options: ["flat", "text", "elevated", "tonal", "outlined", "plain"],
|
||||
options: ["flat", "text", "elevated", "translucent", "outlined", "plain"],
|
||||
},
|
||||
color: { control: "text" },
|
||||
size: {
|
||||
control: "select",
|
||||
options: ["x-small", "small", "default", "large", "x-large"],
|
||||
},
|
||||
rounded: { control: "text" },
|
||||
color: { control: "text" },
|
||||
label: { control: "boolean" },
|
||||
closable: { control: "boolean" },
|
||||
disabled: { control: "boolean" },
|
||||
prependIcon: { control: "text" },
|
||||
appendIcon: { control: "text" },
|
||||
disabled: { control: "boolean" },
|
||||
rounded: { control: "text" },
|
||||
},
|
||||
render: (args) => ({
|
||||
components: { RChip },
|
||||
setup: () => ({ args }),
|
||||
template: `<RChip v-bind="args">{{ args.text ?? 'Action' }}</RChip>`,
|
||||
}),
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RChip>;
|
||||
|
||||
export const Default: Story = {};
|
||||
export const WithIcon: Story = { args: { prependIcon: "mdi-star" } };
|
||||
export const Success: Story = { args: { color: "success" } };
|
||||
export const Outlined: Story = { args: { variant: "outlined" } };
|
||||
export const Label: Story = { args: { label: true, prependIcon: "mdi-tag" } };
|
||||
export const Closable: Story = {
|
||||
args: { closable: true, color: "primary" },
|
||||
// ── Defaults ────────────────────────────────────────────────────────
|
||||
|
||||
export const Default: Story = {
|
||||
args: { variant: "translucent" },
|
||||
render: (args) => ({
|
||||
components: { RChip },
|
||||
setup: () => ({ args }),
|
||||
template: `<RChip v-bind="args">Filter: Genre</RChip>`,
|
||||
template: `<RChip v-bind="args">Action</RChip>`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const WithIcons: Story = {
|
||||
args: {
|
||||
variant: "translucent",
|
||||
color: "primary",
|
||||
prependIcon: "mdi-filter-outline",
|
||||
appendIcon: "mdi-menu-down",
|
||||
},
|
||||
render: (args) => ({
|
||||
components: { RChip },
|
||||
setup: () => ({ args }),
|
||||
template: `<RChip v-bind="args">Genre</RChip>`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Size ladder ─────────────────────────────────────────────────────
|
||||
|
||||
export const SizeLadder: Story = {
|
||||
name: "Size ladder",
|
||||
render: () => ({
|
||||
components: { RChip },
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:18px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RChip variant="translucent" color="primary" size="x-small">x-small</RChip>
|
||||
<span>20px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RChip variant="translucent" color="primary" size="small">small</RChip>
|
||||
<span>24px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RChip variant="translucent" color="primary" size="default">default</RChip>
|
||||
<span>32px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RChip variant="translucent" color="primary" size="large">large</RChip>
|
||||
<span>40px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RChip variant="translucent" color="primary" size="x-large">x-large</RChip>
|
||||
<span>48px</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Variants ────────────────────────────────────────────────────────
|
||||
|
||||
export const Variants: Story = {
|
||||
render: () => ({
|
||||
components: { RChip },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(3,auto);gap:14px 24px;justify-items:center;align-items:center">
|
||||
<RChip variant="flat" color="primary">flat</RChip>
|
||||
<RChip variant="elevated" color="primary">elevated</RChip>
|
||||
<RChip variant="translucent" color="primary">translucent</RChip>
|
||||
<RChip variant="outlined" color="primary">outlined</RChip>
|
||||
<RChip variant="text" color="primary">text</RChip>
|
||||
<RChip variant="plain" color="primary">plain</RChip>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Tones ───────────────────────────────────────────────────────────
|
||||
|
||||
export const Tones: Story = {
|
||||
name: "Tones · translucent",
|
||||
render: () => ({
|
||||
components: { RChip },
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:8px;max-width:520px">
|
||||
<RChip variant="translucent" color="primary" prepend-icon="mdi-shape">primary</RChip>
|
||||
<RChip variant="translucent" color="secondary" prepend-icon="mdi-shape">secondary</RChip>
|
||||
<RChip variant="translucent" color="accent" prepend-icon="mdi-shape">accent</RChip>
|
||||
<RChip variant="translucent" color="success" prepend-icon="mdi-check">success</RChip>
|
||||
<RChip variant="translucent" color="warning" prepend-icon="mdi-alert">warning</RChip>
|
||||
<RChip variant="translucent" color="danger" prepend-icon="mdi-close-octagon">danger</RChip>
|
||||
<RChip variant="translucent" color="info" prepend-icon="mdi-information">info</RChip>
|
||||
<RChip variant="translucent">neutral</RChip>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const TonesFlat: Story = {
|
||||
name: "Tones · flat",
|
||||
render: () => ({
|
||||
components: { RChip },
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:8px;max-width:520px">
|
||||
<RChip variant="flat" color="primary">primary</RChip>
|
||||
<RChip variant="flat" color="secondary">secondary</RChip>
|
||||
<RChip variant="flat" color="accent">accent</RChip>
|
||||
<RChip variant="flat" color="success">success</RChip>
|
||||
<RChip variant="flat" color="warning">warning</RChip>
|
||||
<RChip variant="flat" color="danger">danger</RChip>
|
||||
<RChip variant="flat" color="info">info</RChip>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Shape ───────────────────────────────────────────────────────────
|
||||
|
||||
export const Label: Story = {
|
||||
name: "Label (square corners)",
|
||||
render: () => ({
|
||||
components: { RChip },
|
||||
template: `
|
||||
<div style="display:flex;gap:14px;align-items:center">
|
||||
<RChip variant="translucent" color="primary">Pill (default)</RChip>
|
||||
<RChip variant="translucent" color="primary" label>Label · square</RChip>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const RoundedLadder: Story = {
|
||||
name: "Rounded override",
|
||||
render: () => ({
|
||||
components: { RChip },
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:10px">
|
||||
<RChip variant="translucent" color="primary" :rounded="0">0</RChip>
|
||||
<RChip variant="translucent" color="primary" rounded="sm">sm</RChip>
|
||||
<RChip variant="translucent" color="primary" rounded="md">md</RChip>
|
||||
<RChip variant="translucent" color="primary" rounded="lg">lg</RChip>
|
||||
<RChip variant="translucent" color="primary" rounded="xl">xl</RChip>
|
||||
<RChip variant="translucent" color="primary" :rounded="20">20px</RChip>
|
||||
<RChip variant="translucent" color="primary" rounded="full">full / pill</RChip>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Closable ────────────────────────────────────────────────────────
|
||||
|
||||
export const Closable: Story = {
|
||||
name: "Closable (interactive)",
|
||||
render: () => ({
|
||||
components: { RChip },
|
||||
setup() {
|
||||
const initial = [
|
||||
{ id: 1, label: "Adventure", color: "primary" },
|
||||
{ id: 2, label: "Platformer", color: "accent" },
|
||||
{ id: 3, label: "JRPG", color: "info" },
|
||||
{ id: 4, label: "Co-op", color: "success" },
|
||||
];
|
||||
const tags = ref([...initial]);
|
||||
function remove(id: number) {
|
||||
tags.value = tags.value.filter((t) => t.id !== id);
|
||||
}
|
||||
function reset() {
|
||||
tags.value = [...initial];
|
||||
}
|
||||
return { tags, remove, reset };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:14px;align-items:flex-start">
|
||||
<div style="display:flex;flex-wrap:wrap;gap:8px;max-width:420px">
|
||||
<RChip
|
||||
v-for="t in tags"
|
||||
:key="t.id"
|
||||
variant="translucent"
|
||||
:color="t.color"
|
||||
closable
|
||||
@click:close="remove(t.id)"
|
||||
>
|
||||
{{ t.label }}
|
||||
</RChip>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
style="padding:6px 12px;background:var(--r-color-brand-primary);color:white;border:none;border-radius:6px;font:12px/1 sans-serif;cursor:pointer"
|
||||
@click="reset"
|
||||
>
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Disabled ────────────────────────────────────────────────────────
|
||||
|
||||
export const Disabled: Story = {
|
||||
render: () => ({
|
||||
components: { RChip },
|
||||
template: `
|
||||
<div style="display:flex;flex-wrap:wrap;gap:10px">
|
||||
<RChip variant="translucent" color="primary" disabled>Disabled translucent</RChip>
|
||||
<RChip variant="flat" color="primary" disabled>Disabled flat</RChip>
|
||||
<RChip variant="outlined" color="primary" disabled>Disabled outlined</RChip>
|
||||
<RChip variant="translucent" color="primary" closable disabled>With close</RChip>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world ──────────────────────────────────────────────────────
|
||||
|
||||
export const GalleryTags: Story = {
|
||||
name: "Tag row (Platform / Collection usage)",
|
||||
render: () => ({
|
||||
components: { RChip },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:14px">
|
||||
<div style="display:flex;flex-wrap:wrap;gap:6px">
|
||||
<RChip size="x-small" variant="translucent" color="primary">JP</RChip>
|
||||
<RChip size="x-small" variant="translucent" color="primary">EU</RChip>
|
||||
<RChip size="x-small" variant="translucent" color="primary">USA</RChip>
|
||||
</div>
|
||||
<div style="display:flex;flex-wrap:wrap;gap:6px">
|
||||
<RChip size="small" variant="translucent" :rounded="20">Adventure</RChip>
|
||||
<RChip size="small" variant="translucent" :rounded="20">Platformer</RChip>
|
||||
<RChip size="small" variant="translucent" :rounded="20">2D</RChip>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,78 +1,357 @@
|
||||
<script setup lang="ts">
|
||||
import { VChip } from "vuetify/components/VChip";
|
||||
// RChip — Vuetify-free. Inline-flex pill / square label with prepend +
|
||||
// append icons, optional close button, six variants, and the v2 size
|
||||
// ladder.
|
||||
//
|
||||
// Visual vocabulary matches the rest of the lib: TONE_MAP for colours,
|
||||
// translucent fills via `color-mix`, hover lift via opacity + scale.
|
||||
// Clickable behaviour comes naturally — pass an `@click` listener via
|
||||
// `$attrs` and the chip becomes a hit target (the hover transition
|
||||
// already makes it feel interactive).
|
||||
//
|
||||
// `closable` renders an X button at the trailing edge that emits
|
||||
// `click:close`. The close button stops propagation so chip clicks
|
||||
// don't fire when the user is just dismissing it.
|
||||
//
|
||||
// `label` makes the chip square-cornered (mostly used for tags inline
|
||||
// in lists). `rounded` overrides the default pill / label radius if
|
||||
// you need a specific radius.
|
||||
import { computed } from "vue";
|
||||
import RIcon from "../RIcon/RIcon.vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface Props {
|
||||
variant?: "flat" | "text" | "elevated" | "tonal" | "outlined" | "plain";
|
||||
variant?: "flat" | "text" | "elevated" | "translucent" | "outlined" | "plain";
|
||||
color?: string;
|
||||
size?: "x-small" | "small" | "default" | "large" | "x-large";
|
||||
/** Square corners (small radius) — typical of inline metadata tags. */
|
||||
label?: boolean;
|
||||
/** Renders a trailing × button that emits `click:close`. */
|
||||
closable?: boolean;
|
||||
prependIcon?: string;
|
||||
appendIcon?: string;
|
||||
disabled?: boolean;
|
||||
/** Overrides the chip's default radius. `false`/`"0"` → square,
|
||||
* `"full"`/`true` → pill (999px), `"sm"`/`"md"`/`"lg"`/`"xl"` →
|
||||
* token radii, number → px. */
|
||||
rounded?: string | number | boolean;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
variant: "tonal",
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
variant: "translucent",
|
||||
color: undefined,
|
||||
size: "default",
|
||||
label: false,
|
||||
closable: false,
|
||||
prependIcon: undefined,
|
||||
appendIcon: undefined,
|
||||
rounded: "full",
|
||||
disabled: false,
|
||||
rounded: undefined,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "click:close", evt: MouseEvent): void;
|
||||
}>();
|
||||
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
|
||||
const resolvedColor = computed<string | undefined>(() => {
|
||||
const c = props.color;
|
||||
if (!c) return undefined;
|
||||
return TONE_MAP[c] ?? c;
|
||||
});
|
||||
|
||||
const ROUNDED_MAP: Record<string, string> = {
|
||||
"0": "0",
|
||||
sm: "4px",
|
||||
md: "8px",
|
||||
lg: "12px",
|
||||
xl: "16px",
|
||||
full: "999px",
|
||||
pill: "999px",
|
||||
circle: "50%",
|
||||
};
|
||||
|
||||
const resolvedRounded = computed<string>(() => {
|
||||
const r = props.rounded;
|
||||
if (r === undefined || r === null || r === "") {
|
||||
// Implicit: `label` → small radius, else pill.
|
||||
return props.label ? "4px" : "999px";
|
||||
}
|
||||
if (r === true) return "999px";
|
||||
if (r === false) return "0";
|
||||
if (typeof r === "number") return `${r}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(r as string)) return `${r}px`;
|
||||
return ROUNDED_MAP[r as string] ?? String(r);
|
||||
});
|
||||
|
||||
function onClose(evt: MouseEvent) {
|
||||
evt.stopPropagation();
|
||||
emit("click:close", evt);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VChip
|
||||
<span
|
||||
v-bind="$attrs"
|
||||
class="r-chip"
|
||||
:variant="variant"
|
||||
:color="color"
|
||||
:size="size"
|
||||
:label="label"
|
||||
:closable="closable"
|
||||
:prepend-icon="prependIcon"
|
||||
:append-icon="appendIcon"
|
||||
:disabled="disabled"
|
||||
:rounded="rounded"
|
||||
:class="[
|
||||
`r-chip--${variant}`,
|
||||
`r-chip--${size}`,
|
||||
{
|
||||
'r-chip--has-color': !!resolvedColor,
|
||||
'r-chip--label': label,
|
||||
'r-chip--disabled': disabled,
|
||||
},
|
||||
]"
|
||||
:style="{
|
||||
'--r-chip-color': resolvedColor,
|
||||
borderRadius: resolvedRounded,
|
||||
}"
|
||||
:aria-disabled="disabled || undefined"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VChip>
|
||||
<RIcon
|
||||
v-if="prependIcon"
|
||||
:icon="prependIcon"
|
||||
class="r-chip__icon r-chip__icon--prepend"
|
||||
/>
|
||||
<span class="r-chip__content">
|
||||
<slot />
|
||||
</span>
|
||||
<RIcon
|
||||
v-if="appendIcon"
|
||||
:icon="appendIcon"
|
||||
class="r-chip__icon r-chip__icon--append"
|
||||
/>
|
||||
<button
|
||||
v-if="closable"
|
||||
type="button"
|
||||
class="r-chip__close"
|
||||
aria-label="Remove"
|
||||
:disabled="disabled"
|
||||
@click="onClose"
|
||||
>
|
||||
<RIcon icon="mdi-close" class="r-chip__close-icon" />
|
||||
</button>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
white-space: nowrap;
|
||||
font-weight: var(--r-font-weight-medium);
|
||||
letter-spacing: 0;
|
||||
padding: 0px 16px;
|
||||
}
|
||||
|
||||
/* Clickable chips share the RBtn rest-→-hover illumination: a touch
|
||||
muted at rest, fully bright on hover. Vuetify adds .v-chip--clickable
|
||||
when the `clickable` prop is set, so non-interactive chips (regions,
|
||||
languages, tags…) keep their full opacity. */
|
||||
.r-chip {
|
||||
line-height: 1;
|
||||
border: 1px solid transparent;
|
||||
user-select: none;
|
||||
/* Subtle rest-state mute that brightens on hover — same idiom RBtn
|
||||
uses so chips and buttons share the rest-→-hover feel. Applied to
|
||||
every variant so non-interactive tag chips also feel "alive" when
|
||||
the cursor crosses them. */
|
||||
opacity: 0.85;
|
||||
transition: opacity var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
box-shadow var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
opacity var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
transform var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-chip:hover {
|
||||
.r-chip:hover:not(.r-chip--disabled) {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Optical alignment for prepend/append icons — same fix as RBtn.
|
||||
v-chip never applies text-transform: uppercase, so its mixed-case
|
||||
labels always sit in the x-height band (below the line-box centre)
|
||||
while the icon — sized at ~85% of the text via
|
||||
`.v-chip .v-icon { --v-icon-size-multiplier: 0.857 }` — stays at
|
||||
the line-box geometric centre. A 3px downward nudge lines the icon
|
||||
up with the x-height optical centre. */
|
||||
.r-chip :deep(.v-chip__prepend),
|
||||
.r-chip :deep(.v-chip__append) {
|
||||
margin-block-start: 3px;
|
||||
.r-chip--disabled {
|
||||
opacity: 0.45;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.r-chip__content {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.r-chip__icon {
|
||||
color: inherit;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ── Size ladder — height + horizontal padding + font-size ─────── */
|
||||
.r-chip--x-small {
|
||||
height: 20px;
|
||||
padding: 0 8px;
|
||||
font-size: 10px;
|
||||
gap: 4px;
|
||||
}
|
||||
.r-chip--x-small .r-chip__icon {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.r-chip--small {
|
||||
height: 24px;
|
||||
padding: 0 10px;
|
||||
font-size: 11px;
|
||||
gap: 5px;
|
||||
}
|
||||
.r-chip--small .r-chip__icon {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.r-chip--default {
|
||||
height: 32px;
|
||||
padding: 0 14px;
|
||||
font-size: 13px;
|
||||
gap: 6px;
|
||||
}
|
||||
.r-chip--default .r-chip__icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.r-chip--large {
|
||||
height: 40px;
|
||||
padding: 0 18px;
|
||||
font-size: 15px;
|
||||
gap: 7px;
|
||||
}
|
||||
.r-chip--large .r-chip__icon {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.r-chip--x-large {
|
||||
height: 48px;
|
||||
padding: 0 22px;
|
||||
font-size: 16px;
|
||||
gap: 8px;
|
||||
}
|
||||
.r-chip--x-large .r-chip__icon {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
/* When the chip starts with an icon, trim the leading padding so the
|
||||
icon sits at a consistent visual inset instead of disappearing
|
||||
behind the larger gap. */
|
||||
.r-chip:has(.r-chip__icon--prepend) {
|
||||
padding-inline-start: 8px;
|
||||
}
|
||||
.r-chip:has(.r-chip__icon--append) {
|
||||
padding-inline-end: 8px;
|
||||
}
|
||||
|
||||
/* ── Variant: flat (solid colour fill) ─────────────────────────── */
|
||||
.r-chip--flat.r-chip--has-color {
|
||||
background: var(--r-chip-color);
|
||||
color: white;
|
||||
}
|
||||
.r-chip--flat:not(.r-chip--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
}
|
||||
|
||||
/* ── Variant: elevated (solid + drop shadow) ───────────────────── */
|
||||
.r-chip--elevated.r-chip--has-color {
|
||||
background: var(--r-chip-color);
|
||||
color: white;
|
||||
box-shadow: 0 2px 6px color-mix(in srgb, black 24%, transparent);
|
||||
}
|
||||
.r-chip--elevated:not(.r-chip--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg);
|
||||
box-shadow: 0 2px 6px color-mix(in srgb, black 18%, transparent);
|
||||
}
|
||||
|
||||
/* ── Variant: translucent (translucent + coloured text) ──────────────── */
|
||||
.r-chip--translucent.r-chip--has-color {
|
||||
background: color-mix(in srgb, var(--r-chip-color) 16%, transparent);
|
||||
color: var(--r-chip-color);
|
||||
}
|
||||
.r-chip--translucent:not(.r-chip--has-color) {
|
||||
background: var(--r-color-surface);
|
||||
color: var(--r-color-fg-secondary);
|
||||
}
|
||||
|
||||
/* ── Variant: outlined (border + transparent + coloured text) ──── */
|
||||
.r-chip--outlined {
|
||||
background: transparent;
|
||||
}
|
||||
.r-chip--outlined.r-chip--has-color {
|
||||
color: var(--r-chip-color);
|
||||
border-color: color-mix(in srgb, var(--r-chip-color) 50%, transparent);
|
||||
}
|
||||
.r-chip--outlined:not(.r-chip--has-color) {
|
||||
color: var(--r-color-fg-secondary);
|
||||
border-color: var(--r-color-border);
|
||||
}
|
||||
|
||||
/* ── Variant: text (no chrome, just coloured text) ─────────────── */
|
||||
.r-chip--text {
|
||||
background: transparent;
|
||||
}
|
||||
.r-chip--text.r-chip--has-color {
|
||||
color: var(--r-chip-color);
|
||||
}
|
||||
.r-chip--text:not(.r-chip--has-color) {
|
||||
color: var(--r-color-fg-secondary);
|
||||
}
|
||||
|
||||
/* ── Variant: plain (zero chrome, inherit everything) ──────────── */
|
||||
.r-chip--plain {
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* ── Close button ──────────────────────────────────────────────── */
|
||||
.r-chip__close {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin-inline-start: 4px;
|
||||
margin-inline-end: -2px;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
border-radius: 50%;
|
||||
width: 1.4em;
|
||||
height: 1.4em;
|
||||
/* The X grows + brightens on hover — micro feedback so the user
|
||||
knows the close button is interactive on its own, separately from
|
||||
the chip body. */
|
||||
opacity: 0.6;
|
||||
transition:
|
||||
opacity var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
transform var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-chip__close:hover {
|
||||
opacity: 1;
|
||||
background: color-mix(in srgb, currentColor 12%, transparent);
|
||||
}
|
||||
.r-chip__close:active {
|
||||
transform: scale(0.9);
|
||||
}
|
||||
.r-chip__close:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.4;
|
||||
}
|
||||
.r-chip__close-icon {
|
||||
font-size: 0.85em;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -22,7 +22,10 @@ type Story = StoryObj<typeof RDivider>;
|
||||
|
||||
export const Default: Story = {};
|
||||
|
||||
// ── Variants ─────────────────────────────────────────────────────────
|
||||
|
||||
export const WithText: Story = {
|
||||
name: "With text (default slot)",
|
||||
render: (args) => ({
|
||||
components: { RDivider },
|
||||
setup: () => ({ args }),
|
||||
@@ -40,8 +43,151 @@ export const Vertical: Story = {
|
||||
components: { RDivider },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="height:60px;display:flex;align-items:center;gap:1rem;color:var(--r-color-fg)">
|
||||
<span>left</span><RDivider v-bind="args" /><span>right</span>
|
||||
<div style="height:60px;display:flex;align-items:center;gap:16px;color:var(--r-color-fg)">
|
||||
<span>Left</span>
|
||||
<RDivider v-bind="args" />
|
||||
<span>Right</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const VerticalWithText: Story = {
|
||||
name: "Vertical with text",
|
||||
args: { vertical: true },
|
||||
render: (args) => ({
|
||||
components: { RDivider },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="height:120px;display:flex;align-items:stretch;gap:16px;color:var(--r-color-fg)">
|
||||
<div style="display:flex;align-items:center;padding:0 16px;background:var(--r-color-surface);border-radius:8px">Top</div>
|
||||
<RDivider v-bind="args">or</RDivider>
|
||||
<div style="display:flex;align-items:center;padding:0 16px;background:var(--r-color-surface);border-radius:8px">Bottom</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Thickness ─────────────────────────────────────────────────────────
|
||||
|
||||
export const ThicknessLadder: Story = {
|
||||
name: "Thickness ladder",
|
||||
render: () => ({
|
||||
components: { RDivider },
|
||||
template: `
|
||||
<div style="width:320px;display:flex;flex-direction:column;gap:18px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div>
|
||||
<RDivider :thickness="1" />
|
||||
<div style="margin-top:6px">thickness: 1 (default)</div>
|
||||
</div>
|
||||
<div>
|
||||
<RDivider :thickness="2" />
|
||||
<div style="margin-top:6px">thickness: 2</div>
|
||||
</div>
|
||||
<div>
|
||||
<RDivider :thickness="4" />
|
||||
<div style="margin-top:6px">thickness: 4</div>
|
||||
</div>
|
||||
<div>
|
||||
<RDivider :thickness="8" />
|
||||
<div style="margin-top:6px">thickness: 8</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const ThicknessWithText: Story = {
|
||||
name: "Thickness — with text",
|
||||
render: () => ({
|
||||
components: { RDivider },
|
||||
template: `
|
||||
<div style="width:320px;display:flex;flex-direction:column;gap:18px;color:var(--r-color-fg)">
|
||||
<RDivider :thickness="1">1px</RDivider>
|
||||
<RDivider :thickness="2">2px</RDivider>
|
||||
<RDivider :thickness="4">4px</RDivider>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Inset ────────────────────────────────────────────────────────────
|
||||
|
||||
export const Inset: Story = {
|
||||
args: { inset: true },
|
||||
render: (args) => ({
|
||||
components: { RDivider },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="width:320px;background:var(--r-color-surface);border-radius:8px;overflow:hidden;font:13px/1.4 sans-serif;color:var(--r-color-fg)">
|
||||
<div style="display:flex;align-items:center;gap:16px;padding:10px 16px">
|
||||
<div style="width:40px;height:40px;border-radius:50%;background:var(--r-color-brand-primary)"></div>
|
||||
<span>List item one</span>
|
||||
</div>
|
||||
<RDivider v-bind="args" />
|
||||
<div style="display:flex;align-items:center;gap:16px;padding:10px 16px">
|
||||
<div style="width:40px;height:40px;border-radius:50%;background:var(--r-color-brand-accent)"></div>
|
||||
<span>List item two</span>
|
||||
</div>
|
||||
<RDivider v-bind="args" />
|
||||
<div style="display:flex;align-items:center;gap:16px;padding:10px 16px">
|
||||
<div style="width:40px;height:40px;border-radius:50%;background:var(--r-color-success)"></div>
|
||||
<span>List item three</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world examples ─────────────────────────────────────────────
|
||||
|
||||
export const InCard: Story = {
|
||||
name: "Inside a card (section break)",
|
||||
render: () => ({
|
||||
components: { RDivider },
|
||||
template: `
|
||||
<div style="width:360px;background:var(--r-color-bg-elevated);border:1px solid var(--r-color-border);border-radius:12px;overflow:hidden;font:13px/1.4 sans-serif;color:var(--r-color-fg)">
|
||||
<div style="padding:14px 16px;font-weight:600">Display preferences</div>
|
||||
<RDivider />
|
||||
<div style="padding:14px 16px;color:var(--r-color-fg-muted)">Theme, density, boxart style…</div>
|
||||
<RDivider />
|
||||
<div style="padding:14px 16px;color:var(--r-color-fg-muted)">Show stats summary on home page.</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const ConsumerOverride: Story = {
|
||||
name: "Consumer style override (the Login 'or')",
|
||||
render: () => ({
|
||||
components: { RDivider },
|
||||
template: `
|
||||
<div style="width:320px;display:flex;flex-direction:column;gap:8px;padding:24px;background:var(--r-color-bg);border-radius:12px">
|
||||
<div style="height:40px;background:var(--r-color-surface);border-radius:6px;display:flex;align-items:center;justify-content:center;color:var(--r-color-fg-muted)">Username field</div>
|
||||
<div style="height:40px;background:var(--r-color-surface);border-radius:6px;display:flex;align-items:center;justify-content:center;color:var(--r-color-fg-muted)">Password field</div>
|
||||
<div style="height:36px;border-radius:6px;background:var(--r-color-brand-primary);color:white;display:flex;align-items:center;justify-content:center;font-weight:600">Sign in</div>
|
||||
<RDivider style="margin: 12px 0; color: var(--r-color-fg-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em;">
|
||||
or
|
||||
</RDivider>
|
||||
<div style="height:36px;border-radius:6px;background:var(--r-color-surface);color:var(--r-color-fg);display:flex;align-items:center;justify-content:center;font-weight:500">Continue with OIDC</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Toolbar: Story = {
|
||||
name: "Vertical inside a toolbar",
|
||||
render: () => ({
|
||||
components: { RDivider },
|
||||
template: `
|
||||
<div style="display:inline-flex;align-items:center;gap:8px;padding:6px 10px;background:var(--r-color-surface);border-radius:8px;color:var(--r-color-fg);font:13px/1 sans-serif">
|
||||
<span>File</span>
|
||||
<RDivider vertical />
|
||||
<span>Edit</span>
|
||||
<RDivider vertical />
|
||||
<span>View</span>
|
||||
<RDivider vertical />
|
||||
<span>Help</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import { VDivider } from "vuetify/components/VDivider";
|
||||
// RDivider — Vuetify-free. Three render modes:
|
||||
//
|
||||
// • Horizontal plain — a block element with `border-top` (no inner
|
||||
// children; the border itself paints the line so the divider takes
|
||||
// zero height + zero baseline impact in a flex column).
|
||||
// • Vertical plain — same trick but `border-left` + `align-self:
|
||||
// stretch` so the divider matches its flex parent's cross-axis.
|
||||
// • With text (default slot present) — flex container with two
|
||||
// flex-grown line segments flanking the slot content. The "or"
|
||||
// pattern from Auth / inline section breaks.
|
||||
//
|
||||
// `inset` shifts the divider rightwards 72px to align with list-item
|
||||
// text (matches Vuetify's `inset` semantics, kept for API parity even
|
||||
// though no v2 surface uses it yet). `thickness` accepts a number (px)
|
||||
// or any CSS length.
|
||||
//
|
||||
// Colour + font defaults live on the root so the consumer can recolour
|
||||
// the divider + its text by setting `color` / `font-size` on the root
|
||||
// from outside. Inner content uses `font: inherit; color: inherit;`
|
||||
// to receive those overrides without `:deep()` hacks.
|
||||
import { computed, useSlots } from "vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
@@ -9,20 +29,125 @@ interface Props {
|
||||
thickness?: number | string;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
vertical: false,
|
||||
inset: false,
|
||||
thickness: undefined,
|
||||
});
|
||||
|
||||
const slots = useSlots();
|
||||
const hasText = computed(() => !!slots.default);
|
||||
|
||||
const resolvedThickness = computed<string | undefined>(() => {
|
||||
const t = props.thickness;
|
||||
if (t === undefined || t === null || t === "") return undefined;
|
||||
if (typeof t === "number") return `${t}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(t)) return `${t}px`;
|
||||
return t;
|
||||
});
|
||||
|
||||
// In plain mode the thickness controls the root's border-*-width; in
|
||||
// with-text mode the borders don't exist (the line is a sibling div),
|
||||
// so we instead style the `.r-divider__line` height/width.
|
||||
const rootStyle = computed(() => {
|
||||
if (!resolvedThickness.value || hasText.value) return undefined;
|
||||
return props.vertical
|
||||
? { borderLeftWidth: resolvedThickness.value }
|
||||
: { borderTopWidth: resolvedThickness.value };
|
||||
});
|
||||
|
||||
const lineStyle = computed(() => {
|
||||
if (!resolvedThickness.value || !hasText.value) return undefined;
|
||||
return props.vertical
|
||||
? { width: resolvedThickness.value }
|
||||
: { height: resolvedThickness.value };
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VDivider
|
||||
<div
|
||||
v-bind="$attrs"
|
||||
:vertical="vertical"
|
||||
:inset="inset"
|
||||
:thickness="thickness"
|
||||
class="r-divider"
|
||||
:class="{
|
||||
'r-divider--vertical': vertical,
|
||||
'r-divider--horizontal': !vertical,
|
||||
'r-divider--inset': inset,
|
||||
'r-divider--with-text': hasText,
|
||||
}"
|
||||
:style="rootStyle"
|
||||
role="separator"
|
||||
:aria-orientation="vertical ? 'vertical' : 'horizontal'"
|
||||
>
|
||||
<template v-if="$slots.default" #default>
|
||||
<slot />
|
||||
<template v-if="hasText">
|
||||
<span class="r-divider__line" :style="lineStyle" aria-hidden="true" />
|
||||
<span class="r-divider__content"><slot /></span>
|
||||
<span class="r-divider__line" :style="lineStyle" aria-hidden="true" />
|
||||
</template>
|
||||
</VDivider>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-divider {
|
||||
/* Defaults propagate to content via inheritance — overridable from
|
||||
the consumer side by setting `color` / `font-size` on the root. */
|
||||
color: var(--r-color-fg-muted);
|
||||
font-size: var(--r-font-size-xs);
|
||||
/* Smooth colour changes so a theme swap or hover doesn't pop. */
|
||||
transition: color var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
/* ── Plain (no slot) ───────────────────────────────────────────── */
|
||||
.r-divider:not(.r-divider--with-text) {
|
||||
display: block;
|
||||
}
|
||||
.r-divider--horizontal:not(.r-divider--with-text) {
|
||||
width: 100%;
|
||||
height: 0;
|
||||
border-top: 1px solid var(--r-color-border);
|
||||
}
|
||||
.r-divider--vertical:not(.r-divider--with-text) {
|
||||
align-self: stretch;
|
||||
width: 0;
|
||||
border-left: 1px solid var(--r-color-border);
|
||||
}
|
||||
|
||||
/* ── With text ─────────────────────────────────────────────────── */
|
||||
.r-divider--with-text {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.r-divider--horizontal.r-divider--with-text {
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
gap: 12px;
|
||||
}
|
||||
.r-divider--vertical.r-divider--with-text {
|
||||
flex-direction: column;
|
||||
align-self: stretch;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.r-divider__line {
|
||||
flex: 1 1 auto;
|
||||
background: var(--r-color-border);
|
||||
transition: background var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-divider--horizontal .r-divider__line {
|
||||
height: 1px;
|
||||
}
|
||||
.r-divider--vertical .r-divider__line {
|
||||
width: 1px;
|
||||
}
|
||||
|
||||
.r-divider__content {
|
||||
flex-shrink: 0;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
letter-spacing: inherit;
|
||||
}
|
||||
|
||||
/* ── Inset (list-style left margin) ────────────────────────────── */
|
||||
.r-divider--inset.r-divider--horizontal {
|
||||
margin-inline-start: 72px;
|
||||
}
|
||||
</style>
|
||||
|
||||
34
frontend/src/v2/lib/primitives/RIcon/RIcon.stories.css
Normal file
34
frontend/src/v2/lib/primitives/RIcon/RIcon.stories.css
Normal file
@@ -0,0 +1,34 @@
|
||||
/* Demo-only styles for RIcon stories. Imported by RIcon.stories.ts so
|
||||
Storybook + Vite handles them as a normal CSS module. Inline <style>
|
||||
blocks inside template strings get parsed inconsistently — keep the
|
||||
demo CSS in a real file. */
|
||||
|
||||
/* Hover swap — three flavours of "icon reacts on hover". The base
|
||||
transition is provided by `.r-icon` itself; we only swap colour and
|
||||
transform here. */
|
||||
.r-icon-story-swap {
|
||||
color: var(--r-color-fg-muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
.r-icon-story-swap:hover {
|
||||
color: var(--r-color-brand-primary);
|
||||
transform: scale(1.18);
|
||||
}
|
||||
|
||||
.r-icon-story-swap--fav {
|
||||
color: var(--r-color-fg-faint);
|
||||
cursor: pointer;
|
||||
}
|
||||
.r-icon-story-swap--fav:hover {
|
||||
color: var(--r-color-romm-gold);
|
||||
transform: scale(1.18);
|
||||
}
|
||||
|
||||
.r-icon-story-swap--del {
|
||||
color: var(--r-color-fg-muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
.r-icon-story-swap--del:hover {
|
||||
color: var(--r-color-danger);
|
||||
transform: rotate(-8deg) scale(1.12);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import "./RIcon.stories.css";
|
||||
import RIcon from "./RIcon.vue";
|
||||
|
||||
const meta: Meta<typeof RIcon> = {
|
||||
@@ -19,24 +20,267 @@ export const Default: Story = {
|
||||
args: { icon: "mdi-controller" },
|
||||
};
|
||||
|
||||
export const Colored: Story = {
|
||||
args: { icon: "mdi-heart", color: "romm-red", size: "32" },
|
||||
// ── Sizes ────────────────────────────────────────────────────────────
|
||||
|
||||
export const SizeLadder: Story = {
|
||||
name: "Size ladder",
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:24px">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-star" size="x-small" />
|
||||
<span>x-small · 12px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-star" size="small" />
|
||||
<span>small · 16px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-star" size="default" />
|
||||
<span>default · 24px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-star" size="large" />
|
||||
<span>large · 36px</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-star" size="x-large" />
|
||||
<span>x-large · 40px</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Large: Story = {
|
||||
args: { icon: "mdi-controller-classic", size: "48" },
|
||||
export const NumericSizes: Story = {
|
||||
name: "Numeric sizes",
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:24px">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-controller" :size="14" />
|
||||
<span>14</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-controller" :size="20" />
|
||||
<span>20</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-controller" :size="28" />
|
||||
<span>28</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-controller" :size="48" />
|
||||
<span>48</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-controller" size="64px" />
|
||||
<span>"64px"</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-controller" size="2em" />
|
||||
<span>"2em"</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Colours ──────────────────────────────────────────────────────────
|
||||
|
||||
export const Tones: Story = {
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:16px 24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-circle" color="primary" size="32" />
|
||||
<span>primary</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-circle" color="secondary" size="32" />
|
||||
<span>secondary</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-circle" color="accent" size="32" />
|
||||
<span>accent</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-check-circle" color="success" size="32" />
|
||||
<span>success</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-alert" color="warning" size="32" />
|
||||
<span>warning</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-close-circle" color="danger" size="32" />
|
||||
<span>danger</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-information" color="info" size="32" />
|
||||
<span>info</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const LegacyColors: Story = {
|
||||
name: "Legacy romm-* colours",
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:flex;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-heart" color="romm-red" size="32" />
|
||||
<span>romm-red</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-leaf" color="romm-green" size="32" />
|
||||
<span>romm-green</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-water" color="romm-blue" size="32" />
|
||||
<span>romm-blue</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-star" color="romm-gold" size="32" />
|
||||
<span>romm-gold</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const PassThrough: Story = {
|
||||
name: "CSS-colour pass-through",
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:flex;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-square" color="#ff00ff" size="32" />
|
||||
<code>#ff00ff</code>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-square" color="rgb(80, 200, 220)" size="32" />
|
||||
<code>rgb(...)</code>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-square" color="tomato" size="32" />
|
||||
<code>tomato</code>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-square" color="hsl(280, 70%, 60%)" size="32" />
|
||||
<code>hsl(...)</code>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Composition & inheritance ────────────────────────────────────────
|
||||
|
||||
export const InheritColor: Story = {
|
||||
name: "Inherits parent colour",
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:14px;font:13px/1.4 sans-serif">
|
||||
<div style="color:var(--r-color-brand-primary);display:flex;align-items:center;gap:8px">
|
||||
<RIcon icon="mdi-information" />
|
||||
<span>Wrapped in brand-primary text — icon follows.</span>
|
||||
</div>
|
||||
<div style="color:var(--r-color-danger);display:flex;align-items:center;gap:8px">
|
||||
<RIcon icon="mdi-alert-octagon" />
|
||||
<span>Wrapped in danger text — icon follows.</span>
|
||||
</div>
|
||||
<div style="color:var(--r-color-fg-muted);display:flex;align-items:center;gap:8px">
|
||||
<RIcon icon="mdi-help-circle" />
|
||||
<span>Muted parent — muted icon.</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const WithText: Story = {
|
||||
name: "Inline with text",
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:10px;font:14px/1.4 sans-serif;color:var(--r-color-fg)">
|
||||
<div style="display:inline-flex;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-clock-outline" size="16" />
|
||||
Last played 2 hours ago
|
||||
</div>
|
||||
<div style="display:inline-flex;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-content-save-outline" size="16" color="success" />
|
||||
Saved successfully
|
||||
</div>
|
||||
<div style="display:inline-flex;align-items:center;gap:6px">
|
||||
<RIcon icon="mdi-trash-can-outline" size="16" color="danger" />
|
||||
Delete this collection
|
||||
</div>
|
||||
<h2 style="display:inline-flex;align-items:center;gap:10px;margin:0">
|
||||
<RIcon icon="mdi-gamepad-variant" size="28" color="primary" />
|
||||
Library
|
||||
</h2>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Motion demos ─────────────────────────────────────────────────────
|
||||
|
||||
export const Spinning: Story = {
|
||||
name: "Spinning (mdi-spin)",
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:flex;align-items:center;gap:24px;font:12px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-loading" size="32" color="primary" class="mdi-spin" />
|
||||
<RIcon icon="mdi-refresh" size="32" color="info" class="mdi-spin" />
|
||||
<RIcon icon="mdi-progress-helper" size="32" color="accent" class="mdi-spin" />
|
||||
<span>Built-in <code>mdi-spin</code> from <code>@mdi/font</code> composes with the base — no spin prop needed.</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const ColorSwap: Story = {
|
||||
name: "Hover colour swap (motion preview)",
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:flex;gap:24px;align-items:center;font:12px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RIcon icon="mdi-heart" size="32" class="r-icon-story-swap" />
|
||||
<RIcon icon="mdi-star" size="32" class="r-icon-story-swap--fav" />
|
||||
<RIcon icon="mdi-trash-can-outline" size="32" class="r-icon-story-swap--del" />
|
||||
<span>Hover — icon transitions colour + transform smoothly.</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Catch-all ────────────────────────────────────────────────────────
|
||||
|
||||
export const Gallery: Story = {
|
||||
render: () => ({
|
||||
components: { RIcon },
|
||||
template: `
|
||||
<div style="display:flex;gap:1rem;align-items:center">
|
||||
<div style="display:flex;flex-wrap:wrap;gap:24px;align-items:center">
|
||||
<RIcon icon="mdi-home" />
|
||||
<RIcon icon="mdi-controller" color="primary" />
|
||||
<RIcon icon="mdi-star" color="romm-gold" size="28" />
|
||||
<RIcon icon="mdi-trash-can-outline" color="romm-red" />
|
||||
<RIcon icon="mdi-check-circle" color="romm-green" />
|
||||
<RIcon icon="mdi-account-circle" color="info" size="32" />
|
||||
<RIcon icon="mdi-cog" color="secondary" />
|
||||
<RIcon icon="mdi-pulse" color="accent" size="20" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
|
||||
@@ -1,23 +1,127 @@
|
||||
<script setup lang="ts">
|
||||
import { VIcon } from "vuetify/components/VIcon";
|
||||
// RIcon — Vuetify-free. Renders an MDI glyph via the `@mdi/font` CSS
|
||||
// pseudo-element pipeline. `font-size` drives the visual size; `color`
|
||||
// resolves either a v2 tone keyword (`"primary"`, `"success"`, …) or
|
||||
// a legacy `romm-*` name, or passes through any CSS colour value
|
||||
// (hex, rgb(...), named CSS colour). When `color` is omitted the icon
|
||||
// inherits its parent — matches Vuetify's VIcon behaviour so consumers
|
||||
// don't need to change a single call site.
|
||||
//
|
||||
// Sized via `font-size` (not `width`/`height`) because the glyph is a
|
||||
// pseudo-element on the `.mdi` class. We mirror the icon's `font-size`
|
||||
// to `width`/`height` so the wrapper is a perfect square — keeps icon
|
||||
// + text alignment in flex rows identical to what VIcon produced.
|
||||
import { computed } from "vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface Props {
|
||||
/** MDI class name including the prefix, e.g. `mdi-controller`. */
|
||||
icon?: string;
|
||||
/** Named ladder (`x-small | small | default | large | x-large`),
|
||||
* bare number (px), or any CSS length (`"1.4em"`, `"20px"`). */
|
||||
size?: string | number;
|
||||
/** v2 tone keyword, legacy `romm-*`, or any CSS colour. Omit to
|
||||
* inherit the parent's text colour. */
|
||||
color?: string;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
icon: undefined,
|
||||
size: undefined,
|
||||
color: undefined,
|
||||
});
|
||||
|
||||
// Named size ladder mirrors Vuetify's keyword set so call sites pass
|
||||
// `"small"` / `"large"` without rounding pixel values. Numeric sizes
|
||||
// (`24`, `"24"`) are coerced to px; pre-formatted lengths pass through.
|
||||
const SIZE_MAP: Record<string, string> = {
|
||||
"x-small": "12px",
|
||||
small: "16px",
|
||||
default: "24px",
|
||||
large: "36px",
|
||||
"x-large": "40px",
|
||||
};
|
||||
|
||||
const resolvedSize = computed<string | undefined>(() => {
|
||||
const s = props.size;
|
||||
if (s === undefined || s === null || s === "") return undefined;
|
||||
if (typeof s === "number") return `${s}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(s)) return `${s}px`;
|
||||
return SIZE_MAP[s] ?? s;
|
||||
});
|
||||
|
||||
// Single source of truth for v2 tone aliasing. Other primitives will
|
||||
// share this once we extract it — for now it lives here since RIcon is
|
||||
// the only consumer post-Vuetify-rip.
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
|
||||
const resolvedColor = computed<string | undefined>(() => {
|
||||
const c = props.color;
|
||||
if (!c) return undefined;
|
||||
return TONE_MAP[c] ?? c;
|
||||
});
|
||||
|
||||
const styleObj = computed(() => {
|
||||
const out: Record<string, string> = {};
|
||||
if (resolvedSize.value) {
|
||||
out.fontSize = resolvedSize.value;
|
||||
out.width = resolvedSize.value;
|
||||
out.height = resolvedSize.value;
|
||||
}
|
||||
if (resolvedColor.value) out.color = resolvedColor.value;
|
||||
return out;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VIcon v-bind="$attrs" :icon="icon" :size="size" :color="color">
|
||||
<i
|
||||
v-bind="$attrs"
|
||||
class="r-icon mdi"
|
||||
:class="icon"
|
||||
:style="styleObj"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<slot />
|
||||
</VIcon>
|
||||
</i>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
line-height: 1;
|
||||
/* Inherit colour from the parent unless overridden — Vuetify's VIcon
|
||||
did this implicitly. Keeps icon + text colour locked together
|
||||
inside buttons / chips. */
|
||||
color: inherit;
|
||||
/* Smooth the glyph everywhere the OS will let us. Without these the
|
||||
icon looks slightly heavier on Windows / Linux. */
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
text-rendering: auto;
|
||||
user-select: none;
|
||||
/* Animate colour/transform changes so consumers that toggle tones
|
||||
(favourite, selected, error) get a smooth swap rather than a hard
|
||||
flip. Cheap, idempotent — matches the motion vocabulary RSwitch
|
||||
established. */
|
||||
transition:
|
||||
color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
transform var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
</style>
|
||||
|
||||
41
frontend/src/v2/lib/primitives/RImg/RImg.stories.css
Normal file
41
frontend/src/v2/lib/primitives/RImg/RImg.stories.css
Normal file
@@ -0,0 +1,41 @@
|
||||
/* Demo-only styles for RImg stories. Imported by RImg.stories.ts so
|
||||
Storybook + Vite handles them as a normal CSS module. Inline <style>
|
||||
blocks inside template strings get parsed inconsistently and the
|
||||
keyframes stop animating — keep the demo CSS in a real file. */
|
||||
|
||||
/* Loading-slot shimmer — three-stop gradient sliding across the
|
||||
container. Visible only while RImg is in `loading` state. */
|
||||
@keyframes r-img-story-shimmer {
|
||||
0% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
.r-img-story-shimmer {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--r-color-surface) 0%,
|
||||
var(--r-color-surface-hover) 50%,
|
||||
var(--r-color-surface) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: r-img-story-shimmer 1.4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.r-img-story-reload-btn {
|
||||
padding: 6px 12px;
|
||||
background: var(--r-color-brand-primary);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font: 12px/1 sans-serif;
|
||||
cursor: pointer;
|
||||
}
|
||||
.r-img-story-reload-btn:hover {
|
||||
background: var(--r-color-brand-primary-hover);
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { onMounted, onUnmounted, ref } from "vue";
|
||||
import "./RImg.stories.css";
|
||||
import RImg from "./RImg.vue";
|
||||
|
||||
const meta: Meta<typeof RImg> = {
|
||||
@@ -6,9 +8,12 @@ const meta: Meta<typeof RImg> = {
|
||||
component: RImg,
|
||||
argTypes: {
|
||||
src: { control: "text" },
|
||||
alt: { control: "text" },
|
||||
width: { control: "text" },
|
||||
height: { control: "text" },
|
||||
cover: { control: "boolean" },
|
||||
contain: { control: "boolean" },
|
||||
aspectRatio: { control: "text" },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -16,6 +21,247 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RImg>;
|
||||
|
||||
export const Logo: Story = {
|
||||
args: { src: "/assets/isotipo.svg", width: 80, alt: "RomM logo" },
|
||||
// A small known-good image we can use without network access in
|
||||
// Storybook. The local logo ships at /assets/isotipo.svg.
|
||||
const LOGO = "/assets/isotipo.svg";
|
||||
// Picsum is fine in Storybook; we use seed-based URLs so each story
|
||||
// renders a reproducible image.
|
||||
const PHOTO = "https://picsum.photos/seed/romm/600/400";
|
||||
const PHOTO_TALL = "https://picsum.photos/seed/romm-tall/300/600";
|
||||
|
||||
// ── Basic ────────────────────────────────────────────────────────────
|
||||
|
||||
export const Default: Story = {
|
||||
args: { src: LOGO, width: 80, alt: "RomM logo" },
|
||||
};
|
||||
|
||||
export const NaturalSize: Story = {
|
||||
name: "Natural size (no width / height)",
|
||||
args: { src: LOGO, alt: "RomM logo" },
|
||||
};
|
||||
|
||||
// ── Sizing ───────────────────────────────────────────────────────────
|
||||
|
||||
export const WidthOnly: Story = {
|
||||
name: "Width only — auto height",
|
||||
render: () => ({
|
||||
components: { RImg },
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RImg src="${LOGO}" :width="32" alt="logo" />
|
||||
<span>width 32</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RImg src="${LOGO}" :width="64" alt="logo" />
|
||||
<span>width 64</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
||||
<RImg src="${LOGO}" :width="128" alt="logo" />
|
||||
<span>width 128</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const CoverFit: Story = {
|
||||
name: "cover · width × height",
|
||||
render: () => ({
|
||||
components: { RImg },
|
||||
template: `
|
||||
<div style="display:flex;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RImg src="${PHOTO}" :width="160" :height="100" cover alt="cover" style="border-radius:8px" />
|
||||
<span>cover · 160×100</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RImg src="${PHOTO_TALL}" :width="160" :height="100" cover alt="cover tall" style="border-radius:8px" />
|
||||
<span>cover · tall src → cropped</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const ContainFit: Story = {
|
||||
name: "contain · width × height",
|
||||
render: () => ({
|
||||
components: { RImg },
|
||||
template: `
|
||||
<div style="display:flex;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RImg
|
||||
src="${PHOTO}"
|
||||
:width="160"
|
||||
:height="100"
|
||||
contain
|
||||
alt="contain"
|
||||
style="border-radius:8px;background:var(--r-color-surface)"
|
||||
/>
|
||||
<span>contain · letterboxed</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RImg
|
||||
src="${PHOTO_TALL}"
|
||||
:width="160"
|
||||
:height="100"
|
||||
contain
|
||||
alt="contain tall"
|
||||
style="border-radius:8px;background:var(--r-color-surface)"
|
||||
/>
|
||||
<span>contain · tall src → letterboxed</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const AspectRatio: Story = {
|
||||
name: "aspectRatio (responsive)",
|
||||
render: () => ({
|
||||
components: { RImg },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:16px;width:320px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div>
|
||||
<RImg src="${PHOTO}" aspect-ratio="16/9" cover style="width:100%;border-radius:8px" alt="16/9" />
|
||||
<div style="margin-top:6px">aspectRatio "16/9" · cover · width 100%</div>
|
||||
</div>
|
||||
<div>
|
||||
<RImg src="${PHOTO}" aspect-ratio="1/1" cover style="width:100%;border-radius:8px" alt="1/1" />
|
||||
<div style="margin-top:6px">aspectRatio "1/1" · cover · width 100%</div>
|
||||
</div>
|
||||
<div>
|
||||
<RImg src="${PHOTO}" aspect-ratio="4/3" cover style="width:100%;border-radius:8px" alt="4/3" />
|
||||
<div style="margin-top:6px">aspectRatio "4/3" · cover · width 100%</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Slots ────────────────────────────────────────────────────────────
|
||||
|
||||
export const ErrorSlot: Story = {
|
||||
name: "error slot (fallback)",
|
||||
render: () => ({
|
||||
components: { RImg },
|
||||
template: `
|
||||
<div style="display:flex;align-items:center;gap:24px;font:12px/1.4 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RImg src="/does-not-exist.png" :width="64" :height="64" alt="missing">
|
||||
<template #error>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:4px;color:var(--r-color-fg-faint)">
|
||||
<i class="mdi mdi-image-broken-variant" style="font-size:24px"></i>
|
||||
<span style="font-size:10px">missing</span>
|
||||
</div>
|
||||
</template>
|
||||
</RImg>
|
||||
<span>The src 404s — the <code>#error</code> slot renders instead.</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const LoadingSlot: Story = {
|
||||
name: "loading slot (placeholder)",
|
||||
render: () => ({
|
||||
components: { RImg },
|
||||
setup() {
|
||||
// The story controls how long the loading state lasts:
|
||||
// 1. Start with `src` empty — RImg renders the loading slot.
|
||||
// 2. After `loadingDelay` ms, set a real cache-busted src so
|
||||
// the image fetches and `loaded` takes over.
|
||||
// 3. The "Reload" button restarts the cycle on demand.
|
||||
// This is how we make a network-fast image visibly demo the
|
||||
// loading state — without a delay proxy we'd flash past it in
|
||||
// a couple of frames.
|
||||
const src = ref<string | undefined>(undefined);
|
||||
const loadingDelay = 2500;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
let counter = 0;
|
||||
|
||||
function reload() {
|
||||
if (timer) clearTimeout(timer);
|
||||
src.value = undefined;
|
||||
counter += 1;
|
||||
const myCounter = counter;
|
||||
timer = setTimeout(() => {
|
||||
// Cache-bust each cycle so picsum re-fetches.
|
||||
src.value = `https://picsum.photos/seed/r-img-loading-${myCounter}/400/400`;
|
||||
}, loadingDelay);
|
||||
}
|
||||
|
||||
onMounted(reload);
|
||||
onUnmounted(() => {
|
||||
if (timer) clearTimeout(timer);
|
||||
});
|
||||
|
||||
return { src, reload };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;align-items:center;gap:24px;font:12px/1.4 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RImg
|
||||
:src="src"
|
||||
:width="120"
|
||||
:height="120"
|
||||
cover
|
||||
alt="loading demo"
|
||||
style="border-radius:8px"
|
||||
>
|
||||
<template #loading>
|
||||
<div class="r-img-story-shimmer" />
|
||||
</template>
|
||||
</RImg>
|
||||
<div style="display:flex;flex-direction:column;gap:8px;max-width:240px">
|
||||
<span>The shimmer is forced visible for 2.5s before the image fetches. Click reload to re-trigger.</span>
|
||||
<button class="r-img-story-reload-btn" type="button" @click="reload">Reload</button>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const DefaultSlotOverlay: Story = {
|
||||
name: "default slot (overlay over loaded image)",
|
||||
render: () => ({
|
||||
components: { RImg },
|
||||
template: `
|
||||
<RImg
|
||||
src="${PHOTO}"
|
||||
:width="320"
|
||||
:height="180"
|
||||
cover
|
||||
alt="overlay"
|
||||
style="border-radius:12px"
|
||||
>
|
||||
<div style="
|
||||
width:100%;height:100%;display:flex;align-items:flex-end;
|
||||
padding:12px;
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
transparent 40%,
|
||||
color-mix(in srgb, black 70%, transparent) 100%
|
||||
);
|
||||
color:white;font:600 14px/1.2 sans-serif;
|
||||
">
|
||||
Overlay caption — composes on top of the image
|
||||
</div>
|
||||
</RImg>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world ──────────────────────────────────────────────────────
|
||||
|
||||
export const Logo: Story = {
|
||||
name: "Logo (AppNav usage)",
|
||||
render: () => ({
|
||||
components: { RImg },
|
||||
template: `
|
||||
<div style="display:inline-flex;align-items:center;gap:8px;padding:8px 12px;background:var(--r-color-surface);border-radius:8px">
|
||||
<RImg src="${LOGO}" :width="32" alt="isotipo" />
|
||||
<RImg src="/assets/logotipo.svg" :width="70" alt="logotipo" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { VImg } from "vuetify/components/VImg";
|
||||
// RImg — Vuetify-free. Wraps a native <img> with three slot-driven
|
||||
// states: `loading` (while the network fetch is in flight), `error`
|
||||
// (when load fails or src is empty), and `default` (a content overlay
|
||||
// rendered on top of the loaded image — captions, hover CTAs, etc).
|
||||
//
|
||||
// Layout model — the wrapper takes the explicit width/height, the
|
||||
// `<img>` fills it. Without `cover`/`contain` the image scales by
|
||||
// width (height auto from natural aspect ratio) — matches the v2 logo
|
||||
// usage in AppNav / AuthCard / OIDCButton. Add `cover` (fill + crop)
|
||||
// or `contain` (fit inside, letterbox) when the wrapper has both
|
||||
// width AND height set and you want object-fit behaviour.
|
||||
//
|
||||
// `aspectRatio` accepts CSS-native syntax (`"16/9"` or numeric `1.78`)
|
||||
// — applied to the wrapper. Pair with `width` to get a fixed-ratio
|
||||
// container that flexes with its parent's width.
|
||||
//
|
||||
// Fades in once loaded so the swap from placeholder → image doesn't
|
||||
// pop. Matches the motion vocabulary RSwitch / RIcon established.
|
||||
import { computed, ref, useSlots, watch } from "vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
@@ -8,32 +26,175 @@ interface Props {
|
||||
alt?: string;
|
||||
width?: string | number;
|
||||
height?: string | number;
|
||||
/** Fill the wrapper, crop overflow (object-fit: cover). */
|
||||
cover?: boolean;
|
||||
/** Fit inside the wrapper, letterbox (object-fit: contain). */
|
||||
contain?: boolean;
|
||||
/** CSS aspect-ratio on the wrapper. `"16/9"`, `"1/1"`, `1.78`. */
|
||||
aspectRatio?: string | number;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
src: undefined,
|
||||
alt: undefined,
|
||||
width: undefined,
|
||||
height: undefined,
|
||||
cover: false,
|
||||
contain: false,
|
||||
aspectRatio: undefined,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "load"): void;
|
||||
(e: "error"): void;
|
||||
}>();
|
||||
|
||||
const slots = useSlots();
|
||||
|
||||
type LoadState = "loading" | "loaded" | "error";
|
||||
// Start in `loading` regardless of `src` — "no src yet" is a waiting
|
||||
// state (e.g. consumer is hydrating an async value), not an error.
|
||||
// `error` only flips after a failed network attempt.
|
||||
const state = ref<LoadState>("loading");
|
||||
|
||||
// Reset to `loading` whenever src changes so a swap re-enters the
|
||||
// loading fade rather than flashing the previous image.
|
||||
watch(
|
||||
() => props.src,
|
||||
() => {
|
||||
state.value = "loading";
|
||||
},
|
||||
);
|
||||
|
||||
function onLoad() {
|
||||
state.value = "loaded";
|
||||
emit("load");
|
||||
}
|
||||
function onError() {
|
||||
state.value = "error";
|
||||
emit("error");
|
||||
}
|
||||
|
||||
// Length resolver — bare numbers / numeric strings → px, anything else
|
||||
// (`"100%"`, `"24em"`, `"clamp(...)"`) passes through.
|
||||
function toLength(v: string | number | undefined): string | undefined {
|
||||
if (v === undefined || v === null || v === "") return undefined;
|
||||
if (typeof v === "number") return `${v}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(v)) return `${v}px`;
|
||||
return v;
|
||||
}
|
||||
|
||||
const wrapperStyle = computed(() => ({
|
||||
width: toLength(props.width),
|
||||
height: toLength(props.height),
|
||||
aspectRatio:
|
||||
props.aspectRatio !== undefined ? String(props.aspectRatio) : undefined,
|
||||
}));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VImg
|
||||
<div
|
||||
v-bind="$attrs"
|
||||
:src="src"
|
||||
:alt="alt"
|
||||
:width="width"
|
||||
:height="height"
|
||||
:cover="cover"
|
||||
:aspect-ratio="aspectRatio"
|
||||
class="r-img"
|
||||
:class="{
|
||||
'r-img--loading': state === 'loading',
|
||||
'r-img--loaded': state === 'loaded',
|
||||
'r-img--error': state === 'error',
|
||||
'r-img--cover': cover,
|
||||
'r-img--contain': contain,
|
||||
}"
|
||||
:style="wrapperStyle"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VImg>
|
||||
<img
|
||||
v-if="src && state !== 'error'"
|
||||
:src="src"
|
||||
:alt="alt ?? ''"
|
||||
class="r-img__image"
|
||||
decoding="async"
|
||||
@load="onLoad"
|
||||
@error="onError"
|
||||
/>
|
||||
|
||||
<div v-if="state === 'loading' && slots.loading" class="r-img__layer">
|
||||
<slot name="loading" />
|
||||
</div>
|
||||
<div
|
||||
v-else-if="state === 'loading' && slots.placeholder"
|
||||
class="r-img__layer"
|
||||
>
|
||||
<slot name="placeholder" />
|
||||
</div>
|
||||
|
||||
<div v-if="state === 'error'" class="r-img__layer">
|
||||
<slot name="error" />
|
||||
</div>
|
||||
|
||||
<div v-if="state === 'loaded' && slots.default" class="r-img__overlay">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-img {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
/* Inline-block + line-height: 0 prevents the natural baseline gap
|
||||
under <img> that puts a couple of px under the image when used
|
||||
inline next to text. */
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
/* Image — defaults to width 100%, height auto so a logo with only
|
||||
`width` set keeps its natural aspect ratio. Adding `cover`/`contain`
|
||||
forces the height to fill the wrapper so object-fit takes effect. */
|
||||
.r-img__image {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
/* Fade in once loaded — the `--loaded` class on the wrapper flips
|
||||
opacity. While loading the image is still in the DOM (so onload
|
||||
can fire) but invisible. */
|
||||
opacity: 0;
|
||||
transition: opacity var(--r-motion-base) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-img--loaded .r-img__image {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.r-img--cover .r-img__image,
|
||||
.r-img--contain .r-img__image {
|
||||
height: 100%;
|
||||
}
|
||||
.r-img--cover .r-img__image {
|
||||
object-fit: cover;
|
||||
}
|
||||
.r-img--contain .r-img__image {
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
/* Loading / error layer — absolutely positioned over the wrapper so
|
||||
it sits where the image would and disappears once the image lands.
|
||||
`inset: 0` works with the inline-block sizing. */
|
||||
.r-img__layer {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
/* Layers inherit the wrapper's font-size (in case the consumer puts
|
||||
an MDI fallback icon inside). Reset line-height so text inside
|
||||
reads correctly — the wrapper sets it to 0 to suppress the baseline
|
||||
gap. */
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* Default-slot overlay — sits over the loaded image. Caption /
|
||||
hover-CTA / shimmer-on-top. */
|
||||
.r-img__overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { onMounted, onUnmounted, ref } from "vue";
|
||||
import RProgressCircular from "./RProgressCircular.vue";
|
||||
|
||||
const meta: Meta<typeof RProgressCircular> = {
|
||||
title: "Primitives/RProgressCircular",
|
||||
component: RProgressCircular,
|
||||
argTypes: {
|
||||
indeterminate: { control: "boolean" },
|
||||
size: { control: "number" },
|
||||
width: { control: "number" },
|
||||
color: { control: "text" },
|
||||
indeterminate: { control: "boolean" },
|
||||
modelValue: { control: { type: "range", min: 0, max: 100 } },
|
||||
},
|
||||
};
|
||||
@@ -17,10 +18,204 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RProgressCircular>;
|
||||
|
||||
// ── Defaults ────────────────────────────────────────────────────────
|
||||
|
||||
export const Indeterminate: Story = {
|
||||
args: { indeterminate: true, size: 32 },
|
||||
};
|
||||
|
||||
export const Determinate: Story = {
|
||||
args: { indeterminate: false, modelValue: 65, size: 48, width: 4 },
|
||||
args: { indeterminate: false, modelValue: 65, size: 64, width: 4 },
|
||||
};
|
||||
|
||||
// ── Size ladder ─────────────────────────────────────────────────────
|
||||
|
||||
export const SizeLadder: Story = {
|
||||
name: "Size ladder · indeterminate",
|
||||
render: () => ({
|
||||
components: { RProgressCircular },
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular indeterminate :size="16" :width="2" />
|
||||
<span>16 / 2</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular indeterminate :size="24" :width="2" />
|
||||
<span>24 / 2</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular indeterminate :size="36" :width="3" />
|
||||
<span>36 / 3</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular indeterminate :size="56" :width="4" />
|
||||
<span>56 / 4</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular indeterminate :size="80" :width="6" />
|
||||
<span>80 / 6</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const DeterminateLadder: Story = {
|
||||
name: "Determinate · stepped values",
|
||||
render: () => ({
|
||||
components: { RProgressCircular },
|
||||
template: `
|
||||
<div style="display:flex;align-items:flex-end;gap:24px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular :indeterminate="false" :model-value="0" :size="48" :width="4" />
|
||||
<span>0%</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular :indeterminate="false" :model-value="25" :size="48" :width="4" />
|
||||
<span>25%</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular :indeterminate="false" :model-value="50" :size="48" :width="4" />
|
||||
<span>50%</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular :indeterminate="false" :model-value="75" :size="48" :width="4" />
|
||||
<span>75%</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular :indeterminate="false" :model-value="100" :size="48" :width="4" />
|
||||
<span>100%</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Tones ───────────────────────────────────────────────────────────
|
||||
|
||||
export const Tones: Story = {
|
||||
render: () => ({
|
||||
components: { RProgressCircular },
|
||||
template: `
|
||||
<div style="display:grid;grid-template-columns:repeat(4,auto);gap:24px 32px;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular color="primary" :size="40" :width="3" />
|
||||
<span>primary</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular color="secondary" :size="40" :width="3" />
|
||||
<span>secondary</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular color="accent" :size="40" :width="3" />
|
||||
<span>accent</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular color="success" :size="40" :width="3" />
|
||||
<span>success</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular color="warning" :size="40" :width="3" />
|
||||
<span>warning</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular color="danger" :size="40" :width="3" />
|
||||
<span>danger</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular color="info" :size="40" :width="3" />
|
||||
<span>info</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular color="romm-gold" :size="40" :width="3" />
|
||||
<span>romm-gold</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Slot ─────────────────────────────────────────────────────────────
|
||||
|
||||
export const WithLabel: Story = {
|
||||
name: "Default slot (percentage label)",
|
||||
render: () => ({
|
||||
components: { RProgressCircular },
|
||||
template: `
|
||||
<div style="display:flex;gap:24px;align-items:flex-end;font:11px/1.2 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular :indeterminate="false" :model-value="35" :size="64" :width="4">
|
||||
35%
|
||||
</RProgressCircular>
|
||||
<span>numeric</span>
|
||||
</div>
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:8px">
|
||||
<RProgressCircular :indeterminate="false" :model-value="80" :size="80" :width="5" color="success">
|
||||
<span style="font-size:14px">80%</span>
|
||||
</RProgressCircular>
|
||||
<span>larger + custom font-size</span>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Live progress ───────────────────────────────────────────────────
|
||||
|
||||
export const Animated: Story = {
|
||||
name: "Animated progress (live update)",
|
||||
render: () => ({
|
||||
components: { RProgressCircular },
|
||||
setup() {
|
||||
const value = ref(0);
|
||||
let timer: ReturnType<typeof setInterval> | undefined;
|
||||
onMounted(() => {
|
||||
timer = setInterval(() => {
|
||||
value.value = (value.value + 5) % 105;
|
||||
if (value.value > 100) value.value = 0;
|
||||
}, 400);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
if (timer) clearInterval(timer);
|
||||
});
|
||||
return { value };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;align-items:center;gap:14px;font:12px/1.4 sans-serif;color:var(--r-color-fg-muted)">
|
||||
<RProgressCircular :indeterminate="false" :model-value="value" :size="80" :width="5" color="primary">
|
||||
<span style="font-size:14px;font-weight:600">{{ value }}%</span>
|
||||
</RProgressCircular>
|
||||
<span>Value advances every 400ms — note the smooth fill transition.</span>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Comparison ──────────────────────────────────────────────────────
|
||||
|
||||
export const InContext: Story = {
|
||||
name: "Inline in buttons / dialogs",
|
||||
render: () => ({
|
||||
components: { RProgressCircular },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:18px;font:13px/1.4 sans-serif;color:var(--r-color-fg)">
|
||||
<button
|
||||
type="button"
|
||||
style="display:inline-flex;align-items:center;gap:8px;padding:8px 14px;background:var(--r-color-brand-primary);color:white;border:none;border-radius:6px;font-weight:600;cursor:wait;align-self:flex-start"
|
||||
disabled
|
||||
>
|
||||
<RProgressCircular indeterminate :size="14" :width="2" color="white" />
|
||||
Submitting…
|
||||
</button>
|
||||
<div style="display:flex;align-items:center;gap:14px;padding:16px;background:var(--r-color-surface);border-radius:12px;align-self:flex-start">
|
||||
<RProgressCircular indeterminate :size="36" :width="3" color="primary" />
|
||||
<div style="display:flex;flex-direction:column;gap:2px">
|
||||
<span style="font-weight:600">Fetching metadata</span>
|
||||
<span style="color:var(--r-color-fg-muted);font-size:11px">This may take a few seconds…</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,34 +1,253 @@
|
||||
<script setup lang="ts">
|
||||
import { VProgressCircular } from "vuetify/components/VProgressCircular";
|
||||
// RProgressCircular — Vuetify-free. Pure SVG ring with two modes:
|
||||
//
|
||||
// • Indeterminate (default) — Material-style spinner. The SVG rotates
|
||||
// continuously while the arc's `stroke-dasharray` cycles through a
|
||||
// short→long→short pattern, creating the classic "snake chasing
|
||||
// its tail" loop. Two animations compose on one DOM element so we
|
||||
// don't need a wrapper rotation.
|
||||
//
|
||||
// • Determinate (`indeterminate=false` + `modelValue`) — the arc fills
|
||||
// clockwise from 12 o'clock. `pathLength="100"` normalises the
|
||||
// circle so `stroke-dashoffset = 100 - value` works at any radius —
|
||||
// no per-size maths.
|
||||
//
|
||||
// `size` and `width` are numeric pixels (number or numeric string).
|
||||
// Anything else falls back to the default. Colour goes through the
|
||||
// shared TONE_MAP so `"primary"`, status tones, and legacy `romm-*`
|
||||
// names resolve consistently with the rest of the lib.
|
||||
//
|
||||
// Default slot — overlay content centred over the ring (percentage
|
||||
// text, status icon). Lives outside the SVG so it isn't rotated.
|
||||
import { computed, useSlots } from "vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface Props {
|
||||
/** Spinner mode. Default `true` — Material-style continuous loop. */
|
||||
indeterminate?: boolean;
|
||||
/** Diameter in px. */
|
||||
size?: number | string;
|
||||
/** Stroke width in px. */
|
||||
width?: number | string;
|
||||
/** Tone keyword / legacy `romm-*` / any CSS colour. */
|
||||
color?: string;
|
||||
/** 0–100. Only consulted when `indeterminate` is false. */
|
||||
modelValue?: number;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
indeterminate: true,
|
||||
size: 24,
|
||||
width: 2,
|
||||
color: "primary",
|
||||
modelValue: undefined,
|
||||
});
|
||||
|
||||
const slots = useSlots();
|
||||
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
|
||||
const resolvedColor = computed<string>(
|
||||
() => TONE_MAP[props.color] ?? props.color ?? TONE_MAP.primary,
|
||||
);
|
||||
|
||||
function toNumber(v: number | string, fallback: number): number {
|
||||
if (typeof v === "number") return v;
|
||||
if (typeof v === "string" && /^\d+(\.\d+)?$/.test(v)) return Number(v);
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const diameter = computed(() => toNumber(props.size, 24));
|
||||
const strokeWidth = computed(() => toNumber(props.width, 2));
|
||||
const radius = computed(() => (diameter.value - strokeWidth.value) / 2);
|
||||
|
||||
// Clamp 0–100, gracefully handles undefined.
|
||||
const progressValue = computed<number>(() => {
|
||||
const v = props.modelValue;
|
||||
if (v === undefined || v === null) return 0;
|
||||
return Math.max(0, Math.min(100, v));
|
||||
});
|
||||
|
||||
// With pathLength=100, dash values are percentages of the circle:
|
||||
// dasharray="100" → reserve 100% of the path for the visible stroke
|
||||
// dashoffset → hide N% from the start (= empty portion)
|
||||
const dashOffset = computed(() => 100 - progressValue.value);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VProgressCircular
|
||||
<span
|
||||
v-bind="$attrs"
|
||||
:indeterminate="indeterminate"
|
||||
:size="size"
|
||||
:width="width"
|
||||
:color="color"
|
||||
:model-value="modelValue"
|
||||
class="r-pc"
|
||||
:class="{
|
||||
'r-pc--indeterminate': indeterminate,
|
||||
'r-pc--determinate': !indeterminate,
|
||||
}"
|
||||
:style="{
|
||||
width: `${diameter}px`,
|
||||
height: `${diameter}px`,
|
||||
'--r-pc-color': resolvedColor,
|
||||
}"
|
||||
role="progressbar"
|
||||
:aria-valuemin="0"
|
||||
:aria-valuemax="100"
|
||||
:aria-valuenow="indeterminate ? undefined : progressValue"
|
||||
:aria-busy="indeterminate || undefined"
|
||||
>
|
||||
<slot />
|
||||
</VProgressCircular>
|
||||
<svg class="r-pc__svg" :viewBox="`0 0 ${diameter} ${diameter}`">
|
||||
<!-- Track — faint underlay so the empty portion still reads
|
||||
against complex backgrounds. Hidden under indeterminate. -->
|
||||
<circle
|
||||
class="r-pc__track"
|
||||
:cx="diameter / 2"
|
||||
:cy="diameter / 2"
|
||||
:r="radius"
|
||||
:stroke-width="strokeWidth"
|
||||
fill="none"
|
||||
/>
|
||||
<!-- Arc — the visible progress / spinner snake. -->
|
||||
<circle
|
||||
class="r-pc__arc"
|
||||
:cx="diameter / 2"
|
||||
:cy="diameter / 2"
|
||||
:r="radius"
|
||||
:stroke-width="strokeWidth"
|
||||
fill="none"
|
||||
pathLength="100"
|
||||
:stroke-dasharray="indeterminate ? undefined : 100"
|
||||
:stroke-dashoffset="indeterminate ? undefined : dashOffset"
|
||||
/>
|
||||
</svg>
|
||||
<span v-if="slots.default" class="r-pc__content">
|
||||
<slot />
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-pc {
|
||||
display: inline-flex;
|
||||
position: relative;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
/* `color` is the fallback for the arc — `--r-pc-color` overrides it
|
||||
so consumers can hand-roll a custom tone via inline style without
|
||||
touching the prop. */
|
||||
color: var(--r-pc-color);
|
||||
transition: color var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
.r-pc__svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
/* Start the arc at 12 o'clock — determinate progress reads as
|
||||
"fills clockwise from top" instead of "from 3 o'clock". */
|
||||
transform: rotate(-90deg);
|
||||
transform-origin: 50% 50%;
|
||||
}
|
||||
|
||||
.r-pc__track {
|
||||
stroke: color-mix(in srgb, currentColor 18%, transparent);
|
||||
}
|
||||
|
||||
.r-pc__arc {
|
||||
stroke: currentColor;
|
||||
stroke-linecap: round;
|
||||
/* Smooth the value swap so a determinate `modelValue` change reads
|
||||
as a fluid fill instead of jumping. The indeterminate path below
|
||||
disables this — two animation systems on the same property smear. */
|
||||
transition: stroke-dashoffset 320ms var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
/* ── Indeterminate ─────────────────────────────────────────────── */
|
||||
|
||||
/* Two animations compose on the same SVG: the parent rotates linearly
|
||||
while the arc's dash cycles long→short→long. The combination is the
|
||||
Material-classic spinner — recognisable, smooth, GPU-friendly. */
|
||||
.r-pc--indeterminate .r-pc__svg {
|
||||
animation: r-pc-rotate 1.6s linear infinite;
|
||||
}
|
||||
.r-pc--indeterminate .r-pc__arc {
|
||||
animation: r-pc-dash 1.4s ease-in-out infinite;
|
||||
transition: none;
|
||||
}
|
||||
.r-pc--indeterminate .r-pc__track {
|
||||
/* Hide the track for indeterminate — Material convention. The track
|
||||
only reads as "remaining capacity", which is meaningless during
|
||||
an unbounded loop. */
|
||||
display: none;
|
||||
}
|
||||
|
||||
@keyframes r-pc-rotate {
|
||||
/* Start from the -90deg base (12 o'clock) and complete one full
|
||||
rotation per cycle. End value is `base + 360deg`. */
|
||||
from {
|
||||
transform: rotate(-90deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(270deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes r-pc-dash {
|
||||
/* pathLength=100 → dash values are percentages of the circle. */
|
||||
0% {
|
||||
stroke-dasharray: 1, 100;
|
||||
stroke-dashoffset: 0;
|
||||
}
|
||||
50% {
|
||||
stroke-dasharray: 60, 100;
|
||||
stroke-dashoffset: -15;
|
||||
}
|
||||
100% {
|
||||
stroke-dasharray: 60, 100;
|
||||
stroke-dashoffset: -75;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Content overlay — slot content centred over the ring ──────── */
|
||||
.r-pc__content {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 11px;
|
||||
font-weight: var(--r-font-weight-semibold);
|
||||
color: var(--r-pc-color);
|
||||
line-height: 1;
|
||||
/* Scale the slot text with the ring — `cqi` (container-inline-size)
|
||||
would be ideal but isn't universally supported on SVG-adjacent
|
||||
containers; the static 11px works for most uses. Consumers can
|
||||
override via inline font-size. */
|
||||
}
|
||||
|
||||
/* ── Reduced motion — drop the spinner animations ─────────────── */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.r-pc--indeterminate .r-pc__svg,
|
||||
.r-pc--indeterminate .r-pc__arc {
|
||||
animation: none;
|
||||
}
|
||||
/* Show a static partial arc so the spinner still communicates "busy"
|
||||
without the rotation. */
|
||||
.r-pc--indeterminate .r-pc__arc {
|
||||
stroke-dasharray: 30, 100;
|
||||
stroke-dashoffset: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -10,11 +10,6 @@ const meta: Meta<typeof RList> = {
|
||||
control: "select",
|
||||
options: ["default", "comfortable", "compact"],
|
||||
},
|
||||
nav: { control: "boolean" },
|
||||
lines: {
|
||||
control: "select",
|
||||
options: ["one", "two", "three", false],
|
||||
},
|
||||
rounded: { control: "text" },
|
||||
color: { control: "text" },
|
||||
bgColor: { control: "text" },
|
||||
@@ -25,13 +20,17 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RList>;
|
||||
|
||||
// Reusable wrap so stories share the framing chrome.
|
||||
const SHELL = `style="width:280px;border:1px solid var(--r-color-border);border-radius:var(--r-radius-md);background:var(--r-color-bg-elevated)"`;
|
||||
|
||||
// ── Defaults ────────────────────────────────────────────────────────
|
||||
|
||||
export const Navigation: Story = {
|
||||
args: { nav: true },
|
||||
render: (args) => ({
|
||||
components: { RList, RListItem },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="width: 280px; border: 1px solid var(--r-color-border); border-radius: var(--r-radius-md); padding: var(--r-space-2); background: var(--r-color-bg-elevated)">
|
||||
<div ${SHELL}>
|
||||
<RList v-bind="args">
|
||||
<RListItem prepend-icon="mdi-home" title="Home" active />
|
||||
<RListItem prepend-icon="mdi-controller" title="Platforms" />
|
||||
@@ -43,3 +42,127 @@ export const Navigation: Story = {
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Density ─────────────────────────────────────────────────────────
|
||||
|
||||
export const Density: Story = {
|
||||
name: "Density compression",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<div style="display:flex;gap:18px">
|
||||
<div ${SHELL}>
|
||||
<RList density="default">
|
||||
<RListItem prepend-icon="mdi-home" title="Default" />
|
||||
<RListItem prepend-icon="mdi-controller" title="Density" />
|
||||
<RListItem prepend-icon="mdi-magnify" title="Spacious" />
|
||||
</RList>
|
||||
</div>
|
||||
<div ${SHELL}>
|
||||
<RList density="comfortable">
|
||||
<RListItem prepend-icon="mdi-home" title="Comfortable" />
|
||||
<RListItem prepend-icon="mdi-controller" title="Density" />
|
||||
<RListItem prepend-icon="mdi-magnify" title="Mid-tight" />
|
||||
</RList>
|
||||
</div>
|
||||
<div ${SHELL}>
|
||||
<RList density="compact">
|
||||
<RListItem prepend-icon="mdi-home" title="Compact" />
|
||||
<RListItem prepend-icon="mdi-controller" title="Density" />
|
||||
<RListItem prepend-icon="mdi-magnify" title="Tight rows" />
|
||||
</RList>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Active tone ─────────────────────────────────────────────────────
|
||||
|
||||
export const ActiveColor: Story = {
|
||||
name: "Active tone (color prop)",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<div style="display:flex;gap:18px">
|
||||
<div ${SHELL}>
|
||||
<RList color="primary">
|
||||
<RListItem prepend-icon="mdi-home" title="primary" active />
|
||||
<RListItem prepend-icon="mdi-controller" title="active tone" />
|
||||
</RList>
|
||||
</div>
|
||||
<div ${SHELL}>
|
||||
<RList color="success">
|
||||
<RListItem prepend-icon="mdi-home" title="success" active />
|
||||
<RListItem prepend-icon="mdi-controller" title="active tone" />
|
||||
</RList>
|
||||
</div>
|
||||
<div ${SHELL}>
|
||||
<RList color="danger">
|
||||
<RListItem prepend-icon="mdi-home" title="danger" active />
|
||||
<RListItem prepend-icon="mdi-controller" title="active tone" />
|
||||
</RList>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Background paint ────────────────────────────────────────────────
|
||||
|
||||
export const SelfPainted: Story = {
|
||||
name: "Self-painted list (bgColor)",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<RList bg-color="var(--r-color-bg-elevated)" style="width:280px;border:1px solid var(--r-color-border)">
|
||||
<RListItem prepend-icon="mdi-account" title="With bgColor set" />
|
||||
<RListItem prepend-icon="mdi-bell" title="No outer wrapper needed" />
|
||||
<RListItem prepend-icon="mdi-cog" title="List paints itself" />
|
||||
</RList>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world ──────────────────────────────────────────────────────
|
||||
|
||||
export const SidebarNav: Story = {
|
||||
name: "Sidebar nav (Settings sidebar)",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<div ${SHELL}>
|
||||
<RList>
|
||||
<RListItem prepend-icon="mdi-account-circle" title="User profile" />
|
||||
<RListItem prepend-icon="mdi-palette" title="User interface" active />
|
||||
<RListItem prepend-icon="mdi-key-variant" title="Client API tokens" />
|
||||
<RListItem prepend-icon="mdi-shield-account" title="Administration" />
|
||||
<RListItem prepend-icon="mdi-folder-multiple-outline" title="Library management" />
|
||||
<RListItem prepend-icon="mdi-database" title="Metadata sources" />
|
||||
</RList>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const UserMenu: Story = {
|
||||
name: "User menu (with subtitle)",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<div ${SHELL}>
|
||||
<RList density="comfortable">
|
||||
<RListItem
|
||||
prepend-avatar="/assets/isotipo.svg"
|
||||
title="RomM Admin"
|
||||
subtitle="admin · last seen 3 min ago"
|
||||
/>
|
||||
<RListItem prepend-icon="mdi-account" title="Your profile" />
|
||||
<RListItem prepend-icon="mdi-cog" title="Settings" />
|
||||
<RListItem prepend-icon="mdi-theme-light-dark" title="Toggle theme" append-icon="mdi-chevron-right" />
|
||||
<RListItem prepend-icon="mdi-logout" title="Sign out" />
|
||||
</RList>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,45 +1,121 @@
|
||||
<script setup lang="ts">
|
||||
import { VList } from "vuetify/components/VList";
|
||||
// RList — Vuetify-free. Container for a vertical stack of RListItem
|
||||
// children. Plays two roles:
|
||||
//
|
||||
// • Semantic outer — wraps the items in `role="list"` so screen
|
||||
// readers announce the count + position regardless of how the
|
||||
// RListItem inner element is rendered (button / link / div).
|
||||
// • CSS context — emits `--r-list-item-h` and `--r-list-active-color`
|
||||
// custom properties that children inherit. Tweaking density or
|
||||
// active tone happens at the list, not on each item.
|
||||
//
|
||||
// `density` compresses item height. `color` drives the active highlight
|
||||
// (defaults to brand-primary). `bgColor` paints the list's own surface
|
||||
// — when set, the list reads as a self-contained card; otherwise it
|
||||
// stays transparent and sits inside whatever parent paints around it.
|
||||
import { computed } from "vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface Props {
|
||||
density?: "default" | "comfortable" | "compact";
|
||||
nav?: boolean;
|
||||
lines?: "one" | "two" | "three" | false;
|
||||
rounded?: string | number | boolean;
|
||||
/** Tone for the active item highlight. */
|
||||
color?: string;
|
||||
/** Optional background paint for the list itself. */
|
||||
bgColor?: string;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
density: "comfortable",
|
||||
lines: "one",
|
||||
rounded: "md",
|
||||
color: undefined,
|
||||
color: "primary",
|
||||
bgColor: undefined,
|
||||
});
|
||||
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
|
||||
const resolvedColor = computed<string>(
|
||||
() => TONE_MAP[props.color] ?? props.color ?? TONE_MAP.primary,
|
||||
);
|
||||
|
||||
const resolvedBg = computed<string | undefined>(() => {
|
||||
const b = props.bgColor;
|
||||
if (!b) return undefined;
|
||||
return TONE_MAP[b] ?? b;
|
||||
});
|
||||
|
||||
const ROUNDED_MAP: Record<string, string> = {
|
||||
"0": "0",
|
||||
sm: "4px",
|
||||
md: "8px",
|
||||
lg: "12px",
|
||||
xl: "16px",
|
||||
full: "999px",
|
||||
};
|
||||
const resolvedRounded = computed<string>(() => {
|
||||
const r = props.rounded;
|
||||
if (r === undefined || r === null || r === "") return "8px";
|
||||
if (r === true) return "999px";
|
||||
if (r === false) return "0";
|
||||
if (typeof r === "number") return `${r}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(r as string)) return `${r}px`;
|
||||
return ROUNDED_MAP[r as string] ?? String(r);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VList
|
||||
<ul
|
||||
v-bind="$attrs"
|
||||
role="list"
|
||||
class="r-list"
|
||||
:density="density"
|
||||
:nav="nav"
|
||||
:lines="lines"
|
||||
:rounded="rounded"
|
||||
:color="color"
|
||||
:bg-color="bgColor"
|
||||
:class="[`r-list--density-${density}`]"
|
||||
:style="{
|
||||
borderRadius: resolvedRounded,
|
||||
background: resolvedBg,
|
||||
'--r-list-active-color': resolvedColor,
|
||||
}"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VList>
|
||||
<slot />
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-list {
|
||||
background-color: transparent;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 4px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
color: var(--r-color-fg);
|
||||
/* Default item height (CSS var children read). Density overrides
|
||||
below. Min-height — items can grow vertically when subtitle is
|
||||
present without touching this. */
|
||||
--r-list-item-h: 40px;
|
||||
}
|
||||
|
||||
.r-list--density-default {
|
||||
--r-list-item-h: 48px;
|
||||
}
|
||||
.r-list--density-comfortable {
|
||||
--r-list-item-h: 40px;
|
||||
}
|
||||
.r-list--density-compact {
|
||||
--r-list-item-h: 32px;
|
||||
padding: 2px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { ref } from "vue";
|
||||
import RList from "../RList/RList.vue";
|
||||
import RListItem from "./RListItem.vue";
|
||||
|
||||
@@ -13,18 +14,13 @@ const meta: Meta<typeof RListItem> = {
|
||||
prependAvatar: { control: "text" },
|
||||
active: { control: "boolean" },
|
||||
disabled: { control: "boolean" },
|
||||
density: {
|
||||
control: "select",
|
||||
options: ["default", "comfortable", "compact"],
|
||||
},
|
||||
color: { control: "text" },
|
||||
rounded: { control: "text" },
|
||||
},
|
||||
render: (args) => ({
|
||||
components: { RList, RListItem },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="width: 280px; border: 1px solid var(--r-color-border); border-radius: var(--r-radius-md); padding: var(--r-space-2); background: var(--r-color-bg-elevated)">
|
||||
<div style="width:300px;border:1px solid var(--r-color-border);border-radius:var(--r-radius-md);background:var(--r-color-bg-elevated)">
|
||||
<RList>
|
||||
<RListItem v-bind="args" />
|
||||
</RList>
|
||||
@@ -37,6 +33,11 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RListItem>;
|
||||
|
||||
// Shared wrap snippet to keep the demos consistent.
|
||||
const SHELL = `style="width:300px;border:1px solid var(--r-color-border);border-radius:var(--r-radius-md);background:var(--r-color-bg-elevated)"`;
|
||||
|
||||
// ── Defaults ────────────────────────────────────────────────────────
|
||||
|
||||
export const Default: Story = {
|
||||
args: { title: "Plain item" },
|
||||
};
|
||||
@@ -57,23 +58,148 @@ export const Active: Story = {
|
||||
args: { title: "Active state", prependIcon: "mdi-cog", active: true },
|
||||
};
|
||||
|
||||
export const Gallery: Story = {
|
||||
export const Disabled: Story = {
|
||||
args: {
|
||||
title: "Disabled item",
|
||||
subtitle: "Pointer events suppressed",
|
||||
prependIcon: "mdi-lock",
|
||||
disabled: true,
|
||||
},
|
||||
};
|
||||
|
||||
// ── Prepend zone ────────────────────────────────────────────────────
|
||||
|
||||
export const PrependVariants: Story = {
|
||||
name: "Prepend · icon / avatar / slot",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<div style="width: 280px; border: 1px solid var(--r-color-border); border-radius: var(--r-radius-md); padding: var(--r-space-2); background: var(--r-color-bg-elevated)">
|
||||
<div ${SHELL}>
|
||||
<RList>
|
||||
<RListItem prepend-icon="mdi-account" title="Prepend icon" />
|
||||
<RListItem prepend-avatar="/assets/isotipo.svg" title="Prepend avatar" />
|
||||
<RListItem title="Custom prepend slot">
|
||||
<template #prepend>
|
||||
<span style="display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:6px;background:var(--r-color-success);color:white;font:600 11px/1 sans-serif">7</span>
|
||||
</template>
|
||||
</RListItem>
|
||||
</RList>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const AppendIcon: Story = {
|
||||
name: "Append icon (chevron right)",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<div ${SHELL}>
|
||||
<RList>
|
||||
<RListItem prepend-icon="mdi-account" title="Profile" append-icon="mdi-chevron-right" />
|
||||
<RListItem prepend-icon="mdi-bell" title="Notifications" append-icon="mdi-chevron-right" />
|
||||
<RListItem prepend-icon="mdi-cog" title="Settings" append-icon="mdi-chevron-right" />
|
||||
</RList>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Interactive ────────────────────────────────────────────────────
|
||||
|
||||
export const Interactive: Story = {
|
||||
name: "Click handler (interactive)",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
setup() {
|
||||
const log = ref<string[]>([]);
|
||||
function fire(name: string) {
|
||||
log.value = [...log.value, `Clicked ${name}`].slice(-4);
|
||||
}
|
||||
return { log, fire };
|
||||
},
|
||||
template: `
|
||||
<div style="display:flex;gap:20px;align-items:flex-start">
|
||||
<div ${SHELL}>
|
||||
<RList>
|
||||
<RListItem prepend-icon="mdi-pencil" title="Edit" @click="fire('Edit')" />
|
||||
<RListItem prepend-icon="mdi-content-copy" title="Duplicate" @click="fire('Duplicate')" />
|
||||
<RListItem prepend-icon="mdi-share-variant" title="Share" @click="fire('Share')" />
|
||||
<RListItem prepend-icon="mdi-delete" title="Delete" @click="fire('Delete')" />
|
||||
</RList>
|
||||
</div>
|
||||
<div style="font:12px/1.5 monospace;color:var(--r-color-fg-muted);min-width:160px">
|
||||
<div style="margin-bottom:6px;color:var(--r-color-fg-faint)">log:</div>
|
||||
<div v-for="(l, i) in log" :key="i">{{ l }}</div>
|
||||
<div v-if="!log.length">(no clicks yet)</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const NonInteractive: Story = {
|
||||
name: "Display-only (no hover)",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<div ${SHELL}>
|
||||
<RList>
|
||||
<RListItem prepend-icon="mdi-information" title="Read-only row" subtitle="Hover doesn't tint" />
|
||||
<RListItem prepend-icon="mdi-format-list-bulleted" title="No click handler" subtitle="No to / href / @click" />
|
||||
</RList>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Polymorphic ─────────────────────────────────────────────────────
|
||||
|
||||
export const AsLink: Story = {
|
||||
name: "Polymorphic (href / to)",
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<div ${SHELL}>
|
||||
<RList>
|
||||
<RListItem title="Plain item" />
|
||||
<RListItem prepend-icon="mdi-play" title="With prepend icon" />
|
||||
<RListItem
|
||||
prepend-icon="mdi-star"
|
||||
title="Two-line row"
|
||||
subtitle="Subtitle lives here"
|
||||
href="https://romm.app"
|
||||
target="_blank"
|
||||
prepend-icon="mdi-link-variant"
|
||||
append-icon="mdi-open-in-new"
|
||||
title="External link (<a>)"
|
||||
subtitle="opens in new tab"
|
||||
/>
|
||||
<RListItem
|
||||
prepend-icon="mdi-cog"
|
||||
title="Active state"
|
||||
active
|
||||
href="#"
|
||||
prepend-icon="mdi-account"
|
||||
title="Anchor disabled"
|
||||
subtitle="href stripped — keyboard inert"
|
||||
disabled
|
||||
/>
|
||||
</RList>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Gallery ─────────────────────────────────────────────────────────
|
||||
|
||||
export const Gallery: Story = {
|
||||
render: () => ({
|
||||
components: { RList, RListItem },
|
||||
template: `
|
||||
<div ${SHELL}>
|
||||
<RList>
|
||||
<RListItem title="Plain item" />
|
||||
<RListItem prepend-icon="mdi-play" title="With prepend icon" />
|
||||
<RListItem prepend-icon="mdi-star" title="Two-line row" subtitle="Subtitle lives here" />
|
||||
<RListItem prepend-icon="mdi-cog" title="Active state" active />
|
||||
<RListItem prepend-icon="mdi-lock" title="Disabled" disabled />
|
||||
<RListItem
|
||||
prepend-avatar="/assets/isotipo.svg"
|
||||
title="With avatar"
|
||||
append-icon="mdi-chevron-right"
|
||||
/>
|
||||
</RList>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { VListItem } from "vuetify/components/VList";
|
||||
// RListItem — Vuetify-free. Semantic `<li>` wrapping a polymorphic
|
||||
// interactive inner element:
|
||||
//
|
||||
// • `to` → RouterLink (router-aware)
|
||||
// • `href` → <a>
|
||||
// • on-click listener present → <button>
|
||||
// • otherwise → <div> (non-interactive, display-only)
|
||||
//
|
||||
// The outer `<li>` keeps screen-reader counting correct regardless of
|
||||
// the inner element. The inner element receives hover / active /
|
||||
// disabled styling so a display-only RListItem doesn't react to mouse
|
||||
// movement (no false affordance).
|
||||
//
|
||||
// `prepend-icon` + `prepend-avatar` are mutually exclusive — avatar
|
||||
// wins if both are set (it's the more specific affordance). The
|
||||
// `prepend` / `append` slots win over the props.
|
||||
//
|
||||
// Title + subtitle render in a stacked block; subtitle is muted. Pair
|
||||
// with `density="compact"` on the parent RList for an inline single-
|
||||
// line look (subtitle wraps under).
|
||||
import { computed, useAttrs, useSlots } from "vue";
|
||||
import { RouterLink, type RouteLocationRaw } from "vue-router";
|
||||
import RAvatar from "../../primitives/RAvatar/RAvatar.vue";
|
||||
import RIcon from "../../primitives/RIcon/RIcon.vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
@@ -10,56 +33,271 @@ interface Props {
|
||||
prependIcon?: string;
|
||||
appendIcon?: string;
|
||||
prependAvatar?: string;
|
||||
/** Highlights the item with the list's `--r-list-active-color`. */
|
||||
active?: boolean;
|
||||
disabled?: boolean;
|
||||
density?: "default" | "comfortable" | "compact";
|
||||
to?: string | object;
|
||||
to?: RouteLocationRaw;
|
||||
href?: string;
|
||||
color?: string;
|
||||
target?: string;
|
||||
rounded?: string | number | boolean;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
title: undefined,
|
||||
subtitle: undefined,
|
||||
value: undefined,
|
||||
prependIcon: undefined,
|
||||
appendIcon: undefined,
|
||||
prependAvatar: undefined,
|
||||
density: "comfortable",
|
||||
active: false,
|
||||
disabled: false,
|
||||
to: undefined,
|
||||
href: undefined,
|
||||
color: "primary",
|
||||
rounded: "md",
|
||||
target: undefined,
|
||||
rounded: undefined,
|
||||
});
|
||||
|
||||
const slots = useSlots();
|
||||
const attrs = useAttrs();
|
||||
|
||||
// Interactive if any of: `to` / `href` / `@click` (any onXxx listener).
|
||||
// We can't observe individual handler types so we check for the click
|
||||
// attr explicitly — anything else (focus, mouseenter…) doesn't promote
|
||||
// the item to a button.
|
||||
const hasClickHandler = computed(() => "onClick" in attrs);
|
||||
|
||||
const elementType = computed(() => {
|
||||
if (props.to !== undefined && props.to !== null) return RouterLink;
|
||||
if (props.href !== undefined && props.href !== null) return "a";
|
||||
if (hasClickHandler.value) return "button";
|
||||
return "div";
|
||||
});
|
||||
|
||||
const dynamicAttrs = computed<Record<string, unknown>>(() => {
|
||||
if (props.to !== undefined && props.to !== null) {
|
||||
return {
|
||||
to: props.to,
|
||||
ariaDisabled: props.disabled ? "true" : undefined,
|
||||
};
|
||||
}
|
||||
if (props.href !== undefined && props.href !== null) {
|
||||
return {
|
||||
href: props.disabled ? undefined : props.href,
|
||||
target: props.target,
|
||||
ariaDisabled: props.disabled ? "true" : undefined,
|
||||
};
|
||||
}
|
||||
if (hasClickHandler.value) {
|
||||
return { type: "button", disabled: props.disabled };
|
||||
}
|
||||
return {};
|
||||
});
|
||||
|
||||
const ROUNDED_MAP: Record<string, string> = {
|
||||
"0": "0",
|
||||
sm: "4px",
|
||||
md: "8px",
|
||||
lg: "12px",
|
||||
xl: "16px",
|
||||
full: "999px",
|
||||
};
|
||||
const resolvedRounded = computed<string>(() => {
|
||||
const r = props.rounded;
|
||||
if (r === undefined || r === null || r === "") return "6px";
|
||||
if (r === true) return "999px";
|
||||
if (r === false) return "0";
|
||||
if (typeof r === "number") return `${r}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(r as string)) return `${r}px`;
|
||||
return ROUNDED_MAP[r as string] ?? String(r);
|
||||
});
|
||||
|
||||
const isInteractive = computed(
|
||||
() => elementType.value !== "div" && !props.disabled,
|
||||
);
|
||||
|
||||
// Avatar wins over icon when both are set — kept as a separate
|
||||
// computed so the template stays readable.
|
||||
const showAvatar = computed(() => !!props.prependAvatar);
|
||||
const showPrependIcon = computed(
|
||||
() => !showAvatar.value && !!props.prependIcon,
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VListItem
|
||||
v-bind="$attrs"
|
||||
class="r-list-item"
|
||||
:title="title"
|
||||
:subtitle="subtitle"
|
||||
:value="value"
|
||||
:prepend-icon="prependIcon"
|
||||
:append-icon="appendIcon"
|
||||
:prepend-avatar="prependAvatar"
|
||||
:active="active"
|
||||
:disabled="disabled"
|
||||
:density="density"
|
||||
:to="to"
|
||||
:href="href"
|
||||
:color="color"
|
||||
:rounded="rounded"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VListItem>
|
||||
<li class="r-list-item-wrap">
|
||||
<component
|
||||
:is="elementType"
|
||||
v-bind="{ ...$attrs, ...dynamicAttrs }"
|
||||
class="r-list-item"
|
||||
:class="{
|
||||
'r-list-item--active': active,
|
||||
'r-list-item--disabled': disabled,
|
||||
'r-list-item--interactive': isInteractive,
|
||||
}"
|
||||
:style="{ borderRadius: resolvedRounded }"
|
||||
>
|
||||
<!-- Prepend zone — slot wins; otherwise avatar wins over icon. -->
|
||||
<span
|
||||
v-if="slots.prepend || showAvatar || showPrependIcon"
|
||||
class="r-list-item__prepend"
|
||||
>
|
||||
<slot name="prepend">
|
||||
<RAvatar v-if="showAvatar" :image="prependAvatar" size="32" />
|
||||
<RIcon
|
||||
v-else-if="showPrependIcon"
|
||||
:icon="prependIcon"
|
||||
class="r-list-item__icon"
|
||||
/>
|
||||
</slot>
|
||||
</span>
|
||||
|
||||
<!-- Body — title + subtitle stacked. The default slot lives on
|
||||
top so consumers can drop arbitrary content (forms, chips,
|
||||
etc.) instead of just text. -->
|
||||
<span class="r-list-item__body">
|
||||
<span v-if="title || slots.title" class="r-list-item__title">
|
||||
<slot name="title">{{ title }}</slot>
|
||||
</span>
|
||||
<span v-if="subtitle || slots.subtitle" class="r-list-item__subtitle">
|
||||
<slot name="subtitle">{{ subtitle }}</slot>
|
||||
</span>
|
||||
<slot />
|
||||
</span>
|
||||
|
||||
<!-- Append zone — slot wins over `appendIcon` prop. -->
|
||||
<span v-if="slots.append || appendIcon" class="r-list-item__append">
|
||||
<slot name="append">
|
||||
<RIcon
|
||||
v-if="appendIcon"
|
||||
:icon="appendIcon"
|
||||
class="r-list-item__icon"
|
||||
/>
|
||||
</slot>
|
||||
</span>
|
||||
</component>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* The outer <li> is invisible — it's a semantic shell. All of the
|
||||
visual styling lives on the inner `.r-list-item`. */
|
||||
.r-list-item-wrap {
|
||||
list-style: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.r-list-item {
|
||||
color: var(--r-color-fg);
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-height: var(--r-list-item-h, 40px);
|
||||
padding: 6px 10px;
|
||||
width: 100%;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
text-align: left;
|
||||
text-decoration: none;
|
||||
font: inherit;
|
||||
border: 1px solid transparent;
|
||||
cursor: default;
|
||||
user-select: none;
|
||||
outline: none;
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
/* button reset — when interactive, the inner element is a <button>;
|
||||
strip its native defaults so it reads as a list row, not a button. */
|
||||
button.r-list-item,
|
||||
a.r-list-item {
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
.r-list-item--interactive {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Hover overlay — single `::before` painted in currentColor.
|
||||
Composes cleanly with any list background. Only kicks in on
|
||||
interactive items so display-only rows don't react. */
|
||||
.r-list-item::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: currentColor;
|
||||
opacity: 0;
|
||||
border-radius: inherit;
|
||||
pointer-events: none;
|
||||
transition: opacity var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
.r-list-item--interactive:hover::before {
|
||||
opacity: 0.08;
|
||||
}
|
||||
.r-list-item--interactive:active::before {
|
||||
opacity: 0.14;
|
||||
}
|
||||
|
||||
/* ── Active state — tinted with the list's active colour ──────── */
|
||||
.r-list-item--active {
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--r-list-active-color, var(--r-color-brand-primary)) 14%,
|
||||
transparent
|
||||
);
|
||||
color: var(--r-list-active-color, var(--r-color-brand-primary));
|
||||
}
|
||||
.r-list-item--active.r-list-item--interactive:hover::before {
|
||||
opacity: 0.06;
|
||||
}
|
||||
|
||||
/* ── Disabled ──────────────────────────────────────────────────── */
|
||||
.r-list-item--disabled {
|
||||
opacity: 0.45;
|
||||
pointer-events: none;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* ── Layout regions ──────────────────────────────────────────── */
|
||||
.r-list-item__prepend,
|
||||
.r-list-item__append {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
color: inherit;
|
||||
}
|
||||
.r-list-item__icon {
|
||||
font-size: 18px;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.r-list-item__body {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.r-list-item__title {
|
||||
font-size: 13px;
|
||||
font-weight: var(--r-font-weight-medium);
|
||||
color: inherit;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.r-list-item__subtitle {
|
||||
font-size: 11px;
|
||||
color: var(--r-color-fg-muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.r-list-item--active .r-list-item__subtitle {
|
||||
/* Subtitle in an active row inherits the active tone but stays
|
||||
slightly faded so the title remains dominant. */
|
||||
color: color-mix(in srgb, currentColor 70%, transparent);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -23,13 +23,29 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<typeof RToolbar>;
|
||||
|
||||
export const WithTitleAndActions: Story = {
|
||||
// ── Defaults ────────────────────────────────────────────────────────
|
||||
|
||||
export const Default: Story = {
|
||||
args: { title: "Platforms" },
|
||||
render: (args) => ({
|
||||
components: { RToolbar, RBtn, RIcon },
|
||||
components: { RToolbar },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="width: 720px">
|
||||
<div style="width:720px;border-radius:8px;overflow:hidden;border:1px solid var(--r-color-border)">
|
||||
<RToolbar v-bind="args" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const WithActions: Story = {
|
||||
name: "Title + append actions",
|
||||
args: { title: "Platforms" },
|
||||
render: (args) => ({
|
||||
components: { RToolbar, RBtn },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="width:720px;border-radius:8px;overflow:hidden;border:1px solid var(--r-color-border)">
|
||||
<RToolbar v-bind="args">
|
||||
<template #append>
|
||||
<RBtn variant="text" prepend-icon="mdi-filter">Filters</RBtn>
|
||||
@@ -40,3 +56,179 @@ export const WithTitleAndActions: Story = {
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const WithPrepend: Story = {
|
||||
name: "Prepend (back button)",
|
||||
args: { title: "Super Mario Bros." },
|
||||
render: (args) => ({
|
||||
components: { RToolbar, RBtn },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="width:720px;border-radius:8px;overflow:hidden;border:1px solid var(--r-color-border)">
|
||||
<RToolbar v-bind="args">
|
||||
<template #prepend>
|
||||
<RBtn icon="mdi-arrow-left" variant="text" aria-label="Back" />
|
||||
</template>
|
||||
<template #append>
|
||||
<RBtn icon="mdi-pencil" variant="text" aria-label="Edit" />
|
||||
<RBtn icon="mdi-dots-vertical" variant="text" aria-label="More" />
|
||||
</template>
|
||||
</RToolbar>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Density ─────────────────────────────────────────────────────────
|
||||
|
||||
export const DensityLadder: Story = {
|
||||
name: "Density ladder",
|
||||
render: () => ({
|
||||
components: { RToolbar, RBtn },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:14px;width:720px">
|
||||
<div style="border-radius:8px;overflow:hidden;border:1px solid var(--r-color-border)">
|
||||
<RToolbar title="Default · 64px">
|
||||
<template #append>
|
||||
<RBtn variant="text" size="small">Action</RBtn>
|
||||
</template>
|
||||
</RToolbar>
|
||||
</div>
|
||||
<div style="border-radius:8px;overflow:hidden;border:1px solid var(--r-color-border)">
|
||||
<RToolbar density="comfortable" title="Comfortable · 56px">
|
||||
<template #append>
|
||||
<RBtn variant="text" size="small">Action</RBtn>
|
||||
</template>
|
||||
</RToolbar>
|
||||
</div>
|
||||
<div style="border-radius:8px;overflow:hidden;border:1px solid var(--r-color-border)">
|
||||
<RToolbar density="compact" title="Compact · 48px">
|
||||
<template #append>
|
||||
<RBtn variant="text" size="small">Action</RBtn>
|
||||
</template>
|
||||
</RToolbar>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Variants ────────────────────────────────────────────────────────
|
||||
|
||||
export const Flat: Story = {
|
||||
name: "Flat (no bottom border)",
|
||||
args: { title: "Settings", flat: true },
|
||||
render: (args) => ({
|
||||
components: { RToolbar, RBtn },
|
||||
setup: () => ({ args }),
|
||||
template: `
|
||||
<div style="width:720px">
|
||||
<RToolbar v-bind="args">
|
||||
<template #append>
|
||||
<RBtn variant="text">Reset</RBtn>
|
||||
<RBtn color="primary">Save</RBtn>
|
||||
</template>
|
||||
</RToolbar>
|
||||
<div style="padding:24px;color:var(--r-color-fg-muted);font:12px/1.4 sans-serif">
|
||||
Toolbar sits flush with the body — no hairline divider.
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const Colored: Story = {
|
||||
name: "Coloured toolbars",
|
||||
render: () => ({
|
||||
components: { RToolbar, RBtn },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:14px;width:720px">
|
||||
<RToolbar color="primary" title="Primary">
|
||||
<template #append>
|
||||
<RBtn variant="text" prepend-icon="mdi-bell" />
|
||||
<RBtn variant="text" prepend-icon="mdi-account-circle" />
|
||||
</template>
|
||||
</RToolbar>
|
||||
<RToolbar color="success" title="Success — scan complete">
|
||||
<template #prepend>
|
||||
<RBtn icon="mdi-check-circle" variant="text" aria-label="ok" />
|
||||
</template>
|
||||
</RToolbar>
|
||||
<RToolbar color="danger" title="Connection lost">
|
||||
<template #append>
|
||||
<RBtn variant="text">Retry</RBtn>
|
||||
</template>
|
||||
</RToolbar>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Rounded + height ────────────────────────────────────────────────
|
||||
|
||||
export const RoundedAndHeight: Story = {
|
||||
name: "Rounded + custom height",
|
||||
render: () => ({
|
||||
components: { RToolbar, RBtn },
|
||||
template: `
|
||||
<div style="display:flex;flex-direction:column;gap:14px;width:720px">
|
||||
<RToolbar rounded="lg" title="rounded='lg'">
|
||||
<template #append>
|
||||
<RBtn variant="text" prepend-icon="mdi-cog">Settings</RBtn>
|
||||
</template>
|
||||
</RToolbar>
|
||||
<RToolbar :height="80" title="height=80 (taller)">
|
||||
<template #append>
|
||||
<RBtn color="primary" prepend-icon="mdi-plus">Add</RBtn>
|
||||
</template>
|
||||
</RToolbar>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
// ── Real-world ──────────────────────────────────────────────────────
|
||||
|
||||
export const GalleryHeader: Story = {
|
||||
name: "Gallery header (real-world)",
|
||||
render: () => ({
|
||||
components: { RToolbar, RBtn, RIcon },
|
||||
template: `
|
||||
<div style="width:720px;border-radius:12px;overflow:hidden;border:1px solid var(--r-color-border);background:var(--r-color-bg-elevated)">
|
||||
<RToolbar title="Nintendo 64" flat>
|
||||
<template #prepend>
|
||||
<RBtn icon="mdi-arrow-left" variant="text" aria-label="Back" />
|
||||
</template>
|
||||
<template #append>
|
||||
<RBtn variant="text" prepend-icon="mdi-magnify" />
|
||||
<RBtn variant="text" prepend-icon="mdi-filter">Filters</RBtn>
|
||||
<RBtn variant="text" prepend-icon="mdi-sort-variant">Sort</RBtn>
|
||||
<RBtn icon="mdi-dots-vertical" variant="text" aria-label="More" />
|
||||
</template>
|
||||
</RToolbar>
|
||||
<div style="padding:20px;color:var(--r-color-fg-muted);font:13px/1.5 sans-serif">
|
||||
128 ROMs · 4 missing · last scan 3 hours ago
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
export const DialogTitleRow: Story = {
|
||||
name: "Dialog title row",
|
||||
render: () => ({
|
||||
components: { RToolbar, RBtn },
|
||||
template: `
|
||||
<div style="width:480px;border-radius:12px;overflow:hidden;border:1px solid var(--r-color-border);background:var(--r-color-bg-elevated);box-shadow:0 12px 30px color-mix(in srgb, black 30%, transparent)">
|
||||
<RToolbar density="compact" title="Edit ROM" flat>
|
||||
<template #append>
|
||||
<RBtn icon="mdi-close" variant="text" aria-label="Close" />
|
||||
</template>
|
||||
</RToolbar>
|
||||
<div style="padding:18px 16px;color:var(--r-color-fg-muted);font:13px/1.5 sans-serif">
|
||||
Dialog body — toolbar acts as the title row.
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,46 +1,206 @@
|
||||
<script setup lang="ts">
|
||||
import { VToolbar } from "vuetify/components/VToolbar";
|
||||
// RToolbar — Vuetify-free. Horizontal flex bar with four ordered
|
||||
// regions: `prepend → title → default → append`. Designed for app
|
||||
// bars, gallery headers, dialog title rows — anywhere you want a
|
||||
// header strip that holds a label on the left and actions on the
|
||||
// right.
|
||||
//
|
||||
// `flat` removes the bottom hairline (default look has one so the
|
||||
// toolbar reads as a distinct surface above the content below).
|
||||
// `color` paints the bar in a tone (white text); otherwise the bar
|
||||
// uses the page's elevated bg.
|
||||
//
|
||||
// `height` is an explicit override. Without it the height is driven
|
||||
// by the density ladder (48 / 56 / 64 px).
|
||||
import { computed, useSlots } from "vue";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
interface Props {
|
||||
/** Background tone — keyword / `romm-*` / any CSS colour. */
|
||||
color?: string;
|
||||
density?: "default" | "comfortable" | "compact";
|
||||
/** Drops the bottom border. */
|
||||
flat?: boolean;
|
||||
/** Auto-rendered title text — slot `#title` overrides. */
|
||||
title?: string;
|
||||
/** Explicit height override (number → px / any CSS length). */
|
||||
height?: number | string;
|
||||
rounded?: string | number | boolean;
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
color: undefined,
|
||||
density: "default",
|
||||
flat: false,
|
||||
title: undefined,
|
||||
height: undefined,
|
||||
rounded: undefined,
|
||||
});
|
||||
|
||||
const slots = useSlots();
|
||||
|
||||
const TONE_MAP: Record<string, string> = {
|
||||
primary: "var(--r-color-brand-primary)",
|
||||
secondary: "var(--r-color-brand-secondary)",
|
||||
accent: "var(--r-color-brand-accent)",
|
||||
success: "var(--r-color-success)",
|
||||
warning: "var(--r-color-warning)",
|
||||
danger: "var(--r-color-danger)",
|
||||
error: "var(--r-color-danger)",
|
||||
info: "var(--r-color-info)",
|
||||
"romm-red": "var(--r-color-romm-red)",
|
||||
"romm-green": "var(--r-color-romm-green)",
|
||||
"romm-blue": "var(--r-color-romm-blue)",
|
||||
"romm-gold": "var(--r-color-romm-gold)",
|
||||
};
|
||||
|
||||
const resolvedColor = computed<string | undefined>(() => {
|
||||
const c = props.color;
|
||||
if (!c) return undefined;
|
||||
return TONE_MAP[c] ?? c;
|
||||
});
|
||||
|
||||
const ROUNDED_MAP: Record<string, string> = {
|
||||
"0": "0",
|
||||
sm: "4px",
|
||||
md: "8px",
|
||||
lg: "12px",
|
||||
xl: "16px",
|
||||
full: "999px",
|
||||
};
|
||||
const resolvedRounded = computed<string | undefined>(() => {
|
||||
const r = props.rounded;
|
||||
if (r === undefined || r === null || r === "") return undefined;
|
||||
if (r === true) return "999px";
|
||||
if (r === false) return "0";
|
||||
if (typeof r === "number") return `${r}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(r as string)) return `${r}px`;
|
||||
return ROUNDED_MAP[r as string] ?? String(r);
|
||||
});
|
||||
|
||||
const resolvedHeight = computed<string | undefined>(() => {
|
||||
const h = props.height;
|
||||
if (h === undefined || h === null || h === "") return undefined;
|
||||
if (typeof h === "number") return `${h}px`;
|
||||
if (/^\d+(\.\d+)?$/.test(h as string)) return `${h}px`;
|
||||
return String(h);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VToolbar
|
||||
<div
|
||||
v-bind="$attrs"
|
||||
class="r-toolbar"
|
||||
:color="color"
|
||||
:density="density"
|
||||
:flat="flat"
|
||||
:title="title"
|
||||
:height="height"
|
||||
:rounded="rounded"
|
||||
:class="[
|
||||
`r-toolbar--density-${density}`,
|
||||
{
|
||||
'r-toolbar--has-color': !!resolvedColor,
|
||||
'r-toolbar--flat': flat,
|
||||
},
|
||||
]"
|
||||
:style="{
|
||||
height: resolvedHeight,
|
||||
borderRadius: resolvedRounded,
|
||||
'--r-toolbar-color': resolvedColor,
|
||||
}"
|
||||
role="toolbar"
|
||||
>
|
||||
<template v-for="(_, slot) in $slots" #[slot]="slotProps">
|
||||
<slot :name="slot" v-bind="slotProps || {}" />
|
||||
</template>
|
||||
</VToolbar>
|
||||
<!-- Prepend region (icons, back button, drawer toggle…). -->
|
||||
<span v-if="slots.prepend" class="r-toolbar__prepend">
|
||||
<slot name="prepend" />
|
||||
</span>
|
||||
|
||||
<!-- Title — slot wins over prop. Title is given a min-width: 0 so
|
||||
long labels can ellipsis instead of pushing the action row off
|
||||
screen. -->
|
||||
<span v-if="title || slots.title" class="r-toolbar__title">
|
||||
<slot name="title">{{ title }}</slot>
|
||||
</span>
|
||||
|
||||
<!-- Default slot — the "body". A horizontal spacer is appended
|
||||
after it so anything in `#append` floats to the right edge
|
||||
even when the default slot is empty. -->
|
||||
<span class="r-toolbar__body">
|
||||
<slot />
|
||||
</span>
|
||||
<span class="r-toolbar__spacer" aria-hidden="true" />
|
||||
|
||||
<!-- Append region (action buttons, filters, sort dropdown…). -->
|
||||
<span v-if="slots.append" class="r-toolbar__append">
|
||||
<slot name="append" />
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.r-toolbar {
|
||||
background-color: var(--r-color-bg-elevated);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
background: var(--r-toolbar-color, var(--r-color-bg-elevated));
|
||||
color: var(--r-color-fg);
|
||||
border-bottom: 1px solid var(--r-color-border);
|
||||
/* Smooth tone / theme swaps so a toolbar that changes colour mid-
|
||||
route doesn't pop. */
|
||||
transition:
|
||||
background var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
border-color var(--r-motion-fast) var(--r-motion-ease-out),
|
||||
color var(--r-motion-fast) var(--r-motion-ease-out);
|
||||
}
|
||||
|
||||
.r-toolbar--has-color {
|
||||
/* Coloured toolbars paint white text on top of the brand fill. */
|
||||
color: white;
|
||||
}
|
||||
|
||||
.r-toolbar--flat {
|
||||
border-bottom-color: transparent;
|
||||
}
|
||||
|
||||
/* ── Density — drives height + padding ───────────────────────── */
|
||||
.r-toolbar--density-default {
|
||||
height: 64px;
|
||||
padding: 0 16px;
|
||||
}
|
||||
.r-toolbar--density-comfortable {
|
||||
height: 56px;
|
||||
padding: 0 14px;
|
||||
}
|
||||
.r-toolbar--density-compact {
|
||||
height: 48px;
|
||||
padding: 0 12px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
/* ── Regions ──────────────────────────────────────────────────── */
|
||||
.r-toolbar__prepend,
|
||||
.r-toolbar__append {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.r-toolbar__title {
|
||||
/* Reasonable title weight without screaming. The `min-width: 0` is
|
||||
load-bearing: without it, a long title would push the body / append
|
||||
past the right edge instead of ellipsising. */
|
||||
font-size: 16px;
|
||||
font-weight: var(--r-font-weight-semibold);
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.r-toolbar__body {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.r-toolbar__spacer {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -83,7 +83,7 @@ export const ParentAttach: Story = {
|
||||
components: { RTooltip, RBtn },
|
||||
template: `
|
||||
<div class="r-v2 r-v2-dark" style="padding: 48px; background: #07070f;">
|
||||
<RBtn icon="mdi-delete" variant="tonal">
|
||||
<RBtn icon="mdi-delete" variant="translucent">
|
||||
<RTooltip activator="parent" text="Delete this item" location="top" />
|
||||
</RBtn>
|
||||
</div>
|
||||
|
||||
@@ -165,7 +165,7 @@ watch(
|
||||
<span class="r-eyebrow">{{ kindLabel }}</span>
|
||||
</template>
|
||||
<template v-if="description" #tags>
|
||||
<RChip size="small" variant="tonal" :rounded="20">
|
||||
<RChip size="small" variant="translucent" :rounded="20">
|
||||
{{ description }}
|
||||
</RChip>
|
||||
</template>
|
||||
|
||||
@@ -144,7 +144,7 @@ watch(
|
||||
v-for="t in tags"
|
||||
:key="t"
|
||||
size="small"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
:rounded="20"
|
||||
>
|
||||
{{ t }}
|
||||
|
||||
@@ -111,7 +111,7 @@ async function copyCode() {
|
||||
{{ formattedCode }}
|
||||
</div>
|
||||
<RBtn
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
color="primary"
|
||||
prepend-icon="mdi-content-copy"
|
||||
@click="copyCode"
|
||||
|
||||
@@ -516,7 +516,7 @@ void useLocalStorage;
|
||||
|
||||
<RBtn
|
||||
block
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
color="primary"
|
||||
:prepend-icon="currentAsset ? 'mdi-swap-horizontal' : 'mdi-plus'"
|
||||
:disabled="
|
||||
|
||||
@@ -244,7 +244,7 @@ onMounted(async () => {
|
||||
<div id="r-v2-ruffle-stage" class="r-v2-ruffle__stage" />
|
||||
<RBtn
|
||||
class="r-v2-ruffle__quit"
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
prepend-icon="mdi-exit-to-app"
|
||||
@click="onlyQuit"
|
||||
>
|
||||
|
||||
@@ -197,7 +197,9 @@ onMounted(() => {
|
||||
v-for="source in catalogs"
|
||||
:key="source.value"
|
||||
class="r-v2-meta__card"
|
||||
:class="{ 'r-v2-meta__card--missing': statusOf(source) === 'missing' }"
|
||||
:class="{
|
||||
'r-v2-meta__card--missing': statusOf(source) === 'missing',
|
||||
}"
|
||||
>
|
||||
<header class="r-v2-meta__header">
|
||||
<div class="r-v2-meta__logo">
|
||||
@@ -219,7 +221,7 @@ onMounted(() => {
|
||||
|
||||
<div class="r-v2-meta__actions">
|
||||
<RBtn
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
size="small"
|
||||
prepend-icon="mdi-key-variant"
|
||||
:href="source.docsUrl"
|
||||
@@ -252,7 +254,9 @@ onMounted(() => {
|
||||
v-for="source in specialised"
|
||||
:key="source.value"
|
||||
class="r-v2-meta__card"
|
||||
:class="{ 'r-v2-meta__card--missing': statusOf(source) === 'missing' }"
|
||||
:class="{
|
||||
'r-v2-meta__card--missing': statusOf(source) === 'missing',
|
||||
}"
|
||||
>
|
||||
<header class="r-v2-meta__header">
|
||||
<div class="r-v2-meta__logo">
|
||||
@@ -274,7 +278,7 @@ onMounted(() => {
|
||||
|
||||
<div class="r-v2-meta__actions">
|
||||
<RBtn
|
||||
variant="tonal"
|
||||
variant="translucent"
|
||||
size="small"
|
||||
prepend-icon="mdi-key-variant"
|
||||
:href="source.docsUrl"
|
||||
|
||||
Reference in New Issue
Block a user