@techsio/storybook-better-a11y 0.0.4 → 0.0.6

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.
Files changed (38) hide show
  1. package/dist/AccessibilityRuleMaps.js +532 -0
  2. package/dist/a11yRunner.js +105 -0
  3. package/dist/a11yRunner.test.js +21 -0
  4. package/dist/a11yRunnerUtils.js +30 -0
  5. package/dist/a11yRunnerUtils.test.js +61 -0
  6. package/dist/{699.js → apcaChecker.js} +1 -255
  7. package/dist/apcaChecker.test.js +124 -0
  8. package/dist/axeRuleMappingHelper.js +4 -0
  9. package/dist/components/A11YPanel.js +140 -0
  10. package/dist/components/A11YPanel.stories.js +198 -0
  11. package/dist/components/A11YPanel.test.js +110 -0
  12. package/dist/components/A11yContext.js +438 -0
  13. package/dist/components/A11yContext.test.js +277 -0
  14. package/dist/components/Report/Details.js +169 -0
  15. package/dist/components/Report/Report.js +106 -0
  16. package/dist/components/Report/Report.stories.js +86 -0
  17. package/dist/components/Tabs.js +54 -0
  18. package/dist/components/TestDiscrepancyMessage.js +55 -0
  19. package/dist/components/TestDiscrepancyMessage.stories.js +40 -0
  20. package/dist/components/VisionSimulator.js +83 -0
  21. package/dist/components/VisionSimulator.stories.js +56 -0
  22. package/dist/constants.js +25 -0
  23. package/dist/index.js +5 -6
  24. package/dist/manager.js +11 -1540
  25. package/dist/manager.test.js +86 -0
  26. package/dist/params.js +0 -0
  27. package/dist/postinstall.js +1 -1
  28. package/dist/preview.js +68 -1
  29. package/dist/preview.test.js +215 -0
  30. package/dist/results.mock.js +874 -0
  31. package/dist/types.js +6 -0
  32. package/dist/utils.js +21 -0
  33. package/dist/{100.js → visionSimulatorFilters.js} +1 -23
  34. package/dist/withVisionSimulator.js +41 -0
  35. package/package.json +1 -1
  36. package/dist/212.js +0 -1965
  37. package/dist/212.js.LICENSE.txt +0 -19
  38. package/dist/rslib-runtime.js +0 -37
@@ -0,0 +1,30 @@
1
+ import { global } from "@storybook/global";
2
+ import { PANEL_ID } from "./constants.js";
3
+ const { document: a11yRunnerUtils_document } = global;
4
+ const withLinkPaths = (results, storyId)=>{
5
+ const pathname = a11yRunnerUtils_document.location.pathname.replace(/iframe\.html$/, '');
6
+ const enhancedResults = {
7
+ ...results
8
+ };
9
+ const propertiesToAugment = [
10
+ 'incomplete',
11
+ 'passes',
12
+ 'violations'
13
+ ];
14
+ propertiesToAugment.forEach((key)=>{
15
+ if (Array.isArray(results[key])) enhancedResults[key] = results[key].map((result)=>({
16
+ ...result,
17
+ nodes: result.nodes.map((node, index)=>{
18
+ const id = `${key}.${result.id}.${index + 1}`;
19
+ const linkPath = `${pathname}?path=/story/${storyId}&addonPanel=${PANEL_ID}&a11ySelection=${id}`;
20
+ return {
21
+ id,
22
+ ...node,
23
+ linkPath
24
+ };
25
+ })
26
+ }));
27
+ });
28
+ return enhancedResults;
29
+ };
30
+ export { withLinkPaths };
@@ -0,0 +1,61 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { withLinkPaths } from "./a11yRunnerUtils.js";
3
+ describe('a11yRunnerUtils', ()=>{
4
+ describe('withLinkPaths', ()=>{
5
+ it('should add link paths to the axe results', ()=>{
6
+ const axeResults = {
7
+ violations: [
8
+ {
9
+ id: 'color-contrast',
10
+ nodes: [
11
+ {
12
+ html: '<button>Click me</button>',
13
+ target: [
14
+ '.button'
15
+ ]
16
+ },
17
+ {
18
+ html: '<a href="#">Link</a>',
19
+ target: [
20
+ '.link'
21
+ ]
22
+ }
23
+ ]
24
+ }
25
+ ],
26
+ passes: [
27
+ {
28
+ id: 'button-name',
29
+ nodes: [
30
+ {
31
+ html: '<button>Valid Button</button>',
32
+ target: [
33
+ '.valid-button'
34
+ ]
35
+ }
36
+ ]
37
+ }
38
+ ],
39
+ incomplete: [
40
+ {
41
+ id: 'aria-valid',
42
+ nodes: [
43
+ {
44
+ html: '<div aria-label="test">Test</div>',
45
+ target: [
46
+ '.aria-test'
47
+ ]
48
+ }
49
+ ]
50
+ }
51
+ ],
52
+ inapplicable: []
53
+ };
54
+ const result = withLinkPaths(axeResults, 'test-story-id');
55
+ expect(result.violations[0].nodes[0].linkPath).toBe('/?path=/story/test-story-id&addonPanel=storybook/a11y/panel&a11ySelection=violations.color-contrast.1');
56
+ expect(result.violations[0].nodes[1].linkPath).toBe('/?path=/story/test-story-id&addonPanel=storybook/a11y/panel&a11ySelection=violations.color-contrast.2');
57
+ expect(result.passes[0].nodes[0].linkPath).toBe('/?path=/story/test-story-id&addonPanel=storybook/a11y/panel&a11ySelection=passes.button-name.1');
58
+ expect(result.incomplete[0].nodes[0].linkPath).toBe('/?path=/story/test-story-id&addonPanel=storybook/a11y/panel&a11ySelection=incomplete.aria-valid.1');
59
+ });
60
+ });
61
+ });
@@ -1,44 +1,4 @@
1
- import { __webpack_require__ } from "./rslib-runtime.js";
2
- import { expect } from "storybook/test";
3
- import { ElementA11yParameterError } from "storybook/internal/preview-errors";
4
1
  import { global } from "@storybook/global";
5
- import { addons, useCallback, useEffect, waitForAnimations } from "storybook/preview-api";
6
- import { EVENTS, filters, filterDefs, PANEL_ID } from "./100.js";
7
- var preview_namespaceObject = {};
8
- __webpack_require__.r(preview_namespaceObject);
9
- __webpack_require__.d(preview_namespaceObject, {
10
- afterEach: ()=>afterEach,
11
- decorators: ()=>decorators,
12
- initialGlobals: ()=>initialGlobals,
13
- parameters: ()=>preview_parameters
14
- });
15
- const { document: a11yRunnerUtils_document } = global;
16
- const withLinkPaths = (results, storyId)=>{
17
- const pathname = a11yRunnerUtils_document.location.pathname.replace(/iframe\.html$/, '');
18
- const enhancedResults = {
19
- ...results
20
- };
21
- const propertiesToAugment = [
22
- 'incomplete',
23
- 'passes',
24
- 'violations'
25
- ];
26
- propertiesToAugment.forEach((key)=>{
27
- if (Array.isArray(results[key])) enhancedResults[key] = results[key].map((result)=>({
28
- ...result,
29
- nodes: result.nodes.map((node, index)=>{
30
- const id = `${key}.${result.id}.${index + 1}`;
31
- const linkPath = `${pathname}?path=/story/${storyId}&addonPanel=${PANEL_ID}&a11ySelection=${id}`;
32
- return {
33
- id,
34
- ...node,
35
- linkPath
36
- };
37
- })
38
- }));
39
- });
40
- return enhancedResults;
41
- };
42
2
  const { document: apcaChecker_document } = global;
43
3
  const DEFAULT_APCA_OPTIONS = {
44
4
  level: 'bronze',
@@ -325,218 +285,4 @@ function getImpact(contrastValue, threshold, maxContrast) {
325
285
  if (difference > 10) return 'moderate';
326
286
  return 'minor';
327
287
  }
328
- const { document: a11yRunner_document } = global;
329
- const channel = addons.getChannel();
330
- const DEFAULT_PARAMETERS = {
331
- config: {},
332
- options: {}
333
- };
334
- const DISABLED_RULES = [
335
- 'region'
336
- ];
337
- const queue = [];
338
- let isRunning = false;
339
- const runNext = async ()=>{
340
- if (0 === queue.length) {
341
- isRunning = false;
342
- return;
343
- }
344
- isRunning = true;
345
- const next = queue.shift();
346
- if (next) await next();
347
- runNext();
348
- };
349
- const run = async (input = DEFAULT_PARAMETERS, storyId)=>{
350
- const axeCore = await import("axe-core");
351
- const axe = axeCore?.default || globalThis.axe;
352
- const { config = {}, options = {} } = input;
353
- if (input.element) throw new ElementA11yParameterError();
354
- const context = {
355
- include: a11yRunner_document?.body,
356
- exclude: [
357
- '.sb-wrapper',
358
- '#storybook-docs',
359
- '#storybook-highlights-root'
360
- ]
361
- };
362
- if (input.context) {
363
- const hasInclude = 'object' == typeof input.context && 'include' in input.context && void 0 !== input.context.include;
364
- const hasExclude = 'object' == typeof input.context && 'exclude' in input.context && void 0 !== input.context.exclude;
365
- if (hasInclude) context.include = input.context.include;
366
- else if (!hasInclude && !hasExclude) context.include = input.context;
367
- if (hasExclude) context.exclude = context.exclude.concat(input.context.exclude);
368
- }
369
- axe.reset();
370
- const configWithDefault = {
371
- ...config,
372
- rules: [
373
- ...DISABLED_RULES.map((id)=>({
374
- id,
375
- enabled: false
376
- })),
377
- ...config?.rules ?? []
378
- ]
379
- };
380
- axe.configure(configWithDefault);
381
- return new Promise((resolve, reject)=>{
382
- const highlightsRoot = a11yRunner_document?.getElementById('storybook-highlights-root');
383
- if (highlightsRoot) highlightsRoot.style.display = 'none';
384
- const task = async ()=>{
385
- try {
386
- const result = await axe.run(context, options);
387
- let contextElement = a11yRunner_document;
388
- if (context.include instanceof Element) contextElement = context.include;
389
- else if (Array.isArray(context.include)) {
390
- const first = context.include[0];
391
- if (first instanceof Element) contextElement = first;
392
- else if ('string' == typeof first) contextElement = a11yRunner_document.querySelector(first) || a11yRunner_document;
393
- } else if ('string' == typeof context.include) contextElement = a11yRunner_document.querySelector(context.include) || a11yRunner_document;
394
- const excludeSelectors = Array.isArray(context.exclude) ? context.exclude.filter((value)=>'string' == typeof value) : 'string' == typeof context.exclude ? [
395
- context.exclude
396
- ] : [];
397
- const apcaResult = await runAPCACheck(contextElement, input.apca, excludeSelectors);
398
- if (apcaResult.nodes.length > 0) result.violations.push(apcaResult);
399
- else result.passes.push(apcaResult);
400
- const resultWithLinks = withLinkPaths(result, storyId);
401
- globalThis.__TECHSIO_A11Y_RESULTS__ = {
402
- storyId,
403
- results: resultWithLinks,
404
- timestamp: Date.now()
405
- };
406
- resolve(resultWithLinks);
407
- } catch (error) {
408
- reject(error);
409
- }
410
- };
411
- queue.push(task);
412
- if (!isRunning) runNext();
413
- if (highlightsRoot) highlightsRoot.style.display = '';
414
- });
415
- };
416
- channel.on(EVENTS.MANUAL, async (storyId, input = DEFAULT_PARAMETERS)=>{
417
- try {
418
- await waitForAnimations();
419
- const result = await run(input, storyId);
420
- const resultJson = JSON.parse(JSON.stringify(result));
421
- channel.emit(EVENTS.RESULT, resultJson, storyId);
422
- } catch (error) {
423
- channel.emit(EVENTS.ERROR, error);
424
- }
425
- });
426
- function getIsVitestStandaloneRun() {
427
- try {
428
- return 'false' === ({
429
- MODE: "production",
430
- DEV: false,
431
- PROD: true,
432
- BASE_URL: "/",
433
- ASSET_PREFIX: "auto"
434
- }).VITEST_STORYBOOK;
435
- } catch (e) {
436
- return false;
437
- }
438
- }
439
- const knownFilters = Object.values(filters).map((f)=>f.filter);
440
- const knownFiltersRegExp = new RegExp(`\\b(${knownFilters.join('|')})\\b`, 'g');
441
- const withVisionSimulator = (StoryFn, { globals })=>{
442
- const { vision } = globals;
443
- const applyVisionFilter = useCallback(()=>{
444
- const existingFilters = document.body.style.filter.replaceAll(knownFiltersRegExp, '').trim();
445
- const visionFilter = filters[vision]?.filter;
446
- if (visionFilter && document.body.classList.contains('sb-show-main')) if (existingFilters && 'none' !== existingFilters) document.body.style.filter = `${existingFilters} ${visionFilter}`;
447
- else document.body.style.filter = visionFilter;
448
- else document.body.style.filter = existingFilters || 'none';
449
- return ()=>document.body.style.filter = existingFilters || 'none';
450
- }, [
451
- vision
452
- ]);
453
- useEffect(()=>{
454
- const cleanup = applyVisionFilter();
455
- const observer = new MutationObserver(()=>applyVisionFilter());
456
- observer.observe(document.body, {
457
- attributeFilter: [
458
- 'class'
459
- ]
460
- });
461
- return ()=>{
462
- cleanup();
463
- observer.disconnect();
464
- };
465
- }, [
466
- applyVisionFilter
467
- ]);
468
- useEffect(()=>{
469
- document.body.insertAdjacentHTML('beforeend', filterDefs);
470
- return ()=>{
471
- const filterDefsElement = document.getElementById('storybook-a11y-vision-filters');
472
- filterDefsElement?.parentElement?.removeChild(filterDefsElement);
473
- };
474
- }, []);
475
- return StoryFn();
476
- };
477
- let vitestMatchersExtended = false;
478
- const decorators = [
479
- withVisionSimulator
480
- ];
481
- const afterEach = async ({ id: storyId, reporting, parameters, globals, viewMode })=>{
482
- const a11yParameter = parameters.a11y;
483
- const a11yGlobals = globals.a11y;
484
- const shouldRunEnvironmentIndependent = a11yParameter?.disable !== true && a11yParameter?.test !== 'off' && a11yGlobals?.manual !== true;
485
- const getMode = ()=>{
486
- switch(a11yParameter?.test){
487
- case 'todo':
488
- return 'warning';
489
- case 'error':
490
- default:
491
- return 'failed';
492
- }
493
- };
494
- if (shouldRunEnvironmentIndependent && 'story' === viewMode) try {
495
- const result = await run(a11yParameter, storyId);
496
- if (result) {
497
- const hasViolations = (result?.violations.length ?? 0) > 0;
498
- reporting.addReport({
499
- type: 'a11y',
500
- version: 1,
501
- result,
502
- status: hasViolations ? getMode() : 'passed'
503
- });
504
- if (getIsVitestStandaloneRun()) {
505
- if (hasViolations && 'failed' === getMode()) {
506
- if (!vitestMatchersExtended) {
507
- const { toHaveNoViolations } = await import("./212.js").then((mod)=>({
508
- toHaveNoViolations: mod.toHaveNoViolations
509
- }));
510
- expect.extend({
511
- toHaveNoViolations
512
- });
513
- vitestMatchersExtended = true;
514
- }
515
- expect(result).toHaveNoViolations();
516
- }
517
- }
518
- }
519
- } catch (e) {
520
- reporting.addReport({
521
- type: 'a11y',
522
- version: 1,
523
- result: {
524
- error: e
525
- },
526
- status: 'failed'
527
- });
528
- if (getIsVitestStandaloneRun()) throw e;
529
- }
530
- };
531
- const initialGlobals = {
532
- a11y: {
533
- manual: false
534
- },
535
- vision: void 0
536
- };
537
- const preview_parameters = {
538
- a11y: {
539
- test: 'todo'
540
- }
541
- };
542
- export { afterEach, decorators, initialGlobals, preview_namespaceObject, preview_parameters as parameters };
288
+ export { runAPCACheck };
@@ -0,0 +1,124 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
+ import { runAPCACheck } from "./apcaChecker.js";
3
+ describe('apcaChecker', ()=>{
4
+ let container;
5
+ beforeEach(()=>{
6
+ container = document.createElement('div');
7
+ document.body.appendChild(container);
8
+ });
9
+ afterEach(()=>{
10
+ if (container.parentNode) container.parentNode.removeChild(container);
11
+ });
12
+ it('should detect low contrast text violations', async ()=>{
13
+ const textElement = document.createElement('p');
14
+ textElement.textContent = 'This is test text';
15
+ textElement.style.color = 'rgb(170, 170, 170)';
16
+ textElement.style.backgroundColor = 'rgb(255, 255, 255)';
17
+ textElement.style.fontSize = '16px';
18
+ textElement.style.fontWeight = '400';
19
+ container.appendChild(textElement);
20
+ const result = await runAPCACheck(container);
21
+ expect(result.id).toBe('apca-contrast');
22
+ expect(result.nodes.length).toBeGreaterThan(0);
23
+ expect(result.nodes[0].failureSummary).toContain('Fix any of the following');
24
+ expect(result.nodes[0].failureSummary).toContain('APCA contrast');
25
+ });
26
+ it('should pass for high contrast text', async ()=>{
27
+ const textElement = document.createElement('p');
28
+ textElement.textContent = 'This is test text';
29
+ textElement.style.color = 'rgb(0, 0, 0)';
30
+ textElement.style.backgroundColor = 'rgb(255, 255, 255)';
31
+ textElement.style.fontSize = '16px';
32
+ textElement.style.fontWeight = '400';
33
+ container.appendChild(textElement);
34
+ const result = await runAPCACheck(container);
35
+ expect(result.id).toBe('apca-contrast');
36
+ expect(result.nodes.length).toBe(0);
37
+ });
38
+ it('should skip hidden elements', async ()=>{
39
+ const textElement = document.createElement('p');
40
+ textElement.textContent = 'This is test text';
41
+ textElement.style.color = 'rgb(170, 170, 170)';
42
+ textElement.style.backgroundColor = 'rgb(255, 255, 255)';
43
+ textElement.style.display = 'none';
44
+ container.appendChild(textElement);
45
+ const result = await runAPCACheck(container);
46
+ expect(result.nodes.length).toBe(0);
47
+ });
48
+ it('should skip aria-hidden elements', async ()=>{
49
+ const textElement = document.createElement('p');
50
+ textElement.textContent = 'This is test text';
51
+ textElement.style.color = 'rgb(170, 170, 170)';
52
+ textElement.style.backgroundColor = 'rgb(255, 255, 255)';
53
+ textElement.setAttribute('aria-hidden', 'true');
54
+ container.appendChild(textElement);
55
+ const result = await runAPCACheck(container);
56
+ expect(result.nodes.length).toBe(0);
57
+ });
58
+ it('should use appropriate thresholds for large text', async ()=>{
59
+ const textElement = document.createElement('h1');
60
+ textElement.textContent = 'Large Heading';
61
+ textElement.style.color = 'rgb(100, 100, 100)';
62
+ textElement.style.backgroundColor = 'rgb(255, 255, 255)';
63
+ textElement.style.fontSize = '32px';
64
+ textElement.style.fontWeight = '400';
65
+ container.appendChild(textElement);
66
+ const result = await runAPCACheck(container);
67
+ expect(result.id).toBe('apca-contrast');
68
+ });
69
+ it('should handle elements with inherited background colors', async ()=>{
70
+ const parent = document.createElement('div');
71
+ parent.style.backgroundColor = 'rgb(200, 200, 200)';
72
+ container.appendChild(parent);
73
+ const textElement = document.createElement('p');
74
+ textElement.textContent = 'Nested text';
75
+ textElement.style.color = 'rgb(180, 180, 180)';
76
+ textElement.style.fontSize = '16px';
77
+ parent.appendChild(textElement);
78
+ const result = await runAPCACheck(container);
79
+ expect(result.id).toBe('apca-contrast');
80
+ });
81
+ it('should enforce gold minimum font size for body text', async ()=>{
82
+ const textElement = document.createElement('p');
83
+ textElement.textContent = 'Small body text';
84
+ textElement.style.color = 'rgb(0, 0, 0)';
85
+ textElement.style.backgroundColor = 'rgb(255, 255, 255)';
86
+ textElement.style.fontSize = '12px';
87
+ textElement.style.fontWeight = '400';
88
+ container.appendChild(textElement);
89
+ const result = await runAPCACheck(container, {
90
+ level: 'gold',
91
+ useCase: 'body'
92
+ });
93
+ expect(result.nodes.length).toBeGreaterThan(0);
94
+ expect(result.nodes[0].failureSummary).toContain('minimum 16px');
95
+ });
96
+ it('should flag excessive contrast for large text at silver', async ()=>{
97
+ const textElement = document.createElement('h1');
98
+ textElement.textContent = 'Large heading';
99
+ textElement.style.color = 'rgb(0, 0, 0)';
100
+ textElement.style.backgroundColor = 'rgb(255, 255, 255)';
101
+ textElement.style.fontSize = '40px';
102
+ textElement.style.fontWeight = '400';
103
+ container.appendChild(textElement);
104
+ const result = await runAPCACheck(container, {
105
+ level: 'silver',
106
+ useCase: 'body'
107
+ });
108
+ expect(result.nodes.length).toBeGreaterThan(0);
109
+ expect(result.nodes[0].failureSummary).toContain('exceeds the maximum');
110
+ });
111
+ it('should include proper metadata in results', async ()=>{
112
+ const textElement = document.createElement('p');
113
+ textElement.textContent = 'Test';
114
+ textElement.style.color = 'rgb(170, 170, 170)';
115
+ textElement.style.backgroundColor = 'rgb(255, 255, 255)';
116
+ container.appendChild(textElement);
117
+ const result = await runAPCACheck(container);
118
+ expect(result.id).toBe('apca-contrast');
119
+ expect(result.tags).toContain('wcag3');
120
+ expect(result.tags).toContain('apca');
121
+ expect(result.description).toContain('APCA');
122
+ expect(result.helpUrl).toBeTruthy();
123
+ });
124
+ });
@@ -0,0 +1,4 @@
1
+ import { combinedRulesMap } from "./AccessibilityRuleMaps.js";
2
+ const getTitleForAxeResult = (axeResult)=>combinedRulesMap[axeResult.id]?.title || axeResult.id;
3
+ const getFriendlySummaryForAxeResult = (axeResult)=>combinedRulesMap[axeResult.id]?.friendlySummary || axeResult.description;
4
+ export { getFriendlySummaryForAxeResult, getTitleForAxeResult };
@@ -0,0 +1,140 @@
1
+ import react, { useMemo } from "react";
2
+ import { Badge, Button } from "storybook/internal/components";
3
+ import { SyncIcon } from "@storybook/icons";
4
+ import { styled } from "storybook/theming";
5
+ import { RuleType } from "../types.js";
6
+ import { useA11yContext } from "./A11yContext.js";
7
+ import { Report } from "./Report/Report.js";
8
+ import { Tabs } from "./Tabs.js";
9
+ import { TestDiscrepancyMessage } from "./TestDiscrepancyMessage.js";
10
+ const RotatingIcon = styled(SyncIcon)(({ theme })=>({
11
+ animation: `${theme.animation.rotate360} 1s linear infinite;`,
12
+ margin: 4
13
+ }));
14
+ const Tab = styled.div({
15
+ display: 'flex',
16
+ alignItems: 'center',
17
+ gap: 6
18
+ });
19
+ const Centered = styled.span(({ theme })=>({
20
+ display: 'flex',
21
+ flexDirection: 'column',
22
+ alignItems: 'center',
23
+ justifyContent: 'center',
24
+ textAlign: 'center',
25
+ fontSize: theme.typography.size.s2,
26
+ height: '100%',
27
+ gap: 24,
28
+ div: {
29
+ display: 'flex',
30
+ flexDirection: 'column',
31
+ alignItems: 'center',
32
+ gap: 8
33
+ },
34
+ p: {
35
+ margin: 0,
36
+ color: theme.textMutedColor
37
+ },
38
+ code: {
39
+ display: 'inline-block',
40
+ fontSize: theme.typography.size.s2 - 1,
41
+ backgroundColor: theme.background.app,
42
+ border: `1px solid ${theme.color.border}`,
43
+ borderRadius: 4,
44
+ padding: '2px 3px'
45
+ }
46
+ }));
47
+ const A11YPanel = ()=>{
48
+ const { parameters, tab, results, status, handleManual, error, discrepancy, handleSelectionChange, selectedItems, toggleOpen } = useA11yContext();
49
+ const tabs = useMemo(()=>{
50
+ const { passes, incomplete, violations } = results ?? {
51
+ passes: [],
52
+ incomplete: [],
53
+ violations: []
54
+ };
55
+ return [
56
+ {
57
+ label: /*#__PURE__*/ react.createElement(Tab, null, "Violations", /*#__PURE__*/ react.createElement(Badge, {
58
+ compact: true,
59
+ status: 'violations' === tab ? 'active' : 'neutral'
60
+ }, violations.length)),
61
+ panel: /*#__PURE__*/ react.createElement(Report, {
62
+ items: violations,
63
+ type: RuleType.VIOLATION,
64
+ empty: "No accessibility violations found.",
65
+ handleSelectionChange: handleSelectionChange,
66
+ selectedItems: selectedItems,
67
+ toggleOpen: toggleOpen
68
+ }),
69
+ items: violations,
70
+ type: RuleType.VIOLATION
71
+ },
72
+ {
73
+ label: /*#__PURE__*/ react.createElement(Tab, null, "Passes", /*#__PURE__*/ react.createElement(Badge, {
74
+ compact: true,
75
+ status: 'passes' === tab ? 'active' : 'neutral'
76
+ }, passes.length)),
77
+ panel: /*#__PURE__*/ react.createElement(Report, {
78
+ items: passes,
79
+ type: RuleType.PASS,
80
+ empty: "No passing accessibility checks found.",
81
+ handleSelectionChange: handleSelectionChange,
82
+ selectedItems: selectedItems,
83
+ toggleOpen: toggleOpen
84
+ }),
85
+ items: passes,
86
+ type: RuleType.PASS
87
+ },
88
+ {
89
+ label: /*#__PURE__*/ react.createElement(Tab, null, "Inconclusive", /*#__PURE__*/ react.createElement(Badge, {
90
+ compact: true,
91
+ status: 'incomplete' === tab ? 'active' : 'neutral'
92
+ }, incomplete.length)),
93
+ panel: /*#__PURE__*/ react.createElement(Report, {
94
+ items: incomplete,
95
+ type: RuleType.INCOMPLETION,
96
+ empty: "No inconclusive accessibility checks found.",
97
+ handleSelectionChange: handleSelectionChange,
98
+ selectedItems: selectedItems,
99
+ toggleOpen: toggleOpen
100
+ }),
101
+ items: incomplete,
102
+ type: RuleType.INCOMPLETION
103
+ }
104
+ ];
105
+ }, [
106
+ tab,
107
+ results,
108
+ handleSelectionChange,
109
+ selectedItems,
110
+ toggleOpen
111
+ ]);
112
+ if (parameters.disable || 'off' === parameters.test) return /*#__PURE__*/ react.createElement(Centered, null, /*#__PURE__*/ react.createElement("div", null, /*#__PURE__*/ react.createElement("strong", null, "Accessibility tests are disabled for this story"), /*#__PURE__*/ react.createElement("p", null, "Update", ' ', /*#__PURE__*/ react.createElement("code", null, parameters.disable ? 'parameters.a11y.disable' : 'parameters.a11y.test'), ' ', "to enable accessibility tests.")));
113
+ return /*#__PURE__*/ react.createElement(react.Fragment, null, discrepancy && /*#__PURE__*/ react.createElement(TestDiscrepancyMessage, {
114
+ discrepancy: discrepancy
115
+ }), 'ready' === status || 'ran' === status ? /*#__PURE__*/ react.createElement(Tabs, {
116
+ key: "tabs",
117
+ tabs: tabs
118
+ }) : /*#__PURE__*/ react.createElement(Centered, {
119
+ style: {
120
+ marginTop: discrepancy ? '1em' : 0
121
+ }
122
+ }, 'initial' === status && /*#__PURE__*/ react.createElement("div", null, /*#__PURE__*/ react.createElement(RotatingIcon, {
123
+ size: 12
124
+ }), /*#__PURE__*/ react.createElement("strong", null, "Preparing accessibility scan"), /*#__PURE__*/ react.createElement("p", null, "Please wait while the addon is initializing...")), 'manual' === status && /*#__PURE__*/ react.createElement(react.Fragment, null, /*#__PURE__*/ react.createElement("div", null, /*#__PURE__*/ react.createElement("strong", null, "Accessibility tests run manually for this story"), /*#__PURE__*/ react.createElement("p", null, "Results will not show when using the testing module. You can still run accessibility tests manually.")), /*#__PURE__*/ react.createElement(Button, {
125
+ ariaLabel: false,
126
+ size: "medium",
127
+ onClick: handleManual
128
+ }, "Run accessibility scan"), /*#__PURE__*/ react.createElement("p", null, "Update ", /*#__PURE__*/ react.createElement("code", null, "globals.a11y.manual"), " to disable manual mode.")), 'running' === status && /*#__PURE__*/ react.createElement("div", null, /*#__PURE__*/ react.createElement(RotatingIcon, {
129
+ size: 12
130
+ }), /*#__PURE__*/ react.createElement("strong", null, "Accessibility scan in progress"), /*#__PURE__*/ react.createElement("p", null, "Please wait while the accessibility scan is running...")), 'error' === status && /*#__PURE__*/ react.createElement(react.Fragment, null, /*#__PURE__*/ react.createElement("div", null, /*#__PURE__*/ react.createElement("strong", null, "The accessibility scan encountered an error"), /*#__PURE__*/ react.createElement("p", null, 'string' == typeof error ? error : error instanceof Error ? error.toString() : JSON.stringify(error, null, 2))), /*#__PURE__*/ react.createElement(Button, {
131
+ ariaLabel: false,
132
+ size: "medium",
133
+ onClick: handleManual
134
+ }, "Rerun accessibility scan")), 'component-test-error' === status && /*#__PURE__*/ react.createElement(react.Fragment, null, /*#__PURE__*/ react.createElement("div", null, /*#__PURE__*/ react.createElement("strong", null, "This story's component tests failed"), /*#__PURE__*/ react.createElement("p", null, "Automated accessibility tests will not run until this is resolved. You can still test manually.")), /*#__PURE__*/ react.createElement(Button, {
135
+ ariaLabel: false,
136
+ size: "medium",
137
+ onClick: handleManual
138
+ }, "Run accessibility scan"))));
139
+ };
140
+ export { A11YPanel };