Sha256: b9549bf94305b6088d1ca071aca1e4ff4eaff9194bc786a5606332a2889237f5

Contents?: true

Size: 1.47 KB

Versions: 60

Compression:

Stored size: 1.47 KB

Contents

import {controller} from '@github/catalyst'

// eslint-disable-next-line custom-elements/no-exports-with-element
export class ActionListTruncationObserver {
  resizeObserver = new ResizeObserver(entries => {
    for (const entry of entries) {
      const action = entry.target

      if (action instanceof HTMLElement) {
        this.update(action)
      }
    }
  })

  constructor(el: HTMLElement) {
    this.resizeObserver.observe(el)
  }

  unobserve(el: HTMLElement) {
    this.resizeObserver.unobserve(el)
  }

  update(el: HTMLElement) {
    const items = el.querySelectorAll('li')

    for (const item of items) {
      const label = item.querySelector('.ActionListItem-label') as HTMLElement
      if (!label) continue
      const tooltip = item.querySelector('.ActionListItem-truncationTooltip') as HTMLElement
      if (!tooltip) continue

      const isTruncated = label.scrollWidth > label.clientWidth

      if (isTruncated) {
        tooltip.style.display = ''
      } else {
        tooltip.style.display = 'none'
      }
    }
  }
}

@controller
// eslint-disable-next-line custom-elements/expose-class-on-global
export class ActionListElement extends HTMLElement {
  #truncationObserver: ActionListTruncationObserver

  connectedCallback() {
    this.#truncationObserver = new ActionListTruncationObserver(this)
  }

  disconnectedCallback() {
    this.#truncationObserver.unobserve(this)
  }
}

declare global {
  interface Window {
    ActionListElement: typeof ActionListElement
  }
}

Version data entries

60 entries across 60 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.49.2 app/components/primer/alpha/action_list.ts
primer_view_components-0.35.2 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.49.1 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.49.0 app/components/primer/alpha/action_list.ts
primer_view_components-0.35.1 app/components/primer/alpha/action_list.ts
primer_view_components-0.35.0 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.48.2 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.48.1 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.48.0 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.47.1 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.47.0 app/components/primer/alpha/action_list.ts
primer_view_components-0.34.0 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.46.1 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.46.0 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.45.0 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.44.3 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.44.2 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.44.1 app/components/primer/alpha/action_list.ts
primer_view_components-0.33.0 app/components/primer/alpha/action_list.ts
openproject-primer_view_components-0.44.0 app/components/primer/alpha/action_list.ts