mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-20 17:03:42 +00:00
keyboard stuff, styling things
This commit is contained in:
42
src/lib/title.ts
Normal file
42
src/lib/title.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type {Action} from "svelte/action"
|
||||
import tippy from "tippy.js"
|
||||
import type {SvelteComponent} from "svelte"
|
||||
import Tooltip from "$lib/components/Tooltip.svelte"
|
||||
import hotkeys from "hotkeys-js"
|
||||
|
||||
export const action: Action<HTMLElement, {title?: string; shortcut?: string}> = (
|
||||
node: HTMLElement,
|
||||
{title, shortcut},
|
||||
) => {
|
||||
let component: SvelteComponent | undefined
|
||||
const tooltip = tippy(node, {
|
||||
arrow: false,
|
||||
theme: "tooltip",
|
||||
animation: "fade",
|
||||
delay: [500, 0],
|
||||
onShow(instance) {
|
||||
component ??= new Tooltip({
|
||||
target: instance.popper.querySelector(".tippy-content") as HTMLElement,
|
||||
props: {title, shortcut},
|
||||
})
|
||||
},
|
||||
onHidden() {
|
||||
component?.$destroy()
|
||||
component = undefined
|
||||
},
|
||||
})
|
||||
|
||||
if (shortcut) {
|
||||
hotkeys(shortcut, function (keyboardEvent) {
|
||||
keyboardEvent.preventDefault()
|
||||
node.click()
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
destroy() {
|
||||
tooltip.destroy()
|
||||
hotkeys.unbind(shortcut)
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user