feat(panels): build the rail panels on one UiPanel

The Data, Authoring, Weather, Recent Imagery, Context, CCTV, Street Level
and Radio panels each wrote the same frame by hand. They are now one kit
component, UiPanel, with a title, badge/actions/default slots and
v-model:collapsed, drawing Core's panel markup and classes beside the kit's;
props cover the differences (sideways, glow, scroll, railScroller, tag,
toggleWords). RailPanel binds it to the panel chrome store: v-panel-state
writes its state classes at once, and its button's clicks reach PanelChrome.
UiPanelToggle is the collapse button UiPanel and PanelCollapseButton share.

UiPanel's collapsed drives the button and ui-panel--collapsed
only; the owner hides the body by writing the root's collapsed class, since
the rails measure a panel in the task that opens it. PanelCollapseButton
takes startCollapsed instead of initial and initialTitle, so a button shows
its state's glyph and words before startup presents the panel. Titles render
through t() instead of data-i18n, and the unused "Expand panel" string is
pruned. v-panel-state redraws the presented state after a re-render, in
case a root's class binding ever changes.
This commit is contained in:
Sameh Khamis committed 2026-11-01 08:33:18 -08:00
1 parent a3fc475cbe
commit cd231faae9
30 files changed
+427 -197

No files matched your search

+17 -49
View File
@@ -1,66 +1,34 @@
<script setup>
import { storeToRefs } from 'pinia';
import { computed } from 'vue';
import { msg, t } from '../../i18n/index.js';
import UiButton from '../kit/UiButton.vue';
import UiPanelToggle from '../kit/UiPanelToggle.vue';
import { usePanelChromeStore } from '../stores/panelChrome.js';
// A panel's collapse button: its glyph, aria-expanded and words follow the
// panel's state in the panel chrome store, and a click asks PanelChrome to
// toggle it. Until PanelChrome presents the panel it shows its markup's glyph
// and tip.
// The collapse button of a panel not built on UiPanel: it follows the panel's
// state in the panel chrome store, and a click asks PanelChrome to toggle it.
// Until PanelChrome presents the panel it follows the markup's state.
const props = defineProps({
target: { type: String, required: true },
/** The panel's name in "Expand {name}", already translated. */
name: { type: String, default: () => t('panel') },
/** A right-rail panel opens and closes sideways: ◀ / ▶, not + / −. */
name: { type: String, default: undefined },
sideways: { type: Boolean, default: false },
/** The glyph and tip before the panel is presented. */
initial: { type: String, required: true },
initialTitle: { type: String, default: () => t('Collapse panel') },
/** Words that replace "Expand/Collapse {name}" (Radio's own wording). */
words: { type: Object, default: null },
/** Whether the panel's markup starts collapsed. */
startCollapsed: { type: Boolean, default: false },
});
const chrome = usePanelChromeStore();
const { panels } = storeToRefs(chrome);
const state = computed(() => panels.value[props.target]);
const glyph = computed(() => {
if (!state.value) return props.initial;
if (props.sideways) return state.value.collapsed ? '◀' : '▶';
return state.value.collapsed ? '+' : '−';
});
const label = computed(() => {
if (!state.value) return props.words?.initialLabel;
if (props.words)
return state.value.collapsed
? props.words.expandLabel
: props.words.collapseLabel;
const key = state.value.collapsed
? msg('Expand {name}')
: msg('Collapse {name}');
return t(key, { name: props.name });
});
const title = computed(() => {
if (!state.value) return props.initialTitle;
if (props.words)
return state.value.collapsed
? props.words.expandTitle
: props.words.collapseTitle;
return label.value;
});
const collapsedNow = computed(
() => panels.value[props.target]?.collapsed ?? props.startCollapsed,
);
</script>
<template>
<UiButton
variant="icon"
class="panel-collapse-btn"
:data-collapse-target="target"
:label="label"
:title="title"
:aria-expanded="state ? String(!state.collapsed) : undefined"
@click="chrome.act('toggle', target)"
>{{ glyph }}</UiButton
>
<UiPanelToggle
:target="target"
:name="name"
:sideways="sideways"
:collapsed="collapsedNow"
@update:collapsed="chrome.act('toggle', target)"
/>
</template>