mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
mountCreditsView() keeps its signature and stays the owner: it computes the credits shown once each, keeps the list's open state and its focus, takes the expand and close clicks and Escape, and renders CreditsView synchronously (as the weather readout is rendered), so focus moves as soon as a change returns. The view teleports the line and the list to the end of the body, as the script appended them, so the page's rules that select them as children of the body still apply; CreditItem draws one credit (its logo or its text, only its linked words linked, links and logos kept only for a safe scheme). The ids, classes, roles, aria attributes and text are unchanged. The list's close button is a UiCloseButton with bare, keeping the browser's padding, so it only gains the kit's classes, which carry no rules. The expand button stays a plain button: its words are its content, which a UiButton slot would not word again when the owner renders a new locale. The list's items are keyed by credit, so a link that keeps its place keeps focus through a redraw; one that goes still hands focus to the close button. New tests: the line and list follow the locale, and they are the last of the body with the kit's close button. Co-authored-by: Manjunath Paparaju <[email protected]>
83 lines
3.2 KiB
Vue
83 lines
3.2 KiB
Vue
<script setup>
|
|
import { t } from '../../i18n/index.js';
|
|
import UiCloseButton from '../kit/UiCloseButton.vue';
|
|
import CreditItem from './CreditItem.vue';
|
|
|
|
// The attribution line at the bottom left and the "Data attribution" list it
|
|
// opens, both at the end of `to` (the page's body), where the page's rules
|
|
// place them. The owner (src/ui/creditsView.js) computes the credits shown,
|
|
// keeps the list's open state and its focus, and takes the clicks and keys;
|
|
// `elements` receives the line's, the button's and the list's elements for
|
|
// it.
|
|
const props = defineProps({
|
|
to: { type: Object, required: true },
|
|
panelId: { type: String, required: true },
|
|
/** The credits on the line, once each. */
|
|
inline: { type: Array, required: true },
|
|
/** The credits in the list, once each. */
|
|
listed: { type: Array, required: true },
|
|
open: { type: Boolean, default: false },
|
|
/**
|
|
* The locale its words are in: a change words them again. The template
|
|
* never reads it; `t()` is not reactive, so a new value is what makes the
|
|
* view render again in the new language.
|
|
*/
|
|
locale: { type: String, default: '' },
|
|
elements: { type: Object, required: true },
|
|
onExpand: { type: Function, default: () => {} },
|
|
onClose: { type: Function, default: () => {} },
|
|
onKeydown: { type: Function, default: () => {} },
|
|
});
|
|
|
|
/** Between the line's credits, and before the list's button. */
|
|
const SEPARATOR = ' · ';
|
|
/** A credit's key: the same text and link are one credit. */
|
|
const key = (credit) => `${credit.text}\u0000${credit.href ?? ''}`;
|
|
/** Keep `name`'s element for the owner. */
|
|
const keep = (name) => (element) => {
|
|
props.elements[name] = element?.$el ?? element;
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<Teleport :to="props.to"
|
|
><div id="gev-credits" :ref="keep('bar')" class="gev-credits" tabindex="-1"
|
|
><span :ref="keep('line')" class="gev-credits-line"
|
|
><template v-for="(credit, i) in props.inline" :key="key(credit)"
|
|
>{{ i ? SEPARATOR : '' }}<CreditItem :credit="credit" /></template
|
|
>{{ props.inline.length && props.listed.length ? SEPARATOR : '' }}</span
|
|
><button
|
|
:ref="keep('expand')"
|
|
type="button"
|
|
class="gev-credits-expand"
|
|
aria-haspopup="dialog"
|
|
:aria-controls="props.panelId"
|
|
:aria-expanded="String(props.open)"
|
|
:hidden="props.listed.length === 0"
|
|
@click="props.onExpand()"
|
|
>{{ t('Data attribution') }}</button
|
|
></div
|
|
><div
|
|
:id="props.panelId"
|
|
:ref="keep('panel')"
|
|
class="gev-credits-panel"
|
|
role="dialog"
|
|
:aria-labelledby="`${props.panelId}-title`"
|
|
:hidden="!props.open"
|
|
@keydown="props.onKeydown($event)"
|
|
><div class="gev-credits-header"
|
|
><span class="gev-credits-title" :id="`${props.panelId}-title`">{{
|
|
t('Data provided by:')
|
|
}}</span
|
|
><UiCloseButton
|
|
:ref="keep('close')"
|
|
class="gev-credits-close"
|
|
bare
|
|
:label="t('Close data attribution')"
|
|
@click="props.onClose()" /></div
|
|
><ul class="gev-credits-list"
|
|
><li v-for="credit in props.listed" :key="key(credit)"
|
|
><CreditItem :credit="credit" /></li></ul></div
|
|
></Teleport>
|
|
</template>
|