Files
heroui-vue/apps/docs/demos/drawer-controlled.vue
T

129 lines
3.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { ref } from "vue";
import {
Button,
DrawerBackdrop,
DrawerBody,
DrawerClose,
DrawerCloseTrigger,
DrawerContent,
DrawerDialog,
DrawerFooter,
DrawerHeader,
DrawerHeading,
useOverlayState,
} from "@heroui-vue/components";
const isOpen = ref(false);
const state = useOverlayState();
</script>
<template>
<div class="flex max-w-md flex-col gap-8">
<div class="flex flex-col gap-3">
<h3 class="text-lg font-semibold text-foreground">配合 ref</h3>
<p class="text-sm leading-relaxed text-pretty text-muted">
使用 Vue 的
<code class="text-foreground">ref</code>
管理抽屉开关。
</p>
<div
class="flex flex-col items-start gap-3 rounded-2xl bg-surface p-4 shadow-sm"
>
<p class="text-xs text-muted">
状态:
<span class="font-mono font-medium text-foreground">
{{ isOpen ? "打开" : "关闭" }}
</span>
</p>
<div class="flex gap-2">
<Button size="sm" variant="secondary" @click="isOpen = true">
打开抽屉
</Button>
<Button size="sm" variant="tertiary" @click="isOpen = !isOpen">
切换
</Button>
</div>
</div>
<DrawerBackdrop v-model:is-open="isOpen">
<DrawerContent placement="right">
<DrawerDialog>
<DrawerCloseTrigger />
<DrawerHeader>
<DrawerHeading>由 ref 控制</DrawerHeading>
</DrawerHeader>
<DrawerBody>
<p>
该抽屉由 Vue 的
<code>ref</code>
控制。
</p>
</DrawerBody>
<DrawerFooter>
<DrawerClose as-child>
<Button variant="secondary">关闭</Button>
</DrawerClose>
</DrawerFooter>
</DrawerDialog>
</DrawerContent>
</DrawerBackdrop>
</div>
<div class="flex flex-col gap-3">
<h3 class="text-lg font-semibold text-foreground">
配合 useOverlayState()
</h3>
<p class="text-sm leading-relaxed text-pretty text-muted">
使用
<code class="text-foreground">useOverlayState</code>
获得
<code>open()</code>
、
<code>close()</code>
、
<code>toggle()</code>
等方法。
</p>
<div
class="flex flex-col items-start gap-3 rounded-2xl bg-surface p-4 shadow-sm"
>
<p class="text-xs text-muted">
状态:
<span class="font-mono font-medium text-foreground">
{{ state.isOpen.value ? "打开" : "关闭" }}
</span>
</p>
<div class="flex gap-2">
<Button size="sm" variant="secondary" @click="state.open()">
打开抽屉
</Button>
<Button size="sm" variant="tertiary" @click="state.toggle()">
切换
</Button>
</div>
</div>
<DrawerBackdrop :state="state">
<DrawerContent placement="right">
<DrawerDialog>
<DrawerCloseTrigger />
<DrawerHeader>
<DrawerHeading>由 useOverlayState() 控制</DrawerHeading>
</DrawerHeader>
<DrawerBody>
<p>
<code>useOverlayState</code>
为常见操作提供专用方法。
</p>
</DrawerBody>
<DrawerFooter>
<DrawerClose as-child>
<Button variant="secondary">关闭</Button>
</DrawerClose>
</DrawerFooter>
</DrawerDialog>
</DrawerContent>
</DrawerBackdrop>
</div>
</div>
</template>