diff --git a/changelog.d/1840-kit-close-button.md b/changelog.d/1840-kit-close-button.md new file mode 100644 index 0000000000..0376fb405c --- /dev/null +++ b/changelog.d/1840-kit-close-button.md @@ -0,0 +1,3 @@ +- Every close, dismiss and clear button in the views is now one kit + component, `UiCloseButton`, with the same look and behaviour as before + (manjunath22466, samehkhamis, #1840). diff --git a/docs/VUE-MIGRATION.md b/docs/VUE-MIGRATION.md index 3a8be5b0cb..24b2e2c63a 100644 --- a/docs/VUE-MIGRATION.md +++ b/docs/VUE-MIGRATION.md @@ -53,6 +53,7 @@ never copied: | `UiButton` `variant="action"` | the action surface (`gev-action-button`); `tone="danger"` hovers red, `size="compact"` is the shot-row footprint (on this variant only) | `src/ui/styles/action-button.css` | | `UiButton` `variant="primary"` | the action surface with a group's main-action accent | `src/ui/styles/action-button.css` | | `UiButton` `variant="icon"` | the 22px square glyph button of a panel's collapse toggle | `src/ui/styles/controls.css` | +| `UiCloseButton` | a close, dismiss or clear button: a bare glyph (× with `glyph="times"`, the Material `close` symbol with `glyph="icon"`) with no padding, border or background of its own and a pointer; the site's feature class sets size, colour, hover and any surface, and `bare` leaves the look off for a skin that sets its own padding and border | `src/ui/styles/close-button.css` | | `UiChip` | the read-only chip (a pill of uppercase mono text); `selected` takes the accent | `src/ui/styles/chip.css` | | `UiEmpty` | the one-line empty state (dim mono text), its hint on a line below | `src/ui/styles/empty-state.css` | | `UiBadge` | the read-only badge (`gev-status-badge`) | `src/ui/styles/status-badge.css` | @@ -99,6 +100,13 @@ a `title` and `hint`, but Core's empty states are one line, so the title is the text itself rather than a bold heading; the News feed, Scene shot list, mission roster and imagery strip use it. The locale picker's and the mission tables' empty rows stay a paragraph and table cells. +`UiCloseButton` is a `UiButton` with a fixed glyph, a required `label` and +no tip unless the site passes a `title`; attributes and classes pass through, +so each site keeps its id, feature class and look. Every close, dismiss and +clear button in the views is one (`src/ui/kit/closeButtons.test.mjs` pins +it); Street Level's and the space mission's keep `bare`, since their skins +set their own padding and border. The close buttons built in script (credits, the +Quebec CCTV overlay, the guide) are not converted yet. `UiSlider` keeps the native range input rather than drawing a `role="slider"` track, so Core's keyboard, form behaviour and styling stay; it takes `v-model`, `min`, `max`, `step` and `disabled`, emits a diff --git a/scripts/format-scope.json b/scripts/format-scope.json index 1c5a01c0cc..89cb505b82 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -1329,6 +1329,10 @@ "src/ui/kit/UiBadge.test.mjs", "src/ui/kit/UiEmpty.vue", "src/ui/kit/kitStyles.test.mjs", + "src/ui/kit/UiCloseButton.vue", + "src/ui/kit/UiCloseButton.test.mjs", + "src/ui/kit/closeButtons.test.mjs", + "src/ui/styles/close-button.css", "src/ui/styles/chip.css", "src/ui/styles/empty-state.css", "src/ui/rail/RailChips.vue", diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index dbbfdf35bd..be5b54b3d9 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -241,6 +241,7 @@ "src/ui/kit/UiSelect.js", "src/ui/kit/UiEmpty.vue", "src/ui/kit/UiBadge.vue", + "src/ui/kit/UiCloseButton.vue", "src/ui/stores/globeActions.js", "src/ui/views/panels/GlobeActions.vue", "src/ui/views/panels/RenderFailure.vue", @@ -1014,6 +1015,8 @@ "src/ui/kit/UiSelect.js", "src/ui/kit/UiButton.vue", "src/ui/kit/UiBadge.vue", + "src/ui/kit/UiCloseButton.vue", + "src/ui/kit/UiIcon.vue", "src/ui/rail/fieldValue.js", "src/ui/kit/UiSlider.js", "src/ui/kit/UiSegmented.vue" @@ -1602,6 +1605,7 @@ "src/ui/kit/UiSlider.js", "src/ui/kit/UiButton.vue", "src/ui/kit/UiBadge.vue", + "src/ui/kit/UiCloseButton.vue", "src/ui/stores/globeActions.js", "src/ui/stores/recording.js", "src/ui/i18n.js", @@ -5370,6 +5374,7 @@ "src/ui/kit/UiButton.vue", "src/ui/kit/UiEmpty.vue", "src/ui/kit/UiBadge.vue", + "src/ui/kit/UiCloseButton.vue", "src/ui/stores/globeActions.js", "src/ui/stores/recording.js", "src/ui/i18n.js", diff --git a/src/ui/kit/UiCloseButton.test.mjs b/src/ui/kit/UiCloseButton.test.mjs new file mode 100644 index 0000000000..d2e11796e0 --- /dev/null +++ b/src/ui/kit/UiCloseButton.test.mjs @@ -0,0 +1,98 @@ +import { after, before, test } from 'node:test'; +import assert from 'node:assert/strict'; +import { installVueDom } from '../../testSupport/vueDom.mjs'; + +let mount; +let UiCloseButton; +let uninstall; +before(async () => { + uninstall = installVueDom(); + ({ mount } = await import('@vue/test-utils')); + UiCloseButton = (await import('./UiCloseButton.vue')).default; +}); +after(() => uninstall()); + +function mountClose(props = {}, attrs = {}) { + return mount(UiCloseButton, { + attachTo: document.body, + props: { label: 'Close card', ...props }, + attrs, + }); +} + +test('a close button is a button named by its label, with no tip of its own', () => { + const wrapper = mountClose(); + const button = wrapper.get('button'); + assert.equal(button.attributes('type'), 'button'); + assert.equal(button.attributes('aria-label'), 'Close card'); + assert.equal(button.attributes('title'), undefined); + assert.ok(button.classes().includes('ui-close-button')); + wrapper.unmount(); +}); + +test('glyph="times" draws the × character', () => { + const wrapper = mountClose(); + const button = wrapper.get('button'); + assert.equal(button.element.innerHTML, '×'); + wrapper.unmount(); +}); + +test('glyph="icon" draws the Material close symbol, sized by the stylesheet', () => { + const wrapper = mountClose({ glyph: 'icon' }); + const icon = wrapper.get('button > span'); + assert.equal(wrapper.get('button').element.children.length, 1); + assert.equal(icon.text(), 'close'); + assert.ok(icon.classes().includes('material-symbols-outlined')); + assert.equal(icon.attributes('aria-hidden'), 'true'); + assert.equal(icon.attributes('style'), undefined); + wrapper.unmount(); +}); + +test('attributes and classes pass through to the button', () => { + const wrapper = mountClose( + {}, + { + id: 'gev-chat-close', + class: 'data-toggle-chip', + title: 'Clear reading', + 'data-action-id': 'clear', + 'aria-hidden': 'true', + disabled: true, + hidden: true, + }, + ); + const button = wrapper.get('button'); + assert.equal(button.attributes('id'), 'gev-chat-close'); + assert.ok(button.classes().includes('data-toggle-chip')); + assert.ok(button.classes().includes('ui-close-button')); + assert.equal(button.attributes('title'), 'Clear reading'); + assert.equal(button.attributes('data-action-id'), 'clear'); + assert.equal(button.attributes('aria-hidden'), 'true'); + assert.equal(button.element.disabled, true); + assert.equal(button.element.hidden, true); + wrapper.unmount(); +}); + +test('bare leaves the kit look off', () => { + const wrapper = mountClose({ bare: true }, { class: 'sl-viewer-x' }); + const classes = wrapper.get('button').classes(); + assert.ok(classes.includes('sl-viewer-x')); + assert.equal(classes.includes('ui-close-button'), false); + wrapper.unmount(); +}); + +test('a click is emitted with its event', async () => { + const wrapper = mountClose(); + await wrapper.get('button').trigger('click'); + const clicks = wrapper.emitted('click'); + assert.equal(clicks.length, 1); + assert.ok(clicks[0][0] instanceof Event); + wrapper.unmount(); +}); + +test('a disabled close button emits no click', async () => { + const wrapper = mountClose({}, { disabled: true }); + await wrapper.get('button').trigger('click'); + assert.equal(wrapper.emitted('click'), undefined); + wrapper.unmount(); +}); diff --git a/src/ui/kit/UiCloseButton.vue b/src/ui/kit/UiCloseButton.vue new file mode 100644 index 0000000000..febe762d68 --- /dev/null +++ b/src/ui/kit/UiCloseButton.vue @@ -0,0 +1,40 @@ + + + diff --git a/src/ui/kit/UiIcon.vue b/src/ui/kit/UiIcon.vue index 4f34f29e4b..01bfedd230 100644 --- a/src/ui/kit/UiIcon.vue +++ b/src/ui/kit/UiIcon.vue @@ -1,5 +1,8 @@ diff --git a/src/ui/views/panels/EntityCard.vue b/src/ui/views/panels/EntityCard.vue index 3ca7087c2f..77ae67c486 100644 --- a/src/ui/views/panels/EntityCard.vue +++ b/src/ui/views/panels/EntityCard.vue @@ -10,6 +10,7 @@ import AltitudeGraph from './AltitudeGraph.vue'; import { contextNeedle, contextSearchText, matchesContextSearch } from '../../contextSearch.js'; import RouteGlobe from './RouteGlobe.vue'; import CctvPreview from './CctvPreview.vue'; +import UiCloseButton from '../../kit/UiCloseButton.vue'; import { useCctvStore } from '../../stores/cctv.js'; import SpotConditions from './SpotConditions.vue'; import { shownLayerName } from '../../layerNames.js'; @@ -396,9 +397,7 @@ watch(

{{ shownTitle }}

{{ subtitle }} - +
diff --git a/src/ui/views/panels/MissionDetail.vue b/src/ui/views/panels/MissionDetail.vue index d88bc2e5ae..cd310841ce 100644 --- a/src/ui/views/panels/MissionDetail.vue +++ b/src/ui/views/panels/MissionDetail.vue @@ -5,6 +5,7 @@ import { t } from '../../../i18n/index.js'; import UiSlider from '../../kit/UiSlider.js'; import { useSpaceMissionsStore } from '../../stores/spaceMissions.js'; import UiButton from '../../kit/UiButton.vue'; +import UiCloseButton from '../../kit/UiCloseButton.vue'; // The selected space mission. The launches layer presents it // and hides the panel while none is selected; the roster beside it hides @@ -27,7 +28,7 @@ watch(