-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from radek00/modal
Modal
- Loading branch information
Showing
4 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<template> | ||
<svg | ||
class="w-3 h-3" | ||
aria-hidden="true" | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 14 14" | ||
> | ||
<path | ||
stroke="currentColor" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" | ||
/> | ||
</svg> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script setup lang="ts"> | ||
import CloseIcon from "@/assets/icons/CloseIcon.vue"; | ||
defineEmits(["closeClick"]); | ||
</script> | ||
|
||
<template> | ||
<!-- Main modal --> | ||
<div | ||
tabindex="-1" | ||
aria-hidden="true" | ||
class="absolute h-screen w-screen flex items-center justify-center bg-gray-900/50" | ||
> | ||
<div class="relative w-full max-w-2xl max-h-full"> | ||
<!-- Modal content --> | ||
<div class="relative rounded-lg shadow bg-gray-700"> | ||
<!-- Modal header --> | ||
<div | ||
class="flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600" | ||
> | ||
<h3 class="text-xl font-semibold text-white"> | ||
<slot name="header"></slot> | ||
</h3> | ||
<button | ||
@click="$emit('closeClick')" | ||
type="button" | ||
class="text-gray-400 bg-transparent rounded-lg text-sm w-8 h-8 ml-auto inline-flex justify-center items-center hover:bg-gray-600 hover:text-white" | ||
> | ||
<CloseIcon></CloseIcon> | ||
<span class="sr-only">Close modal</span> | ||
</button> | ||
</div> | ||
<!-- Modal body --> | ||
|
||
<div | ||
class="p-6 space-y-6 overflow-x-hidden overflow-y-auto max-h-[200px]" | ||
> | ||
<p class="text-base leading-relaxed text-gray-400"> | ||
<slot name="body"></slot> | ||
</p> | ||
</div> | ||
|
||
<!-- Modal footer --> | ||
<div | ||
class="flex items-center p-4 space-x-2 border-t rounded-b border-gray-600" | ||
> | ||
<slot name="footer"></slot> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
56 changes: 56 additions & 0 deletions
56
SecureSend/ClientApp/src/utils/composables/useConfirmDialog.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { type Ref, ref, computed, type ComputedRef } from "vue"; | ||
|
||
export type UseConfirmDialogRevealResult<C, D> = | ||
| { | ||
data?: C; | ||
isCanceled: false; | ||
} | ||
| { | ||
data?: D; | ||
isCanceled: true; | ||
}; | ||
|
||
export interface UseConfirmDialogReturn<RevealData, ConfirmData, CancelData> { | ||
isRevealed: ComputedRef<boolean>; | ||
reveal: ( | ||
data?: RevealData | ||
) => Promise<UseConfirmDialogRevealResult<ConfirmData, CancelData>>; | ||
confirm: (data?: ConfirmData) => void; | ||
cancel: (data?: CancelData) => void; | ||
} | ||
|
||
export function useConfirmDialog<ConfirmData, CancelData>( | ||
revealed: Ref<boolean> = ref(false) | ||
) { | ||
let _resolve: ( | ||
arg0: UseConfirmDialogRevealResult<ConfirmData, CancelData> | ||
) => void; | ||
|
||
const reveal = () => { | ||
revealed.value = true; | ||
|
||
return new Promise<UseConfirmDialogRevealResult<ConfirmData, CancelData>>( | ||
(resolve) => { | ||
_resolve = resolve; | ||
} | ||
); | ||
}; | ||
|
||
const confirm = (data: ConfirmData) => { | ||
revealed.value = false; | ||
|
||
_resolve({ data, isCanceled: false }); | ||
}; | ||
|
||
const cancel = (data?: CancelData) => { | ||
revealed.value = false; | ||
_resolve({ data, isCanceled: true }); | ||
}; | ||
|
||
return { | ||
isRevealed: computed(() => revealed.value), | ||
reveal, | ||
confirm, | ||
cancel, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters