Files
gods-eye-view/src/ui/views/panels/DrawSwatches.vue
T
Sameh KhamisandManjunath Paparaju 35fb3684ba Vue kit: Draw's and Import's buttons and glyphs are kit controls
UTILITIES ▸ Draw and Import no longer hand-write a button or a Material
Symbols span. Clear and Import are ghost UiButtons (Draw already was), and
the Draw and Import glyphs are UiIcons that keep pp-icon, with
:size="null" so controls.css still sizes them. Draw's five colour swatches
(in the toolbar and in a drawn shape's row) are ghost UiButtons that keep
role="radio", aria-checked and their own active class; they are not
pressed toggles. A drawn shape's row (its swatch, show/hide, the
application's row actions and fly to) is on the kit too, beside the remove
UiCloseButton it already had; its glyphs are UiIcons with :size="null".
Show/hide keeps naming itself Show … / Hide … rather than becoming a
pressed toggle.

Template refs that now hold a component reach the button through $el:
the swatches' arrow-key focus and Import's focus fallback when the last
imported file goes.

The Street Level panel's controls were already kit controls (its ⤢ ⤡ and
⚠ are text characters), so its template is unchanged; the new guard test
pins it with Draw and Import.

src/ui/kit/drawControls.test.mjs pins it: no hand-written button, select,
checkbox, range or Material span in DrawControls, DrawSwatches,
DrawMarkList, GeoImport or StreetLevelPanel; the kit counts per file;
Draw a pressed toggle with active; the swatches radios rather than
pressed; :size="null" on every glyph; and the $el refs.
docs/VUE-MIGRATION.md describes the surface.

Co-authored-by: Manjunath Paparaju <[email protected]>
2026-11-19 12:24:55 -08:00

53 lines
2.5 KiB
Vue

<script setup>
import { onMounted } from 'vue';
import { t } from '../../../i18n/index.js';
import {
DRAW_COLORS,
DRAW_COLOR_CSS,
DRAW_COLOR_NAMES,
} from '../../../annotations/drawMarks.js';
import UiButton from '../../kit/UiButton.vue';
// Draw's five colours as one radio group: the next shape's colour and a
// drawn shape's picker. Only the checked colour is a tab stop; the arrows,
// Home and End move to and choose another, as a radio group's do. Each swatch
// shows its colour from DRAW_COLOR_CSS, the same value the shape is drawn in.
// The swatches are ghost UiButtons with role="radio": they say they are
// chosen with aria-checked and their own `active` class, never aria-pressed,
// and `buttons` keeps their elements for the arrows.
// The template is one line: templates keep whitespace.
const props = defineProps({
modelValue: { type: String, default: 'primary' },
/** The group's accessible name, already translated. */
label: { type: String, required: true },
/** Focus the checked colour once shown (a picker that just opened). */
autofocus: { type: Boolean, default: false },
});
// `choose` is a click: a picker closes on it, and stays open for the arrows.
const emit = defineEmits(['update:modelValue', 'choose']);
const buttons = [];
const STEPS = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 };
function onKey(event) {
const from = Math.max(0, DRAW_COLORS.indexOf(props.modelValue));
let to;
if (STEPS[event.key])
to = (from + STEPS[event.key] + DRAW_COLORS.length) % DRAW_COLORS.length;
else if (event.key === 'Home') to = 0;
else if (event.key === 'End') to = DRAW_COLORS.length - 1;
else return;
event.preventDefault();
buttons[to]?.focus();
if (to !== from) emit('update:modelValue', DRAW_COLORS[to]);
}
onMounted(() => {
if (props.autofocus)
buttons[Math.max(0, DRAW_COLORS.indexOf(props.modelValue))]?.focus();
});
</script>
<template>
<div class="draw-colors" role="radiogroup" :aria-label="props.label" @keydown="onKey"><UiButton v-for="(color, index) in DRAW_COLORS" :key="color" :ref="(swatch) => (buttons[index] = swatch?.$el)" class="draw-color" :class="{ active: color === props.modelValue }" role="radio" :data-color="color" :data-control="`color-${color}`" :aria-checked="String(color === props.modelValue)" :tabindex="color === props.modelValue ? 0 : -1" :style="{ background: DRAW_COLOR_CSS[color] }" :label="t(DRAW_COLOR_NAMES[color])" @click="emit('update:modelValue', color), emit('choose', color)" /></div>
</template>