Skip to content

Commit 8c4daeb

Browse files
committed
chore: big changes
1 parent 9cc4d54 commit 8c4daeb

12 files changed

Lines changed: 225 additions & 212 deletions

File tree

examples/react/basic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@tanstack/react-query-devtools": "^5.90.1",
1818
"@tanstack/react-router": "^1.132.0",
1919
"@tanstack/react-router-devtools": "^1.132.0",
20+
"@tanstack/devtools-a11y": "workspace:*",
2021
"react": "^19.2.0",
2122
"react-dom": "^19.2.0",
2223
"zod": "^4.1.11"

examples/react/basic/src/setup.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
22
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
3+
import { createA11yDevtoolsReactPlugin } from '@tanstack/devtools-a11y/react'
4+
35
import {
46
Link,
57
Outlet,
@@ -70,10 +72,15 @@ export default function DevtoolsExample() {
7072
name: 'TanStack Router',
7173
render: <TanStackRouterDevtoolsPanel router={router} />,
7274
},
75+
{
76+
name: 'TanStack Router',
77+
render: <TanStackRouterDevtoolsPanel router={router} />,
78+
},
7379
{
7480
name: 'Package.json',
7581
render: () => <PackageJsonPanel />,
7682
},
83+
createA11yDevtoolsReactPlugin({ runOnMount: false })[0](),
7784
/* {
7885
name: "The actual app",
7986
render: <iframe style={{ width: '100%', height: '100%' }} src="http://localhost:3005" />,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { createContext, createMemo, createSignal, useContext } from 'solid-js'
2+
import { createStore } from 'solid-js/store'
3+
4+
import { runAudit } from '../scanner/audit'
5+
import { DEFAULT_CONFIG } from '../config'
6+
7+
import type {
8+
A11yAuditResult,
9+
A11yPluginOptions,
10+
SeverityThreshold,
11+
} from '../types'
12+
import type { ParentComponent } from 'solid-js'
13+
14+
type UseAllyValueProps = {
15+
options?: A11yPluginOptions
16+
}
17+
18+
function useAllyValue(props: UseAllyValueProps) {
19+
const [config, setConfig] = createStore<A11yPluginOptions>({
20+
...DEFAULT_CONFIG,
21+
...(props.options ?? {}),
22+
})
23+
24+
const [allyResult, setAllyResult] = createStore<{
25+
audit?: A11yAuditResult
26+
state: 'init' | 'scanning' | 'done'
27+
}>({ state: 'init' })
28+
const [impactKey, setImpactKey] = createSignal<SeverityThreshold | 'all'>(
29+
'all',
30+
)
31+
32+
const triggerAllyScan = async () => {
33+
const results = await runAudit(config)
34+
setAllyResult({ audit: results, state: 'done' })
35+
}
36+
37+
const filteredIssues = createMemo(() => {
38+
if (allyResult.state !== 'done' || !allyResult.audit?.issues) return []
39+
if (impactKey() === 'all') return allyResult.audit.issues
40+
41+
return allyResult.audit.issues.filter((val) => val.impact === impactKey())
42+
})
43+
44+
return {
45+
impactKey,
46+
setImpactKey,
47+
48+
filteredIssues,
49+
50+
triggerAllyScan,
51+
52+
setConfig,
53+
54+
audit: allyResult.audit,
55+
state: allyResult.state,
56+
}
57+
}
58+
59+
type ContextType = ReturnType<typeof useAllyValue>
60+
61+
const AllyContext = createContext<ContextType | null>(null)
62+
63+
type AllyProviderProps = { options?: A11yPluginOptions }
64+
65+
export const AllyProvider: ParentComponent<AllyProviderProps> = (props) => {
66+
const value = useAllyValue({ options: props.options })
67+
68+
return (
69+
<AllyContext.Provider value={value}>{props.children}</AllyContext.Provider>
70+
)
71+
}
72+
73+
export function useAllyContext() {
74+
const context = useContext(AllyContext)
75+
76+
if (context === null) {
77+
throw new Error('useAllyContext must be used within an AllyProvider')
78+
}
79+
80+
return context
81+
}

packages/devtools-a11y/src/core/A11yDevtoolsCore.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { createSignal } from 'solid-js'
44
import { A11yDevtoolsPanel } from '../ui/A11yDevtoolsPanel'
5-
import type {Accessor} from 'solid-js';
5+
import type { Accessor } from 'solid-js'
66
import type { A11yPluginOptions } from '../types'
77

88
function resolveTheme(theme: 'light' | 'dark' | 'system'): 'light' | 'dark' {

0 commit comments

Comments
 (0)