add NavbarActions.vue
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<template>
|
||||
<div v-if="props.visible && visibleActionList.length" class="nav-actions">
|
||||
<t-popover
|
||||
v-model:visible="menuVisible"
|
||||
placement="bottom-right"
|
||||
:show-arrow="false"
|
||||
theme="light"
|
||||
>
|
||||
<t-button
|
||||
class="trigger"
|
||||
variant="text"
|
||||
:aria-label="props.triggerLabel"
|
||||
type="button"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon :name="props.triggerIcon" />
|
||||
</template>
|
||||
<span v-if="props.triggerText" v-text="props.triggerText" />
|
||||
</t-button>
|
||||
<template #content>
|
||||
<div class="menu">
|
||||
<t-button
|
||||
v-for="action in visibleActionList"
|
||||
:key="action.key"
|
||||
class="menu-item"
|
||||
variant="text"
|
||||
type="button"
|
||||
:theme="action.theme"
|
||||
:loading="action.loading"
|
||||
:disabled="action.disabled || action.loading"
|
||||
@click="handleAction(action)"
|
||||
>
|
||||
<template v-if="action.icon" #icon>
|
||||
<t-icon :name="action.icon" />
|
||||
</template>
|
||||
<span v-text="action.text" />
|
||||
</t-button>
|
||||
</div>
|
||||
</template>
|
||||
</t-popover>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { NavbarAction } from "@/types/NavbarAction.ts";
|
||||
|
||||
interface Props {
|
||||
actions: NavbarAction[];
|
||||
triggerIcon?: string;
|
||||
triggerLabel?: string;
|
||||
triggerText?: string;
|
||||
visible?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
triggerIcon: "ellipsis",
|
||||
triggerLabel: "更多操作",
|
||||
triggerText: "",
|
||||
visible: true
|
||||
});
|
||||
|
||||
const menuVisible = ref(false);
|
||||
const visibleActionList = computed(() => props.actions.filter(action => action.visible !== false));
|
||||
|
||||
async function handleAction(action: NavbarAction): Promise<void> {
|
||||
menuVisible.value = false;
|
||||
await action.action();
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.nav-actions {
|
||||
--td-popover-padding: 0 .5rem;
|
||||
|
||||
width: 6rem;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
|
||||
:deep(.t-popover__content) { border-radius: .875rem; }
|
||||
|
||||
.trigger { padding: 0; }
|
||||
|
||||
.menu {
|
||||
gap: .25rem;
|
||||
display: grid;
|
||||
padding: .5rem 0;
|
||||
min-width: 9rem;
|
||||
|
||||
.menu-item {
|
||||
--td-button-medium-height: 32px;
|
||||
--td-button-medium-padding-horizontal: 10px;
|
||||
|
||||
gap: .25rem;
|
||||
width: 100%;
|
||||
font-weight: unset;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:global(html.theme-dark) {
|
||||
.nav-actions {
|
||||
:deep(.t-popover__content) {
|
||||
color: #e2e8f0;
|
||||
background: rgba(30, 41, 59, .98);
|
||||
}
|
||||
|
||||
.menu-item { color: #e2e8f0; }
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user