|
1 | 1 | import {throttle} from 'throttle-debounce';
|
2 |
| -import {isHorizontallyOverflown, createElementFromHTML} from '../utils/dom.js'; |
3 | 2 | import {svg} from '../svg.js';
|
4 |
| -import $ from 'jquery'; |
| 3 | +import {createTippy} from '../modules/tippy.js'; |
5 | 4 |
|
6 | 5 | const update = throttle(100, (menu) => {
|
7 |
| - const isOverflown = isHorizontallyOverflown(menu); |
8 |
| - if (isOverflown) { |
9 |
| - const overflownItems = []; |
10 |
| - const {right: menuRight} = menu.getBoundingClientRect(); |
11 |
| - for (const item of menu.querySelectorAll('.overflow-menu-items .item')) { |
12 |
| - const {right: itemRight} = item.getBoundingClientRect(); |
13 |
| - if (itemRight >= menuRight) { |
14 |
| - overflownItems.push(item.cloneNode(true)); |
15 |
| - item.remove(); |
16 |
| - } |
| 6 | + const menuItems = menu.querySelectorAll('.overflow-menu-items .item'); |
| 7 | + const buttonItems = []; |
| 8 | + |
| 9 | + const {right: menuRight} = menu.getBoundingClientRect(); |
| 10 | + for (const item of menuItems) { |
| 11 | + const {right: itemRight} = item.getBoundingClientRect(); |
| 12 | + if (itemRight >= menuRight) { |
| 13 | + buttonItems.push(item.cloneNode(true)); |
| 14 | + item.remove(); |
17 | 15 | }
|
18 |
| - if (overflownItems.length) { |
19 |
| - menu.querySelector('.overflow-menu')?.remove(); |
20 |
| - menu.append(createElementFromHTML(` |
21 |
| - <div class="ui dropdown overflow-menu gt-px-2"> |
22 |
| - <div class="text">${svg('octicon-kebab-horizontal')}</div> |
23 |
| - <div class="menu">${overflownItems.map((item) => item.outerHTML).join('')}</div> |
24 |
| - </div> |
25 |
| - `)); |
26 |
| - $(menu).dropdown(); |
| 16 | + } |
| 17 | + |
| 18 | + if (buttonItems.length && !menu.querySelector('.overflow-menu-button')) { |
| 19 | + const btn = document.createElement('button'); |
| 20 | + btn.classList.add('overflow-menu-button', 'btn', 'tw-px-4'); |
| 21 | + btn.innerHTML = svg('octicon-kebab-horizontal'); |
| 22 | + |
| 23 | + const itemsMenu = document.createElement('div'); |
| 24 | + itemsMenu.classList.add('overflow-menu-tippy', 'ui', 'vertical', 'menu'); |
| 25 | + for (const item of buttonItems) { |
| 26 | + itemsMenu.append(item); |
27 | 27 | }
|
| 28 | + |
| 29 | + createTippy(btn, { |
| 30 | + trigger: 'click', |
| 31 | + hideOnClick: true, |
| 32 | + interactive: true, |
| 33 | + placement: 'bottom-end', |
| 34 | + role: 'menu', |
| 35 | + content: itemsMenu, |
| 36 | + }); |
| 37 | + |
| 38 | + menu.append(btn); |
28 | 39 | }
|
29 | 40 | });
|
30 | 41 |
|
|
0 commit comments