﻿# Drawer {#drawer}

An Element Plus drawer with asynchronous confirmation, cancellation, custom footer and vertical tabs. Supports Chalk/OEM themes.

<span id="interactive"></span>

## Basic usage {#basic}

### Basic usage
```vue
<script setup>
import { ref, onBeforeUnmount } from 'vue'
const open = ref(false)
const timers = new Set()
function confirm(done) {
  const timer = setTimeout(() => { timers.delete(timer); done() }, 1000)
  timers.add(timer)
}
onBeforeUnmount(() => timers.forEach(clearTimeout))
</script>

<template>
  <nf-button type="primary" style="margin-left: 16px" @click="open = true">Click to open</nf-button>
  <nf-drawer v-model:visible="open" title="My title" cancel-button-text="Cancel" confirm-button-text="Confirm" @confirm="confirm">
    <div style="padding: 20px">My custom content!!</div>
  </nf-drawer>
</template>
```

## Custom title {#header}

### Custom title
```vue
<script setup>
import { ref, onBeforeUnmount } from 'vue'
import { Eleme } from '@element-plus/icons-vue'
const open = ref(false)
const timers = new Set()
function confirm(done) {
  const timer = setTimeout(() => { timers.delete(timer); done() }, 1000)
  timers.add(timer)
}
onBeforeUnmount(() => timers.forEach(clearTimeout))
</script>

<template>
  <nf-button type="primary" style="margin-left: 16px" @click="open = true">Click to open</nf-button>
  <nf-drawer v-model:visible="open" @confirm="confirm">
    <template #title><span style="display: inline-flex; align-items: center; gap: 4px"><el-icon><Eleme /></el-icon>My custom title</span></template>
    <div style="padding: 20px">My custom content!!</div>
  </nf-drawer>
</template>
```

## Custom footer {#footer}

### Custom footer
```vue
<script setup>
import { ref } from 'vue'
const open = ref(false)
</script>

<template>
  <nf-button type="primary" style="margin-left: 16px" @click="open = true">Click to open</nf-button>
  <nf-drawer v-model:visible="open" title="My title">
    <div style="padding: 20px">My custom content!!</div>
    <template #footer><div style="padding: 20px">My custom footer</div></template>
  </nf-drawer>
</template>
```

## Custom tabs {#tabs}

### Custom tabs
```vue
<script setup>
import { ref, onBeforeUnmount } from 'vue'
const open = ref(false)
const timers = new Set()
function confirm(done) {
  const timer = setTimeout(() => { timers.delete(timer); done() }, 1000)
  timers.add(timer)
}
onBeforeUnmount(() => timers.forEach(clearTimeout))
const current = ref("Advanced settings")
const tabs = [
  { name: "Basic settings", slot: 'tab-1' },
  { name: "Advanced settings", slot: 'tab-2' },
  { name: "Special settings", slot: 'tab-3' },
]
</script>

<template>
  <nf-button type="primary" style="margin-left: 16px" @click="open = true">Click to open</nf-button>
  <nf-drawer v-model:visible="open" v-model:current-tab="current" title="My title" :tabs="tabs" @confirm="confirm">
    <template #tab-1><div style="padding: 20px">My custom basic settings</div></template>
    <template #tab-2><div style="padding: 20px">My custom advanced settings</div></template>
    <template #tab-3><div style="padding: 20px">My custom special settings</div></template>
  </nf-drawer>
</template>
```

## Hide footer buttons {#hide-footer}

### Hide footer buttons
```vue
<script setup>
import { ref, onBeforeUnmount } from 'vue'
const open = ref(false)
const noFooter = ref(false)
const timers = new Set()
function confirm(done) {
  const timer = setTimeout(() => { timers.delete(timer); done() }, 1000)
  timers.add(timer)
}
onBeforeUnmount(() => timers.forEach(clearTimeout))
</script>

<template>
  <nf-button type="primary" style="margin-left: 16px" @click="open = true">Hide confirm button</nf-button>
  <nf-button type="primary" style="margin-left: 16px" @click="noFooter = true">Hide both buttons (hide footer)</nf-button>
  <nf-drawer v-model:visible="open" title="My title" cancel-button-text="Close" :show-confirm-button="false" @confirm="confirm">
    <div style="padding: 20px">Hide confirm button！！</div>
  </nf-drawer>
  <nf-drawer v-model:visible="noFooter" title="My title" :show-confirm-button="false" :show-cancel-button="false" @confirm="confirm">
    <div style="padding: 20px">Hide both buttons (hide footer)！！</div>
  </nf-drawer>
</template>
```

## Installation {#installation}

```ts
import NfDrawer from '@94ai-plus/nf-drawer'
import 'element-plus/dist/index.css'
import '@94ai-plus/nf-theme-chalk/nf-drawer.css'
app.use(NfDrawer)
```

## Props {#props}

| Attribute | Description | Type | Accepted values | Default |
| --- | --- | --- | --- | --- |
| showConfirmButton | Whether to show the confirm button | boolean | — | true |
| showCancelButton | Whether to show the cancel button | boolean | — | true |
| cancelButtonText | Cancel button text | string | — | Current locale |
| confirmButtonText | Confirm button text | string | — | Current locale |
| currentTab | Current tab name; supports v-model:current-tab; invalid values fall back to the first tab | string | — | undefined |
| tabs | Tab data: name is the tab name, slot names its content slot | ITabItem[] / DrawerTabItem[] | — | undefined |
| modelValue | Visibility with v-model; takes precedence over visible | boolean | — | false |
| visible | Visibility with v-model:visible | boolean | — | false |
| title | Title | string | — | `''` |
| customClass | Custom class name | string | — | `''` |
| wrapperClosable | Whether clicking the backdrop closes Drawer | boolean | — | false |
| closeOnClickModal | Backdrop closing; when explicit, overrides wrapperClosable | boolean | — | wrapperClosable |
| closeOnPressEscape | Whether Escape closes Drawer | boolean | — | false |
| direction | Drawer opening direction | string | rtl / ltr / ttb / btt | rtl |
| size | Drawer size: width for horizontal, height for vertical | string / number | — | 30% |
| beforeClose | Before-close callback; done() continues closing; successful confirmation bypasses it | `(done: (cancel?: boolean) => void) => void` | — | — |
| withHeader / showClose / appendTo / appendToBody / destroyOnClose / resizable / modal / lockScroll / openDelay / closeDelay / zIndex / headerClass / bodyClass / footerClass | Forwards the same Element Plus Drawer properties, defaults and behavior | Element Plus Drawer | — | [Element Plus Drawer](https://element-plus.org/en-US/component/drawer.html#attributes) |

## Events {#events}

| Event | Description | Payload |
| --- | --- | --- |
| cancel | Drawer cancel button callback | event: MouseEvent |
| confirm | Drawer confirm callback; done() closes, error() only stops loading | done: () => void, error: () => void |
| changeTab | Tab change callback, receiving the current tab name | name: string |
| update:modelValue | Emitted when visibility changes | value: boolean |
| update:visible | Emitted when visibility changes | value: boolean |
| update:currentTab | Synchronizes the active tab; undefined for an empty list | value: string / undefined |
| open / opened / close / closed / openAutoFocus / closeAutoFocus | Forwards Element Plus Drawer opening, closing and autofocus events | — |
| resize-start / resize / resize-end | Emitted when resizing starts, moves and ends | event: MouseEvent, size: number |

## Slots {#slots}

| Slot | Description | Payload |
| --- | --- | --- |
| default | Drawer content | — |
| title | Drawer title content | close, titleId, titleClass |
| header | Drawer header content; takes precedence over the title slot | close, titleId, titleClass |
| footer | Drawer footer content; hidden when both buttons are hidden | — |
| tabs[].slot | Tab content named by tabs[].slot | — |

## Types {#types}

```ts
import type { DrawerProps, DrawerTabItem, ITabItem, DrawerInstance } from '@94ai-plus/nf-drawer'
// DrawerTabItem: { name: string; slot: string }; ITabItem = DrawerTabItem
// DrawerInstance: closeDrawer(), handleClose(); both run beforeClose
```

## Migration {#migration}

Replace Vue 2 :visible.sync with v-model:visible. wrapperClosable maps to closeOnClickModal (the latter wins); customClass is merged onto the panel. The legacy title slot maps to header; otherwise the title prop renders normally. Hiding both buttons hides the entire footer, including custom content. Confirmation callbacks are single-use and invalidated on close/reopen/unmount. SSR renders a placeholder until mounted.
