Sha256: 01df9b2b2ba59a56e36b463d224ad338d84b6bd22c82a13ca51f82a81ee2ce6b
Contents?: true
Size: 1.38 KB
Versions: 41
Compression:
Stored size: 1.38 KB
Contents
import {controllerFactory} from '@utils/createController' import '@github/clipboard-copy-element' const CLIPBOARD_COPY_TIMER_DURATION = 2000 export default class ClipboardCopyController extends controllerFactory<HTMLDetailsElement>()({ targets: { initial: HTMLElement, confirmed: null, }, }) { declare clipboardCopyElementTimers: WeakMap<HTMLElement, number> connect() { this.clipboardCopyElementTimers = new WeakMap() } copy(event: Event) { const target = event.target as HTMLElement const currentTimeout = this.clipboardCopyElementTimers.get(target) if (currentTimeout) { clearTimeout(currentTimeout) this.clipboardCopyElementTimers.delete(target) } else { this.showConfirm() } this.clipboardCopyElementTimers.set( target, window.setTimeout(() => { this.showInitial() this.clipboardCopyElementTimers.delete(target) }, CLIPBOARD_COPY_TIMER_DURATION), ) } showConfirm() { if (this.hasConfirmedTarget) { this.confirmedTarget.classList.remove('hidden') this.confirmedTarget.classList.add('inline-block') this.initialTarget.classList.add('hidden') } } showInitial() { this.initialTarget.classList.remove('hidden') this.initialTarget.classList.add('inline-block') if (this.hasConfirmedTarget) { this.confirmedTarget.classList.add('hidden') } } }
Version data entries
41 entries across 41 versions & 1 rubygems
Version | Path |
---|---|
ariadne_view_components-0.0.64 | app/components/ariadne/ui/clipboard_copy/component.ts |