|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { AllTabGroup } from '../../types' |
| 3 | +import { |
| 4 | + DEFAULT_TAB_GROUP, checkGroupExist, |
| 5 | + createGroup, removeTabGroup, resetAllTabs, |
| 6 | + shouldHideTabGroup, ungroupAllTabs, |
| 7 | +} from '../store' |
| 8 | +
|
| 9 | +const groupTabs = useGroupedTabs() |
| 10 | +
|
| 11 | +const [showConfirm, toggleConfirm] = useToggle(false) |
| 12 | +
|
| 13 | +const currentRemovedGroup = ref<AllTabGroup | null>(null) |
| 14 | +const confirmHandlers = { |
| 15 | + ungroup: { |
| 16 | + message: 'Are you sure you want to ungroup all tabs?', |
| 17 | + handler: ungroupAllTabs, |
| 18 | + }, |
| 19 | + reset: { |
| 20 | + message: 'Are you sure you want to reset group?', |
| 21 | + handler: resetAllTabs, |
| 22 | + }, |
| 23 | + remove: { |
| 24 | + message: 'Are you sure you want to remove this group?', |
| 25 | + handler: () => currentRemovedGroup.value && removeTabGroup(currentRemovedGroup.value), |
| 26 | + }, |
| 27 | +} |
| 28 | +const currentConfirm = ref<keyof typeof confirmHandlers>('reset') |
| 29 | +const currentConfirmHandlers = computed(() => confirmHandlers[currentConfirm.value]) |
| 30 | +
|
| 31 | +function handleShowConfirm(confirmType: keyof typeof confirmHandlers) { |
| 32 | + currentConfirm.value = confirmType |
| 33 | + toggleConfirm(true) |
| 34 | +} |
| 35 | +
|
| 36 | +const groupName = ref('') |
| 37 | +
|
| 38 | +function handleCreateGroup() { |
| 39 | + const name = groupName.value.trim() |
| 40 | + if (checkGroupExist(name)) |
| 41 | + // eslint-disable-next-line no-alert |
| 42 | + return alert('[Vue-Devtools] Group already exist') |
| 43 | +
|
| 44 | + createGroup(name) |
| 45 | + groupName.value = '' |
| 46 | +} |
| 47 | +</script> |
| 48 | + |
| 49 | +<template> |
| 50 | + <div flex flex-wrap items-center gap-12px> |
| 51 | + <VButton n="primary" @click.prevent="handleShowConfirm('reset')"> |
| 52 | + <div i-material-symbols:360 /> |
| 53 | + Reset group |
| 54 | + </VButton> |
| 55 | + <VButton |
| 56 | + n="primary" @click.prevent="handleShowConfirm('ungroup')" |
| 57 | + > |
| 58 | + <div i-material-symbols-ungroup /> |
| 59 | + Ungroup all tabs |
| 60 | + </VButton> |
| 61 | + <div flex gap-2> |
| 62 | + <VTextInput v-model="groupName" class="w-120px" /> |
| 63 | + <VButton |
| 64 | + border-none bg-primary text-white hover:text-white |
| 65 | + :disabled="!groupName.trim().length" @click="handleCreateGroup()" |
| 66 | + > |
| 67 | + Create |
| 68 | + </VButton> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + <VConfirm v-model="showConfirm" :message="currentConfirmHandlers.message" @confirm="currentConfirmHandlers.handler" /> |
| 72 | + <template v-for="[name, { show, tabs }] in groupTabs" :key="name"> |
| 73 | + <div v-if="!shouldHideTabGroup(name, tabs.length) && show" mt-3> |
| 74 | + <div flex="~ gap-2" flex-auto items-center justify-between> |
| 75 | + <span capitalize op75>{{ name }}</span> |
| 76 | + <VIconButton |
| 77 | + v-if="name !== DEFAULT_TAB_GROUP" |
| 78 | + icon="material-symbols:delete" class="hover:color-red" |
| 79 | + @click="currentRemovedGroup = name; handleShowConfirm('remove')" |
| 80 | + /> |
| 81 | + </div> |
| 82 | + <TabGroupItem |
| 83 | + :tabs="tabs" :group-name="name" |
| 84 | + /> |
| 85 | + </div> |
| 86 | + </template> |
| 87 | +</template> |
0 commit comments