feat: drawer close icon placement (#5269)

This commit is contained in:
Netfan 2024-12-30 23:30:53 +08:00 committed by GitHub
parent 27ba45aa75
commit 376aad5d26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 6 deletions

View File

@ -84,6 +84,7 @@ const [Drawer, drawerApi] = useVbenDrawer({
| isOpen | 弹窗打开状态 | `boolean` | `false` |
| loading | 弹窗加载状态 | `boolean` | `false` |
| closable | 显示关闭按钮 | `boolean` | `true` |
| closeIconPlacement | 关闭按钮位置 | `'left'\|'right'` | `right` |
| modal | 显示遮罩 | `boolean` | `true` |
| header | 显示header | `boolean` | `true` |
| footer | 显示footer | `boolean\|slot` | `true` |
@ -129,6 +130,8 @@ const [Drawer, drawerApi] = useVbenDrawer({
| default | 默认插槽 - 弹窗内容 |
| prepend-footer | 取消按钮左侧 |
| append-footer | 取消按钮右侧 |
| close-icon | 关闭按钮图标 |
| extra | 额外内容(标题右侧) |
### modalApi

View File

@ -6,6 +6,8 @@ import type { Component, Ref } from 'vue';
export type DrawerPlacement = 'bottom' | 'left' | 'right' | 'top';
export type CloseIconPlacement = 'left' | 'right';
export interface DrawerProps {
/**
*
@ -18,10 +20,14 @@ export interface DrawerProps {
cancelText?: string;
class?: ClassType;
/**
*
*
* @default true
*/
closable?: boolean;
/**
*
*/
closeIconPlacement?: CloseIconPlacement;
/**
*
* @default true

View File

@ -10,6 +10,7 @@ import {
} from '@vben-core/composables';
import { X } from '@vben-core/icons';
import {
Separator,
Sheet,
SheetClose,
SheetContent,
@ -33,6 +34,7 @@ interface Props extends DrawerProps {
const props = withDefaults(defineProps<Props>(), {
appendToMain: false,
closeIconPlacement: 'right',
drawerApi: undefined,
zIndex: 1000,
});
@ -155,11 +157,29 @@ const getAppendTo = computed(() => {
headerClass,
{
'px-4 py-3': closable,
'pl-2': closable && closeIconPlacement === 'left',
},
)
"
>
<div>
<div class="flex items-center">
<SheetClose
v-if="closable && closeIconPlacement === 'left'"
as-child
class="data-[state=open]:bg-secondary ml-[2px] cursor-pointer rounded-full opacity-80 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none"
>
<slot name="close-icon">
<VbenIconButton>
<X class="size-4" />
</VbenIconButton>
</slot>
</SheetClose>
<Separator
v-if="closable && closeIconPlacement === 'left'"
class="ml-1 mr-2 h-8"
decorative
orientation="vertical"
/>
<SheetTitle v-if="title" class="text-left">
<slot name="title">
{{ title }}
@ -184,13 +204,15 @@ const getAppendTo = computed(() => {
<div class="flex-center">
<slot name="extra"></slot>
<SheetClose
v-if="closable"
v-if="closable && closeIconPlacement === 'right'"
as-child
class="data-[state=open]:bg-secondary ml-[2px] cursor-pointer rounded-full opacity-80 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none"
>
<VbenIconButton>
<X class="size-4" />
</VbenIconButton>
<slot name="close-icon">
<VbenIconButton>
<X class="size-4" />
</VbenIconButton>
</slot>
</SheetClose>
</div>
</SheetHeader>