mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Vue kit: the kit's classes wear Core's standard looks
UiButton gains styled variants beside the unstyled default ghost: action (the gev-action-button surface, tone="danger" and size="compact"), primary (that surface with the scene panel's main-action accent) and icon (the panel collapse toggle's square glyph button). A pressed styled button looks as a hovered one does. UiChip wears the read-only chip (now chip.css, shared with the news chips), UiEmpty the one-line empty state (now empty-state.css, shared with the news readout), and UiBadge and UiSegmented carry their skins through the kit's own classes too. Every kit selector shares one selector list with the Core skin it comes from, in skins loaded before the feature stylesheets, so no rule is copied and feature classes still win. The app renders as before: the voice card chip and the Recent Imagery and Authoring empty states keep their own type by inheriting it, and the dock pin buttons drop variant="icon", which they never wore. kitStyles.test.mjs pins the shared rules. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
ec1fc6bc09
commit
9f8a4cb39d
22 files changed
+363
-61
No files matched your search
@@ -1,8 +1,10 @@
|
||||
<script setup>
|
||||
// Core's read-only badge, with a `tone` and the kit's classes. It carries Core's `gev-status-badge` class, and
|
||||
// callers add its density variants (`gev-status-badge--box`, `--plain`) and
|
||||
// the feature classes that colour it; the kit classes carry no Core styles
|
||||
// yet. Not mirrored yet: pulse, busy, the tone glyphs and the clipped title.
|
||||
// Core's read-only badge, with a `tone` and the kit's classes. `ui-badge`
|
||||
// wears Core's badge (status-badge.css) beside Core's `gev-status-badge`
|
||||
// class; callers add its density variants (`gev-status-badge--box`,
|
||||
// `--plain`) and the feature classes that colour it. The tone classes carry
|
||||
// no style yet. Not mirrored yet: pulse, busy, the tone glyphs and the
|
||||
// clipped title.
|
||||
defineProps({
|
||||
tone: { type: String, default: 'neutral' },
|
||||
});
|
||||
|
||||
@@ -100,3 +100,50 @@ test('server-rendered markup carries the pressed classes', async () => {
|
||||
assert.match(html, /<button[^>]*class="[^"]*\bactive\b[^"]*"/);
|
||||
assert.match(html, /aria-pressed="true"/);
|
||||
});
|
||||
|
||||
const LOOKS = [
|
||||
'ui-button--action',
|
||||
'ui-button--primary',
|
||||
'ui-button--icon',
|
||||
'ui-button--compact',
|
||||
];
|
||||
|
||||
test('a ghost button, the default, carries no look of the kit’s', () => {
|
||||
const wrapper = mountButton({}, { class: 'pp-toggle-btn' });
|
||||
const classes = wrapper.get('button').classes();
|
||||
assert.ok(classes.includes('ui-button--ghost'));
|
||||
for (const look of LOOKS) assert.equal(classes.includes(look), false, look);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('the variant, tone and size render their kit classes', async () => {
|
||||
const wrapper = mountButton({ variant: 'action', tone: 'danger' });
|
||||
const button = wrapper.get('button');
|
||||
assert.ok(button.classes().includes('ui-button--action'));
|
||||
assert.ok(button.classes().includes('ui-button--danger'));
|
||||
assert.equal(button.classes().includes('ui-button--compact'), false);
|
||||
await wrapper.setProps({ size: 'compact' });
|
||||
assert.ok(button.classes().includes('ui-button--compact'));
|
||||
for (const variant of ['primary', 'icon']) {
|
||||
await wrapper.setProps({ variant });
|
||||
assert.ok(button.classes().includes(`ui-button--${variant}`));
|
||||
assert.equal(button.classes().includes('ui-button--action'), false);
|
||||
}
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('a styled variant still presses', async () => {
|
||||
const wrapper = mountButton({
|
||||
variant: 'action',
|
||||
pressed: false,
|
||||
pressedClass: 'active',
|
||||
});
|
||||
const button = wrapper.get('button');
|
||||
assert.equal(button.attributes('aria-pressed'), 'false');
|
||||
await wrapper.setProps({ pressed: true });
|
||||
assert.equal(button.attributes('aria-pressed'), 'true');
|
||||
assert.ok(button.classes().includes('ui-button--pressed'));
|
||||
assert.ok(button.classes().includes('ui-button--action'));
|
||||
assert.ok(button.classes().includes('active'));
|
||||
wrapper.unmount();
|
||||
});
|
||||
+31
-5
@@ -4,9 +4,19 @@ import { vClassToggle } from '../rail/classToggle.js';
|
||||
|
||||
// Core's button and its attribute contract: the button is always the root,
|
||||
// attributes passed in win over its own (a `title` replaces the label's), and
|
||||
// `pressed` renders aria-pressed only when it is passed. Core styles the
|
||||
// button through the classes its callers pass; the kit classes carry no Core
|
||||
// styles yet. Core adds `pressedClass`, its class on a pressed button (most
|
||||
// `pressed` renders aria-pressed only when it is passed. The variant picks
|
||||
// the look:
|
||||
// - `ghost` (the default) carries no style; the caller's classes style it.
|
||||
// - `action` wears Core's action surface (action-button.css), with
|
||||
// `tone="danger"` for a red hover and `size="compact"` for the smaller
|
||||
// shot-row footprint.
|
||||
// - `primary` is that surface with the accent emphasis of a group's one main
|
||||
// action (action-button.css).
|
||||
// - `icon` is the 22px square glyph button of a panel's collapse toggle
|
||||
// (controls.css).
|
||||
// A pressed action, primary or icon button looks as a hovered one does. Each
|
||||
// resting rule selects one kit class, so a feature class loaded later still
|
||||
// wins. Core adds `pressedClass`, its class on a pressed button (most
|
||||
// toggles use `active`). The pressed classes toggle through `classList`, so
|
||||
// classes other code adds to the button (a voice highlight) survive a press.
|
||||
// Not mirrored yet: icon, loading, disabledReason and the missing-label
|
||||
@@ -14,8 +24,20 @@ import { vClassToggle } from '../rail/classToggle.js';
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = defineProps({
|
||||
variant: { type: String, default: 'ghost' },
|
||||
variant: {
|
||||
type: String,
|
||||
default: 'ghost',
|
||||
validator: (value) =>
|
||||
['ghost', 'action', 'primary', 'icon'].includes(value),
|
||||
},
|
||||
/** `accent`, or `danger` for an action that destroys or stops. */
|
||||
tone: { type: String, default: 'accent' },
|
||||
/** `compact` for an action's smaller footprint. */
|
||||
size: {
|
||||
type: String,
|
||||
default: 'regular',
|
||||
validator: (value) => ['regular', 'compact'].includes(value),
|
||||
},
|
||||
/** The accessible name (aria-label) and, with nativeTitle, the tip. */
|
||||
label: { type: String, default: undefined },
|
||||
pressed: { type: Boolean, default: undefined },
|
||||
@@ -53,7 +75,11 @@ const vPressedClasses = {
|
||||
:type="props.type"
|
||||
:form="props.form"
|
||||
class="ui-button ui-focus"
|
||||
:class="[`ui-button--${props.variant}`, `ui-button--${props.tone}`]"
|
||||
:class="[
|
||||
`ui-button--${props.variant}`,
|
||||
`ui-button--${props.tone}`,
|
||||
{ 'ui-button--compact': props.size === 'compact' },
|
||||
]"
|
||||
:aria-label="props.label"
|
||||
:title="props.nativeTitle ? props.label : undefined"
|
||||
:aria-pressed="
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<script setup>
|
||||
// Core's chip: a label that says what something is, never a control.
|
||||
// Core styles it through the classes its callers pass; the kit classes carry
|
||||
// no Core styles yet. A chip that presses is a UiButton with pressedClass.
|
||||
// Core's chip: a label that says what something is, never a control. It
|
||||
// wears Core's read-only chip (chip.css: a pill of small uppercase mono
|
||||
// text), and `selected` its accent; feature classes the caller passes
|
||||
// restyle it. A chip that presses is a UiButton with pressedClass.
|
||||
defineProps({
|
||||
selected: { type: Boolean, default: false },
|
||||
mono: { type: Boolean, default: false },
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<script setup>
|
||||
// Core's empty state, with a `title` and `hint`. Core's empty states are one
|
||||
// line, so the title is the text itself rather than a bold heading; a hint
|
||||
// follows it. Core
|
||||
// styles it through the classes its callers pass. Not mirrored yet: icon.
|
||||
// follows it on a line of its own. It wears Core's empty line
|
||||
// (empty-state.css: dim 10px mono text); feature classes the caller passes
|
||||
// restyle it. Not mirrored yet: icon.
|
||||
defineProps({
|
||||
title: { type: String, required: true },
|
||||
hint: { type: String, default: undefined },
|
||||
|
||||
@@ -7,7 +7,9 @@ import { computed } from 'vue';
|
||||
// stop that arrows move) or `radio` (arrows plus Home and
|
||||
// End). Each option may carry `attrs` (an id, data attributes, a tip), and
|
||||
// Core's classes sit beside the kit's: `gev-segmented`, `gev-segment` and the
|
||||
// selected option's `activeClass`. An option with an `icon` shows the glyph,
|
||||
// selected option's `activeClass`. The kit's classes wear Core's segmented
|
||||
// skin (segmented-control.css) as Core's do; `stacked` carries no style yet.
|
||||
// An option with an `icon` shows the glyph,
|
||||
// and its label becomes the button's accessible name and tooltip, unless its
|
||||
// `attrs` carry a tip of their own.
|
||||
const props = defineProps({
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
// The kit's classes wear Core's standard looks: each shares one selector list
|
||||
// with the Core skin it comes from, so the rules are never copied, and the
|
||||
// default ghost button carries none.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readStylesheet } from '../../testSupport/readStylesheet.mjs';
|
||||
|
||||
const css = readStylesheet(new URL('../../../style.css', import.meta.url));
|
||||
|
||||
/** Each rule's selectors, outside @media and other at-rule preludes. */
|
||||
function rules(source) {
|
||||
const out = [];
|
||||
const re = /([^{}]+)\{([^{}]*)\}/g;
|
||||
const bare = source.replace(/\/\*[\s\S]*?\*\//g, '');
|
||||
let match;
|
||||
while ((match = re.exec(bare))) {
|
||||
const prelude = match[1].split('}').pop().trim();
|
||||
if (prelude.startsWith('@')) continue;
|
||||
out.push({
|
||||
selectors: prelude.split(',').map((s) => s.replace(/\s+/g, ' ').trim()),
|
||||
body: match[2],
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
const all = rules(css);
|
||||
|
||||
/** The rule that lists exactly `selector`, which must exist. */
|
||||
function ruleWith(selector) {
|
||||
const found = all.filter((rule) => rule.selectors.includes(selector));
|
||||
assert.equal(found.length, 1, `one rule lists ${selector}`);
|
||||
return found[0];
|
||||
}
|
||||
|
||||
/** `kit` and `core` share one rule, so the kit wears Core's skin unchanged. */
|
||||
function shares(kit, core) {
|
||||
const rule = ruleWith(kit);
|
||||
assert.ok(rule.selectors.includes(core), `${kit} shares ${core}'s rule`);
|
||||
return rule;
|
||||
}
|
||||
|
||||
test('UiButton variants wear Core’s action and icon skins', () => {
|
||||
shares('.ui-button--action', '.gev-action-button');
|
||||
shares('.ui-button--primary', '.gev-action-button');
|
||||
shares(
|
||||
'.ui-button--action:hover:not(:disabled)',
|
||||
'.gev-action-button:hover:not(:disabled)',
|
||||
);
|
||||
shares('.ui-button--action:disabled', '.gev-action-button:disabled');
|
||||
shares(
|
||||
'.ui-button--action.ui-button--danger:hover:not(:disabled)',
|
||||
'.gev-action-button--danger:hover:not(:disabled)',
|
||||
);
|
||||
shares(
|
||||
'.ui-button--primary:where(:not(:disabled))',
|
||||
'#scene-panel .scene-btn-primary:not(:disabled)',
|
||||
);
|
||||
shares('.ui-button--compact', '.gev-action-button--compact');
|
||||
shares(
|
||||
'.ui-button--compact.ui-button--danger:hover:not(:disabled)',
|
||||
'.gev-action-button--compact.gev-action-button--danger:hover:not(:disabled)',
|
||||
);
|
||||
shares('.ui-button--icon', '.panel-collapse-btn');
|
||||
shares('.ui-button--icon:hover', '.panel-collapse-btn:hover');
|
||||
});
|
||||
|
||||
test('a pressed styled button looks as a hovered one does', () => {
|
||||
shares(
|
||||
'.ui-button--action.ui-button--pressed:not(:disabled)',
|
||||
'.gev-action-button:hover:not(:disabled)',
|
||||
);
|
||||
shares(
|
||||
'.ui-button--primary.ui-button--pressed:not(:disabled)',
|
||||
'.gev-action-button:hover:not(:disabled)',
|
||||
);
|
||||
shares(
|
||||
'.ui-button--action.ui-button--danger.ui-button--pressed:not(:disabled)',
|
||||
'.gev-action-button--danger:hover:not(:disabled)',
|
||||
);
|
||||
shares('.ui-button--icon.ui-button--pressed', '.panel-collapse-btn:hover');
|
||||
});
|
||||
|
||||
test('a ghost button and the tones alone carry no style', () => {
|
||||
const kitButton =
|
||||
/\.ui-button(?:--(?:ghost|accent|danger|alert|pressed))?(?![\w-])/;
|
||||
const look = /\.ui-button--(?:action|primary|icon|compact)(?![\w-])/;
|
||||
for (const rule of all)
|
||||
for (const selector of rule.selectors)
|
||||
assert.ok(
|
||||
!kitButton.test(selector) || look.test(selector),
|
||||
`${selector} styles a kit button without a look`,
|
||||
);
|
||||
});
|
||||
|
||||
test('UiChip, UiEmpty, UiBadge and UiSegmented wear Core’s skins', () => {
|
||||
shares('.ui-chip', '.news-chip');
|
||||
shares('.ui-chip--selected', '.news-chip--official');
|
||||
shares('.ui-empty', '.news-readout__empty');
|
||||
assert.match(ruleWith('.ui-empty__hint').body, /display:\s*block/);
|
||||
shares('.ui-badge', '.gev-status-badge');
|
||||
shares('.ui-badge[hidden]', '.gev-status-badge[hidden]');
|
||||
shares('.ui-segmented', '.gev-segmented');
|
||||
shares('.ui-segmented[hidden]', '.gev-segmented[hidden]');
|
||||
shares('.ui-segmented__item', '.gev-segment');
|
||||
shares(
|
||||
'.ui-segmented__item + .ui-segmented__item',
|
||||
'.gev-segment + .gev-segment',
|
||||
);
|
||||
shares(
|
||||
".ui-segmented__item[aria-checked='true']",
|
||||
".gev-segment[aria-checked='true']",
|
||||
);
|
||||
shares(
|
||||
'.ui-segmented__item:hover:not(:disabled)',
|
||||
'.gev-segment:hover:not(:disabled)',
|
||||
);
|
||||
shares('.ui-segmented__item:focus-visible', '.gev-segment:focus-visible');
|
||||
shares('.ui-segmented__item:disabled', '.gev-segment:disabled');
|
||||
});
|
||||
|
||||
test('the kit’s skins load before the feature stylesheets that restyle them', () => {
|
||||
const at = (selector) => css.indexOf(selector);
|
||||
for (const [kit, feature] of [
|
||||
['.ui-chip,', '.gev-voice-card-chip {'],
|
||||
['.ui-empty,', '.scene-shot-empty {'],
|
||||
['.ui-empty,', '.recent-imagery-readout .ri-strip-empty {'],
|
||||
['.ui-empty,', '#space-mission-panel-host .space-mission-roster-empty {'],
|
||||
['.ui-button--icon,', '#command-dock .panel-collapse-btn'],
|
||||
]) {
|
||||
assert.ok(
|
||||
at(kit) >= 0 && at(feature) > at(kit),
|
||||
`${kit} loads before ${feature}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user