-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathControlPanel.vue
More file actions
146 lines (133 loc) · 4.73 KB
/
ControlPanel.vue
File metadata and controls
146 lines (133 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<script setup lang="ts">
import type { WcagLevel } from '../../../src/runtime/types'
import { isScanRunning, isConstantScanningEnabled, enableConstantScanning, disableConstantScanning, triggerScan, resetViolations, axeViolations, currentRoute } from '../composables/rpc'
import { copyToClipboard } from '../composables/clipboard'
import { formatViolationsReport } from '../utils/format-report'
const props = defineProps<{
totalViolations: number
wcagFilter: WcagLevel
wcagLevelOptions: { value: WcagLevel, label: string }[]
hasViolations: boolean
}>()
const emit = defineEmits<{
'update:wcagFilter': [value: WcagLevel]
}>()
function toggleConstantScanning() {
if (isConstantScanningEnabled.value) {
disableConstantScanning()
}
else {
enableConstantScanning()
}
}
function handleTriggerScan() {
triggerScan()
}
function handleReset() {
clearAllPinned()
resetViolations()
}
async function handleCopyReport() {
const report = formatViolationsReport(axeViolations.value, currentRoute.value)
const success = await copyToClipboard(report)
if (success) {
devtoolsUiShowNotification({
message: 'Report copied to clipboard',
icon: 'i-carbon-checkmark',
classes: 'text-white bg-green-600/90',
duration: 3000,
})
}
else {
devtoolsUiShowNotification({
message: 'Failed to copy report to clipboard',
icon: 'i-carbon-close',
classes: 'text-white bg-red-600/90',
duration: 5000,
})
}
}
</script>
<template>
<NCard class="p-4 mb-4">
<div class="flex items-center justify-between gap-4 flex-wrap">
<div class="flex items-center gap-4 flex-wrap">
<button
class="px-3 py-1.5 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-900 dark:text-gray-100 text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
:disabled="isScanRunning"
@click="handleTriggerScan"
>
<span class="flex items-center gap-2">
<NIcon
:icon="isScanRunning ? 'i-carbon-renew' : 'i-carbon-play'"
:class="{ 'animate-spin': isScanRunning }"
/>
{{ isScanRunning ? 'Scanning' : 'Run Scan' }}
</span>
</button>
<button
class="px-3 py-1.5 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-900 dark:text-gray-100 text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
:disabled="totalViolations === 0"
@click="handleReset"
>
<span class="flex items-center gap-2">
<NIcon icon="i-carbon-trash-can" />
Clear Results
</span>
</button>
<button
class="px-3 py-1.5 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-900 dark:text-gray-100 text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
:disabled="totalViolations === 0"
@click="handleCopyReport"
>
<span class="flex items-center gap-2">
<NIcon icon="i-carbon-copy" />
Copy Report
</span>
</button>
<div class="flex items-center gap-2">
<label class="flex items-center gap-2 cursor-pointer">
<input
type="checkbox"
:checked="isConstantScanningEnabled"
class="w-4 h-4 cursor-pointer"
@change="toggleConstantScanning"
>
<span class="text-sm">Auto-scan on user events</span>
</label>
<NIcon
v-if="isConstantScanningEnabled"
icon="i-carbon-checkmark-filled"
class="text-green-500"
/>
</div>
<div
v-if="props.hasViolations"
class="flex items-center gap-2"
>
<span class="text-sm opacity-70">WCAG Level Filter:</span>
<NSelect
:model-value="props.wcagFilter"
aria-label="WCAG level filter"
class="text-sm"
@update:model-value="(value) => emit('update:wcagFilter', value as WcagLevel)"
>
<option
v-for="option in props.wcagLevelOptions"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</option>
</NSelect>
</div>
</div>
<div
v-if="isConstantScanningEnabled"
class="text-xs opacity-70"
>
Scanning automatically on mouse, keyboard, and touch events
</div>
</div>
</NCard>
</template>