add modal component
This commit is contained in:
46
src/components/Modal.vue
Normal file
46
src/components/Modal.vue
Normal file
@@ -0,0 +1,46 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { onClickOutside } from '@vueuse/core'
|
||||
|
||||
const modalBox = ref(null)
|
||||
const show = ref(false)
|
||||
|
||||
const open = () => (show.value = true)
|
||||
const close = () => (show.value = false)
|
||||
|
||||
const slotProps = { open, close }
|
||||
|
||||
onClickOutside(modalBox, () => close())
|
||||
|
||||
const onEnter = (el: Element, done: () => void): void => {
|
||||
setTimeout(() => {
|
||||
el.classList.add('modal-open')
|
||||
done()
|
||||
})
|
||||
}
|
||||
|
||||
const onLeave = (el: Element, done: () => void): void => {
|
||||
el.classList.remove('modal-open')
|
||||
el.addEventListener('transitionend', () => done())
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<slot name="activator" v-bind="slotProps"></slot>
|
||||
<Teleport to="body">
|
||||
<Transition @enter="onEnter" @leave="onLeave">
|
||||
<div class="modal bg-neutral-800 bg-opacity-60" v-if="show">
|
||||
<div class="modal-box" ref="modalBox">
|
||||
<h3 class="text-lg font-bold" v-if="$slots.title"><slot name="title" /></h3>
|
||||
<p class="py-4">
|
||||
<slot />
|
||||
</p>
|
||||
<div class="modal-action">
|
||||
<slot name="actions" v-bind="slotProps">
|
||||
<button class="btn-sm btn" @click="close">Close</button>
|
||||
</slot>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import NoteEditor from '@/components/NoteEditor.vue'
|
||||
import Modal from '@/components/Modal.vue'
|
||||
import { formatDate } from '@/utils/helpers'
|
||||
import { notes, activeNote } from '@/composables/useNotes'
|
||||
import { notesRelations } from '@/composables/useNotes'
|
||||
@@ -32,9 +33,9 @@ const references = computed<Note[]>(() => {
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<div class="flex items-center mb-2">
|
||||
<div class="mb-2 flex items-center">
|
||||
<h1
|
||||
class="flex flex-1 items-center rounded-md text-3xl font-semibold hover:bg-gray-200 mr-2"
|
||||
class="mr-2 flex flex-1 items-center rounded-md text-3xl font-semibold hover:bg-gray-200"
|
||||
>
|
||||
<i
|
||||
class="fas fa-fw fa-home mr-2 text-base text-secondary opacity-40"
|
||||
@@ -47,12 +48,42 @@ const references = computed<Note[]>(() => {
|
||||
/>
|
||||
</h1>
|
||||
<div class="btn-group flex items-center">
|
||||
<button class="btn-sm btn">
|
||||
<i class="fas fa-fw fa-trash" />
|
||||
</button>
|
||||
<button class="btn-sm btn">
|
||||
<i class="fas fa-fw fa-sitemap" />
|
||||
</button>
|
||||
<Modal>
|
||||
<template #activator="{ open }">
|
||||
<button class="btn-sm btn" @click="open">
|
||||
<i class="fas fa-fw fa-trash" />
|
||||
</button>
|
||||
</template>
|
||||
<template #default>Are you sure you want to delete this?</template>
|
||||
<template #actions="{ close }">
|
||||
<button
|
||||
class="btn-primary btn-sm btn mr-1"
|
||||
@click="() => console.log('delete note')"
|
||||
>
|
||||
Delete note
|
||||
</button>
|
||||
<button class="btn-sm btn" @click="close">Close</button>
|
||||
</template>
|
||||
</Modal>
|
||||
<Modal>
|
||||
<template #activator="{ open }">
|
||||
<button class="btn-sm btn" @click="open">
|
||||
<i class="fas fa-fw fa-sitemap" />
|
||||
</button>
|
||||
</template>
|
||||
<template #default>
|
||||
Are you sure you want to set this note as root note?
|
||||
</template>
|
||||
<template #actions="{ close }">
|
||||
<button
|
||||
class="btn-primary btn-sm btn mr-1"
|
||||
@click="() => console.log('set root note')"
|
||||
>
|
||||
Set current note as root
|
||||
</button>
|
||||
<button class="btn-sm btn" @click="close">Close</button>
|
||||
</template>
|
||||
</Modal>
|
||||
</div>
|
||||
</div>
|
||||
<NoteEditor
|
||||
|
||||
Reference in New Issue
Block a user