β¬ οΈ Back to Table of Contents
π useConfirmDialog¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 4 |
| π¦ Imports | 8 |
| β‘ Async/Await Patterns | 2 |
| π’ Vue Composition API | 1 |
| π Interfaces | 1 |
| π Type Aliases | 1 |
π Table of Contents¶
π οΈ File Location:¶
π packages/core/useConfirmDialog/index.ts
π¦ Imports¶
| Name | Source |
|---|---|
EventHook |
@vueuse/shared |
EventHookOn |
@vueuse/shared |
ComputedRef |
vue |
ShallowRef |
vue |
createEventHook |
@vueuse/shared |
noop |
@vueuse/shared |
computed |
vue |
shallowRef |
vue |
Async/Await Patterns¶
| Type | Function | Await Expressions | Promise Chains |
|---|---|---|---|
| promise-chain | useConfirmDialog |
none | new Promise(...) |
| promise-chain | reveal |
none | new Promise(...) |
Vue Composition API¶
| Name | Type | Reactive Variables | Composables |
|---|---|---|---|
computed |
computed | none | none |
Functions¶
useConfirmDialog(revealed: ShallowRef<boolean>): UseConfirmDialogReturn<RevealData, ConfirmData, CancelData>¶
Hooks for creating confirm dialogs. Useful for modal windows, popups and logins.
Parameters:
revealedany:booleanrefthat handles a modal window
See: https://vueuse.org/useConfirmDialog/
Tags: @__NO_SIDE_EFFECTS__
Raw JSDoc
Calls:
createEventHook (from @vueuse/shared)revealHook.triggerconfirmHook.trigger_resolvecancelHook.triggercomputed (from vue)
Code
export function useConfirmDialog<
RevealData = any,
ConfirmData = any,
CancelData = any,
>(
revealed: ShallowRef<boolean> = shallowRef(false),
): UseConfirmDialogReturn<RevealData, ConfirmData, CancelData> {
const confirmHook: EventHook = createEventHook<ConfirmData>()
const cancelHook: EventHook = createEventHook<CancelData>()
const revealHook: EventHook = createEventHook<RevealData>()
let _resolve: (arg0: UseConfirmDialogRevealResult<ConfirmData, CancelData>) => void = noop
const reveal = (data?: RevealData) => {
revealHook.trigger(data)
revealed.value = true
return new Promise<UseConfirmDialogRevealResult<ConfirmData, CancelData>>((resolve) => {
_resolve = resolve
})
}
const confirm = (data?: ConfirmData) => {
revealed.value = false
confirmHook.trigger(data)
_resolve({ data, isCanceled: false })
}
const cancel = (data?: CancelData) => {
revealed.value = false
cancelHook.trigger(data)
_resolve({ data, isCanceled: true })
}
return {
isRevealed: computed(() => revealed.value),
reveal,
confirm,
cancel,
onReveal: revealHook.on,
onConfirm: confirmHook.on,
onCancel: cancelHook.on,
}
}
Internal helpers¶
Declared inside another function in this file.
reveal(data: RevealData): Promise<UseConfirmDialogRevealResult<ConfirmData, CancelDat⦶
Parameters:
dataRevealData
Returns: Promise<UseConfirmDialogRevealResult<ConfirmData, CancelData>>
Calls:
revealHook.trigger
Code
confirm(data: ConfirmData): void¶
Parameters:
dataConfirmData
Returns: void
Calls:
confirmHook.trigger_resolve
Code
cancel(data: CancelData): void¶
Parameters:
dataCancelData
Returns: void
Calls:
cancelHook.trigger_resolve
Code
Interfaces¶
UseConfirmDialogReturn<RevealData, ConfirmData, CancelData>¶
Interface Code
export interface UseConfirmDialogReturn<RevealData, ConfirmData, CancelData> {
/**
* Revealing state
*/
isRevealed: ComputedRef<boolean>
/**
* Opens the dialog.
* Create promise and return it. Triggers `onReveal` hook.
*/
reveal: (data?: RevealData) => Promise<UseConfirmDialogRevealResult<ConfirmData, CancelData>>
/**
* Confirms and closes the dialog. Triggers a callback inside `onConfirm` hook.
* Resolves promise from `reveal()` with `data` and `isCanceled` ref with `false` value.
* Can accept any data and to pass it to `onConfirm` hook.
*/
confirm: (data?: ConfirmData) => void
/**
* Cancels and closes the dialog. Triggers a callback inside `onCancel` hook.
* Resolves promise from `reveal()` with `data` and `isCanceled` ref with `true` value.
* Can accept any data and to pass it to `onCancel` hook.
*/
cancel: (data?: CancelData) => void
/**
* Event Hook to be triggered right before dialog creating.
*/
onReveal: EventHookOn<RevealData>
/**
* Event Hook to be called on `confirm()`.
* Gets data object from `confirm` function.
*/
onConfirm: EventHookOn<ConfirmData>
/**
* Event Hook to be called on `cancel()`.
* Gets data object from `cancel` function.
*/
onCancel: EventHookOn<CancelData>
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
isRevealed |
ComputedRef<boolean> |
β | not shown |
reveal |
(data?: RevealData) => Promise<UseConfirmDialogRevealResult<ConfirmData, Canc... |
β | not shown |
confirm |
(data?: ConfirmData) => void |
β | not shown |
cancel |
(data?: CancelData) => void |
β | not shown |
onReveal |
EventHookOn<RevealData> |
β | not shown |
onConfirm |
EventHookOn<ConfirmData> |
β | not shown |
onCancel |
EventHookOn<CancelData> |
β | not shown |
Type Aliases¶
UseConfirmDialogRevealResult<C, D>¶
type UseConfirmDialogRevealResult<C, D> = {
data?: C
isCanceled: false
} | {
data?: D
isCanceled: true
};
Generated by Syntax Scribe