Skip to content

Commit 3c17826

Browse files
committed
refactor: ui components
1 parent c661887 commit 3c17826

File tree

7 files changed

+46
-40
lines changed

7 files changed

+46
-40
lines changed

examples/plugin-a11y-checker/src/node/plugin.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import fs from 'node:fs'
33
import { fileURLToPath } from 'node:url'
44
import { normalizePath } from 'vite'
55

6-
function resolveClientScript(): string {
7-
const distFromBundle = fileURLToPath(new URL('./client/run-axe.js', import.meta.url))
8-
const distFromSource = fileURLToPath(new URL('../../dist/client/run-axe.js', import.meta.url))
9-
return fs.existsSync(distFromBundle) ? distFromBundle : distFromSource
6+
function resolveClientScript(): string | undefined {
7+
const paths = [
8+
fileURLToPath(new URL('./client/run-axe.js', import.meta.url)),
9+
fileURLToPath(new URL('../../dist/client/run-axe.js', import.meta.url)),
10+
fileURLToPath(new URL('../client/run-axe.ts', import.meta.url)),
11+
]
12+
return paths.find(path => fs.existsSync(path))
1013
}
1114

1215
export function A11yCheckerPlugin(): PluginWithDevTools {
@@ -15,6 +18,9 @@ export function A11yCheckerPlugin(): PluginWithDevTools {
1518
devtools: {
1619
setup(context) {
1720
const clientScript = resolveClientScript()
21+
if (!clientScript) {
22+
throw new Error('[plugin-a11y-checker] Client script not found, did you build the plugin?')
23+
}
1824

1925
context.docks.register({
2026
type: 'action',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@unocss/eslint-config": "catalog:devtools",
5050
"@vueuse/core": "catalog:frontend",
5151
"ansis": "catalog:deps",
52+
"axe-core": "catalog:devtools",
5253
"bumpp": "catalog:devtools",
5354
"chokidar": "catalog:devtools",
5455
"esbuild": "catalog:build",

packages/core/src/client/webcomponents/components/FilterToggles.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defineProps<{
66
/** Map item key → { icon, color, label } for styled items */
77
styles?: Record<string, { icon?: string, color?: string, label?: string }>
88
/** Compute inline color via hash for items without predefined styles */
9-
hashColor?: (item: string) => string
9+
hashColor?: (item: string, opacity: number) => string
1010
}>()
1111
1212
defineEmits<{
@@ -16,7 +16,7 @@ defineEmits<{
1616

1717
<template>
1818
<span class="text-xs op40">{{ label }}</span>
19-
<div class="flex flex-wrap items-center gap-0">
19+
<div class="flex flex-wrap items-center gap-0.5">
2020
<button
2121
v-for="item of items"
2222
:key="item"
@@ -26,7 +26,10 @@ defineEmits<{
2626
? (styles?.[item]?.color || '')
2727
: 'op30',
2828
]"
29-
:style="!styles?.[item]?.color && hashColor ? { color: active.size === 0 || active.has(item) ? hashColor(item) : undefined } : undefined"
29+
:style="!styles?.[item]?.color && hashColor ? {
30+
color: active.size === 0 || active.has(item) ? hashColor(item, 1) : undefined,
31+
backgroundColor: active.size === 0 || active.has(item) ? hashColor(item, 0.1) : undefined,
32+
} : undefined"
3033
@click="$emit('toggle', item)"
3134
>
3235
<div v-if="styles?.[item]?.icon" :class="styles[item]!.icon" class="w-3.5 h-3.5" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script setup lang="ts">
2+
import { computed } from 'vue'
3+
import { getHashColorFromString } from './LogItemConstants'
4+
5+
const props = defineProps<{
6+
label: string
7+
}>()
8+
9+
const style = computed(() => ({
10+
color: getHashColorFromString(props.label),
11+
backgroundColor: getHashColorFromString(props.label, 0.1),
12+
}))
13+
</script>
14+
15+
<template>
16+
<span class="text-xs px-1 rounded" :style="style">{{ label }}</span>
17+
</template>

packages/core/src/client/webcomponents/components/LogItem.vue

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script setup lang="ts">
22
import type { DevToolsLogEntry } from '@vitejs/devtools-kit'
33
import { useTimeAgo } from '@vueuse/core'
4-
import { getHashColorFromString, levels } from './LogItemConstants'
4+
import HashBadge from './HashBadge.vue'
5+
import { levels } from './LogItemConstants'
56
67
const props = defineProps<{
78
entry: DevToolsLogEntry
@@ -33,17 +34,8 @@ const timeAgo = useTimeAgo(() => props.entry.timestamp)
3334
{{ entry.description }}
3435
</div>
3536
<div v-if="!compact" class="flex items-center gap-2 mt-0.5">
36-
<span
37-
v-if="entry.category"
38-
class="text-xs px-1 rounded"
39-
:style="{ color: getHashColorFromString(entry.category), backgroundColor: getHashColorFromString(entry.category, 0.1) }"
40-
>{{ entry.category }}</span>
41-
<span
42-
v-for="label of entry.labels"
43-
:key="label"
44-
class="text-xs px-1 rounded"
45-
:style="{ color: getHashColorFromString(label), backgroundColor: getHashColorFromString(label, 0.1) }"
46-
>{{ label }}</span>
37+
<HashBadge v-if="entry.category" :label="entry.category" />
38+
<HashBadge v-for="label of entry.labels" :key="label" :label="label" />
4739
</div>
4840
</div>
4941
<span v-if="!compact" class="text-xs op40 flex-none" :title="new Date(entry.timestamp).toLocaleString()">{{ timeAgo }}</span>

packages/core/src/client/webcomponents/components/ViewBuiltinLogs.vue

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useTimeAgo } from '@vueuse/core'
66
import { computed, onMounted, ref } from 'vue'
77
import { markLogsAsRead, useLogs } from '../state/logs'
88
import FilterToggles from './FilterToggles.vue'
9+
import HashBadge from './HashBadge.vue'
910
import LogItem from './LogItem.vue'
1011
import { getHashColorFromString, levels, sources } from './LogItemConstants'
1112
@@ -277,7 +278,7 @@ onMounted(() => {
277278
label="Category"
278279
:items="allCategories"
279280
:active="(activeCategories as Set<string>)"
280-
:hash-color="(item: string) => getHashColorFromString(item)"
281+
:hash-color="getHashColorFromString"
281282
@toggle="toggleCategory"
282283
/>
283284
</template>
@@ -288,7 +289,7 @@ onMounted(() => {
288289
label="Labels"
289290
:items="allLabels"
290291
:active="(activeLabelFilters as Set<string>)"
291-
:hash-color="(item: string) => getHashColorFromString(item)"
292+
:hash-color="getHashColorFromString"
292293
@toggle="toggleLabelFilter"
293294
/>
294295
</template>
@@ -374,25 +375,8 @@ onMounted(() => {
374375

375376
<!-- Category + Labels -->
376377
<div v-if="selectedEntry.category || (selectedEntry.labels && selectedEntry.labels.length)" class="flex flex-wrap gap-1 mb-3">
377-
<span
378-
v-if="selectedEntry.category"
379-
class="text-xs px-1.5 py-0.5 rounded border-l-2"
380-
:style="{
381-
color: getHashColorFromString(selectedEntry.category),
382-
borderColor: getHashColorFromString(selectedEntry.category, 0.4),
383-
backgroundColor: getHashColorFromString(selectedEntry.category, 0.1),
384-
}"
385-
>{{ selectedEntry.category }}</span>
386-
<span
387-
v-for="label of selectedEntry.labels"
388-
:key="label"
389-
class="text-xs px-1.5 py-0.5 rounded border-l-2"
390-
:style="{
391-
color: getHashColorFromString(label),
392-
borderColor: getHashColorFromString(label, 0.4),
393-
backgroundColor: getHashColorFromString(label, 0.1),
394-
}"
395-
>{{ label }}</span>
378+
<HashBadge v-if="selectedEntry.category" :label="selectedEntry.category" />
379+
<HashBadge v-for="label of selectedEntry.labels" :key="label" :label="label" />
396380
</div>
397381

398382
<!-- File position -->

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)