Sha256: a2128ede87d5ef5f226d54cefe8ddb4c2b8fee03d00a4aed15935074ea7f729a

Contents?: true

Size: 1.29 KB

Versions: 19

Compression:

Stored size: 1.29 KB

Contents

import '@github/clipboard-copy-element'

const CLIPBOARD_COPY_TIMER_DURATION = 2000

function showSVG(svg: SVGElement) {
  svg.style.display = 'inline-block'
}

function hideSVG(svg: SVGElement) {
  svg.style.display = 'none'
}

// Toggle a copy button.
function showCopy(button: HTMLElement) {
  const [copyIcon, checkIcon] = button.querySelectorAll<SVGElement>('.octicon')

  if (!copyIcon || !checkIcon) return

  showSVG(copyIcon)
  hideSVG(checkIcon)
}

// Toggle a copy button.
function showCheck(button: HTMLElement) {
  const [copyIcon, checkIcon] = button.querySelectorAll<SVGElement>('.octicon')

  if (!copyIcon || !checkIcon) return

  hideSVG(copyIcon)
  showSVG(checkIcon)
}

const clipboardCopyElementTimers = new WeakMap<HTMLElement, number>()

document.addEventListener('clipboard-copy', function({target}) {
  if (!(target instanceof HTMLElement)) return
  if (!target.hasAttribute('data-view-component')) return

  const currentTimeout = clipboardCopyElementTimers.get(target)

  if (currentTimeout) {
    clearTimeout(currentTimeout)
    clipboardCopyElementTimers.delete(target)
  } else {
    showCheck(target)
  }

  clipboardCopyElementTimers.set(
    target,
    setTimeout(() => {
      showCopy(target)
      clipboardCopyElementTimers.delete(target)
    }, CLIPBOARD_COPY_TIMER_DURATION)
  )
})

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
primer_view_components-0.0.92 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.91 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.90 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.89 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.88 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.87 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.86 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.85 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.84 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.83 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.82 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.81 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.80 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.79 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.78 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.77 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.76 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.75 app/components/primer/clipboard_copy_component.ts
primer_view_components-0.0.74 app/components/primer/clipboard_copy_component.ts