-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Saqib Ansari <[email protected]>
- Loading branch information
1 parent
38728b8
commit 4d6868a
Showing
5 changed files
with
153 additions
and
0 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,62 @@ | ||
# Confirm Dialog | ||
|
||
This component is to confirm an action with the user. | ||
|
||
## Usage | ||
|
||
Call the `confirmDialog` function with options to show a confirmation dialog. | ||
You need to make sure you include the `Dialogs` component in your root component | ||
([`App.vue`](#app-vue)). | ||
|
||
<Story> | ||
<Button | ||
@click=" | ||
confirmDialog({ | ||
title: 'Are you sure?', | ||
message: 'This will permanently delete the file. Are you sure you want to proceed?', | ||
onConfirm: ({ hideDialog }) => { | ||
// deleteFile() | ||
// hideDialog() // closes dialog | ||
}, | ||
}) | ||
" | ||
> | ||
Delete File | ||
</Button> | ||
</Story> | ||
|
||
```vue | ||
<template> | ||
<Button | ||
@click=" | ||
confirmDialog({ | ||
title: 'Are you sure?', | ||
message: | ||
'This will permanently delete the file. Are you sure you want to proceed?', | ||
onConfirm: ({ hideDialog }) => { | ||
// deleteFile() | ||
// hideDialog() // closes dialog | ||
}, | ||
}) | ||
" | ||
> | ||
Delete File | ||
</Button> | ||
</template> | ||
<script setup> | ||
import { confirmDialog, Button } from 'frappe-ui' | ||
</script> | ||
``` | ||
|
||
### App.vue | ||
|
||
```vue | ||
<template> | ||
<!-- your markup --> | ||
<Dialogs /> | ||
</template> | ||
<script setup> | ||
import { Dialogs } from 'frappe-ui' | ||
</script> | ||
``` |
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 @@ | ||
<template> | ||
<Dialog v-model="showDialog" :options="{ title }"> | ||
<template #body-content> | ||
<div class="space-y-4"> | ||
<p class="text-p-base text-gray-800" v-if="message" v-html="message" /> | ||
</div> | ||
</template> | ||
<template #actions> | ||
<Button class="w-full" v-bind="primaryActionProps" /> | ||
</template> | ||
</Dialog> | ||
</template> | ||
<script> | ||
import Dialog from './Dialog.vue' | ||
export default { | ||
name: 'ConfirmDialog', | ||
props: ['title', 'message', 'fields', 'onConfirm'], | ||
This comment has been minimized.
Sorry, something went wrong. |
||
expose: ['show', 'hide'], | ||
components: { | ||
Dialog, | ||
}, | ||
data() { | ||
return { | ||
showDialog: true, | ||
isLoading: false, | ||
} | ||
}, | ||
methods: { | ||
handleConfirmation() { | ||
try { | ||
this.onConfirm?.({ | ||
hideDialog: this.hide, | ||
}) | ||
} finally { | ||
this.isLoading = false | ||
} | ||
}, | ||
show() { | ||
this.showDialog = true | ||
}, | ||
hide() { | ||
this.showDialog = false | ||
}, | ||
}, | ||
computed: { | ||
primaryActionProps() { | ||
return { | ||
label: 'Confirm', | ||
variant: 'solid', | ||
loading: this.isLoading, | ||
onClick: this.handleConfirmation, | ||
} | ||
}, | ||
}, | ||
} | ||
</script> |
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,8 @@ | ||
<template> | ||
<div> | ||
<component v-for="dialog in dialogs" :is="dialog"></component> | ||
</div> | ||
</template> | ||
<script setup> | ||
import { dialogs } from '../utils/confirmDialog.js' | ||
</script> |
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
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,25 @@ | ||
import ConfirmDialog from '../components/ConfirmDialog.vue' | ||
import { h, ref } from 'vue' | ||
|
||
export function confirmDialog({ | ||
title = 'Untitled', | ||
message = '', | ||
fields = [], | ||
onConfirm, | ||
}) { | ||
renderDialog( | ||
h(ConfirmDialog, { | ||
title, | ||
message, | ||
fields, | ||
onConfirm, | ||
}) | ||
) | ||
} | ||
|
||
export const dialogs = ref([]) | ||
|
||
export function renderDialog(component) { | ||
component.id = dialogs.length | ||
dialogs.value.push(component) | ||
} |
fields
does nothing here. Why is it added?