1
0
elk/composables/aria.ts

62 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

export type AriaLive = 'off' | 'polite' | 'assertive'
export type AriaAnnounceType = 'announce' | 'mute' | 'unmute'
2022-12-24 00:08:36 +09:00
const ariaAnnouncer = useEventBus<AriaAnnounceType, string | undefined>(Symbol('aria-announcer'))
export function useAriaAnnouncer() {
2022-12-24 00:08:36 +09:00
const announce = (message: string) => {
ariaAnnouncer.emit('announce', message)
}
const mute = () => {
ariaAnnouncer.emit('mute')
}
const unmute = () => {
ariaAnnouncer.emit('unmute')
}
return { announce, ariaAnnouncer, mute, unmute }
}
export function useAriaLog() {
const logs = ref<any[]>([])
2022-12-24 00:08:36 +09:00
const announceLogs = (messages: any[]) => {
logs.value = messages
2022-12-24 00:08:36 +09:00
}
const appendLogs = (messages: any[]) => {
logs.value = logs.value.concat(messages)
2022-12-24 00:08:36 +09:00
}
const clearLogs = () => {
logs.value = []
2022-12-24 00:08:36 +09:00
}
return {
announceLogs,
appendLogs,
clearLogs,
logs,
}
}
export function useAriaStatus() {
const status = ref<any>('')
2022-12-24 00:08:36 +09:00
const announceStatus = (message: any) => {
status.value = message
2022-12-24 00:08:36 +09:00
}
const clearStatus = () => {
status.value = ''
2022-12-24 00:08:36 +09:00
}
return {
announceStatus,
clearStatus,
status,
}
}