UIDrawerContent
UIDrawerContent
A component that provides a structured layout for content within a UIDrawer, with support for header, body, and footer sections.
<template> <UIDrawer v-model:show="showDrawer"> <UIDrawerContent :title="'Edit Profile'" :loading="loading" :showDivider="true" @close="handleClose" > <template #header> <div class="flex items-center justify-between"> <h2 class="text-lg font-medium"> Edit Profile </h2> <UIButton type="text" @click="handleClose" > <XIcon class="w-5 h-5" /> </UIButton> </div> </template>
<template #default> <div class="p-6"> <UIForm :model="formData" :rules="formRules" > <UIFormItem label="Name"> <UIInput v-model="formData.name" /> </UIFormItem> <UIFormItem label="Email"> <UIInput v-model="formData.email" /> </UIFormItem> </UIForm> </div> </template>
<template #footer> <div class="flex justify-end space-x-4 px-6 py-4"> <UIButton type="default" @click="handleClose" > Cancel </UIButton> <UIButton type="primary" :loading="saving" @click="handleSave" > Save Changes </UIButton> </div> </template> </UIDrawerContent> </UIDrawer></template>
<script setup lang="ts">const showDrawer = ref(false)const loading = ref(false)const saving = ref(false)const formData = ref({ name: '', email: ''})
const handleClose = () => { showDrawer.value = false}
const handleSave = async () => { saving.value = true try { // Save changes showDrawer.value = false } finally { saving.value = false }}</script>Props
title(string): Drawer titleloading(boolean): Show loading stateshowDivider(boolean): Show dividers between sectionsbodyStyle(object): Custom body section stylesheaderStyle(object): Custom header section stylesfooterStyle(object): Custom footer section stylesscrollable(boolean): Enable body scrollingcloseOnClickOutside(boolean): Close when clicking outsidecloseOnEsc(boolean): Close on Escape keymaskClosable(boolean): Close when clicking mask
Events
close: Emitted when drawer is closedafterClose: Emitted after close animationafterOpen: Emitted after open animation
Slots
header: Custom header contentdefault: Main drawer contentfooter: Custom footer contentclose: Custom close button contentloading: Custom loading state
Usage Examples
- Basic Drawer Content:
<template> <UIDrawerContent title="Details"> <div class="p-6"> Content goes here </div> </UIDrawerContent></template>- Form in Drawer:
<template> <UIDrawerContent title="Create Item" :loading="loading" > <UIForm class="p-6"> <UIFormItem label="Name"> <UIInput v-model="name" /> </UIFormItem> </UIForm>
<template #footer> <div class="flex justify-end space-x-4"> <UIButton @click="cancel"> Cancel </UIButton> <UIButton type="primary" @click="save" > Save </UIButton> </div> </template> </UIDrawerContent></template>- Custom Header:
<template> <UIDrawerContent> <template #header> <div class="flex items-center justify-between p-4"> <div class="flex items-center space-x-4"> <UIAvatar :src="user.avatar" /> <div> <h3 class="font-medium"> {{ user.name }} </h3> <p class="text-sm text-gray-500"> {{ user.email }} </p> </div> </div> <UIButton type="text" @click="close" > <XIcon class="w-5 h-5" /> </UIButton> </div> </template> </UIDrawerContent></template>- Loading State:
<template> <UIDrawerContent title="Loading Data" :loading="true" > <template #loading> <div class="flex items-center justify-center p-8"> <UISpinner size="lg" /> </div> </template> </UIDrawerContent></template>Best Practices
-
Layout:
- Use consistent padding
- Maintain clear hierarchy
- Group related actions
- Consider content scrolling
-
Header:
- Keep titles concise
- Include close button
- Show relevant metadata
- Use appropriate icons
-
Footer:
- Align actions consistently
- Order buttons logically
- Show loading states
- Handle long labels
-
Content:
- Structure content clearly
- Use appropriate spacing
- Handle overflow gracefully
- Show loading states
-
Accessibility:
- Use semantic markup
- Support keyboard navigation
- Manage focus properly
- Provide ARIA labels