-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathDockOverflowButton.vue
More file actions
92 lines (83 loc) · 2.42 KB
/
DockOverflowButton.vue
File metadata and controls
92 lines (83 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<script setup lang="ts">
import type { DevToolsDockEntry } from '@vitejs/devtools-kit'
import type { DocksContext } from '@vitejs/devtools-kit/client'
import type { DevToolsDockEntriesGrouped } from '../state/dock-settings'
import { watchDebounced } from '@vueuse/core'
import { computed, h, ref, useTemplateRef } from 'vue'
import { setDocksOverflowPanel, useDocksOverflowPanel } from '../state/floating-tooltip'
import DockEntriesWithCategories from './DockEntriesWithCategories.vue'
import DockEntry from './DockEntry.vue'
const props = defineProps<{
context: DocksContext
isVertical: boolean
groups: DevToolsDockEntriesGrouped
selected: DevToolsDockEntry | null
}>()
const emit = defineEmits<{
(e: 'select', entry: DevToolsDockEntry): void
}>()
const overflowButton = useTemplateRef<HTMLButtonElement>('overflowButton')
const overflowBadge = computed(() => {
const count = props.groups.reduce((acc, [_, items]) => acc + items.length, 0)
if (count > 9)
return '9+'
return count.toString()
})
const isOverflowPanelVisible = ref(false)
const docksOverflowPanel = useDocksOverflowPanel()
function showOverflowPanel() {
if (!overflowButton.value)
return
isOverflowPanelVisible.value = true
setDocksOverflowPanel({
content: () => h('div', {
class: 'flex gap-0 flex-wrap max-w-200px',
}, [
h(DockEntriesWithCategories, {
context: props.context,
groups: props.groups,
isVertical: false,
selected: props.selected,
onSelect: e => emit('select', e),
}),
]),
el: overflowButton.value,
})
}
// We have an internal state and delay the update to the DOM to conflicts with the "onClickOutside" logic
watchDebounced(
() => docksOverflowPanel.value,
(value) => {
isOverflowPanelVisible.value = !!value
},
{ debounce: 1000 },
)
function toggleOverflowPanel() {
if (isOverflowPanelVisible.value)
hideOverflowPanel()
else
showOverflowPanel()
}
function hideOverflowPanel() {
isOverflowPanelVisible.value = false
setDocksOverflowPanel(null)
}
</script>
<template>
<div ref="overflowButton">
<DockEntry
:dock="{
id: 'overflow',
title: 'Overflow',
icon: 'ph:dots-three-circle-duotone',
}"
class="overflow-button"
:tooltip="false"
:badge="overflowBadge"
:is-vertical="isVertical"
:is-selected="false"
:is-dimmed="false"
@click="toggleOverflowPanel"
/>
</div>
</template>