@jskit-ai/shell-web 0.2.52 → 0.2.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ <script setup>
2
+ // A button in each colour that has a container role and each variant, for its label's contrast at rest, hovered,
3
+ // focused and pressed: a state layer is drawn under the label, so it is part of what the label is read against.
4
+ const COLORS = Object.freeze(["primary", "secondary", "tertiary", "error", "success", "warning", "info"]);
5
+ const VARIANTS = Object.freeze(["flat", "elevated", "tonal", "outlined", "text"]);
6
+ </script>
7
+
8
+ <template>
9
+ <section class="d-flex flex-column ga-2 pa-4">
10
+ <div v-for="color in COLORS" :key="color" class="d-flex flex-wrap ga-2">
11
+ <v-btn
12
+ v-for="variant in VARIANTS"
13
+ :key="variant"
14
+ :color="color"
15
+ :variant="variant"
16
+ :data-testid="`contrast-${color}-${variant}`"
17
+ >
18
+ {{ variant }}
19
+ </v-btn>
20
+ </div>
21
+ </section>
22
+ </template>
@@ -11,6 +11,7 @@ import { shellScrollBehavior } from "@jskit-ai/kernel/client";
11
11
  import App from "./App.vue";
12
12
  import ActionsFormPage from "./ActionsFormPage.vue";
13
13
  import ActionsPage from "./ActionsPage.vue";
14
+ import ButtonContrastPage from "./ButtonContrastPage.vue";
14
15
  import ButtonStatesPage from "./ButtonStatesPage.vue";
15
16
  import ButtonsPage from "./ButtonsPage.vue";
16
17
  import ComponentsPage from "./ComponentsPage.vue";
@@ -350,6 +351,7 @@ const routes = [
350
351
  },
351
352
  { path: "/home/buttons", component: ButtonsPage, meta: { jskit: { title: "Buttons" } } },
352
353
  { path: "/home/button-states", component: ButtonStatesPage, meta: { jskit: { title: "Button states" } } },
354
+ { path: "/home/button-contrast", component: ButtonContrastPage, meta: { jskit: { title: "Button contrast" } } },
353
355
  { path: "/home/components", component: ComponentsPage, meta: { jskit: { title: "Components" } } },
354
356
  { path: "/home/actions", component: ActionsPage, meta: { jskit: { title: "Actions" } } },
355
357
  { path: "/home/actions/new", component: ActionsFormPage, meta: { jskit: { title: "New entry", parent: "/actions" } } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/shell-web",
3
- "version": "0.2.52",
3
+ "version": "0.2.53",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -51,7 +51,7 @@
51
51
  "@jskit-ai/architecture-inspector": "0.1.34"
52
52
  },
53
53
  "devDependencies": {
54
- "@jskit-ai/material-web": "0.1.11",
54
+ "@jskit-ai/material-web": "0.1.12",
55
55
  "@vue/compiler-sfc": "3.5.44"
56
56
  },
57
57
  "peerDependencies": {
@@ -146,3 +146,66 @@ test("a menu mounted while closed covers nothing, and still opens and closes wit
146
146
  assert.equal(seen.at(-1).overlay, "none", "once closed, the menu's overlay is gone again");
147
147
  await expect(items).toBeAttached();
148
148
  });
149
+
150
+ // A state layer lies under the label, so a hovered, focused or pressed button's label is read against its container
151
+ // with the layer over it. Material 3's layers (hover 8%, focus and pressed 10%) keep every label at 4.5:1: a filled
152
+ // button's on-colour over its colour, a tonal button's on-container colour over its tint.
153
+ test("every button's label keeps 4.5:1 at rest, hovered, focused and pressed, in each colour, variant and theme", {
154
+ skip: SKIP,
155
+ timeout: 180_000
156
+ }, async (t) => {
157
+ const { vite, browser } = await open(t);
158
+ const failures = [];
159
+ let judged = 0;
160
+ for (const theme of ["light", "dark"]) {
161
+ const page = await browser.newPage({
162
+ baseURL: vite.baseURL,
163
+ colorScheme: theme,
164
+ viewport: { width: 390, height: 844 },
165
+ reducedMotion: "reduce"
166
+ });
167
+ t.after(() => page.close());
168
+ await page.goto(`/home/button-contrast?theme=${theme}`);
169
+ await expect(page.getByTestId("jskit-shell-page-title")).toHaveText("Button contrast");
170
+ await page.addScriptTag({ path: AXE_PATH });
171
+ const buttons = await page.locator("[data-testid^=contrast-]").all();
172
+ assert.equal(buttons.length, 35, "seven colours in five variants");
173
+ for (const button of buttons) {
174
+ const name = await button.getAttribute("data-testid");
175
+ for (const state of ["rest", "hover", "focus", "pressed"]) {
176
+ if (state === "hover") {
177
+ await button.hover();
178
+ } else if (state === "focus") {
179
+ // A key press first, so the focus shows as keyboard focus.
180
+ await page.keyboard.press("Shift");
181
+ await button.focus();
182
+ } else if (state === "pressed") {
183
+ await button.hover();
184
+ await page.mouse.down();
185
+ }
186
+ const found = await button.evaluate(async (element) => {
187
+ const results = await globalThis.axe.run(element, { runOnly: { type: "rule", values: ["color-contrast"] } });
188
+ const nodes = (outcome) => outcome.flatMap((rule) => rule.nodes);
189
+ return [
190
+ ...nodes(results.violations).map((node) => `${node.any.map((check) => check.data?.contrastRatio).join("|")}:1 ` +
191
+ `(${node.any.map((check) => `${check.data?.fgColor} on ${check.data?.bgColor}`).join("|")})`),
192
+ ...nodes(results.incomplete).map((node) => `unjudged: ${node.any.map((check) => check.data?.messageKey).join("|")}`)
193
+ ];
194
+ });
195
+ judged += 1;
196
+ for (const finding of found) {
197
+ failures.push(`${theme} ${name} ${state}: ${finding}`);
198
+ }
199
+ if (state === "pressed") {
200
+ await page.mouse.up();
201
+ }
202
+ await button.blur();
203
+ await page.mouse.move(1, 300);
204
+ // A released press leaves its ripple fading out for a moment; the next state starts once it has gone.
205
+ await expect(page.locator(".v-ripple__container")).toHaveCount(0);
206
+ }
207
+ }
208
+ }
209
+ assert.equal(judged, 280, "every button judged in four states and two themes");
210
+ assert.deepEqual(failures, [], "every label at 4.5:1 or more in every state");
211
+ });