mirror of https://github.com/Budibase/budibase.git
15 changed files with 227 additions and 102 deletions
@ -0,0 +1,15 @@ |
|||
<script> |
|||
import { confirmationStore } from "../store" |
|||
import { Modal, ModalContent } from "@budibase/bbui" |
|||
</script> |
|||
|
|||
{#if $confirmationStore.showConfirmation} |
|||
<Modal fixed on:cancel={confirmationStore.actions.cancel}> |
|||
<ModalContent |
|||
title={$confirmationStore.title} |
|||
onConfirm={confirmationStore.actions.confirm} |
|||
> |
|||
{$confirmationStore.text} |
|||
</ModalContent> |
|||
</Modal> |
|||
{/if} |
|||
@ -0,0 +1,39 @@ |
|||
import { writable, get } from "svelte/store" |
|||
|
|||
const initialState = { |
|||
showConfirmation: false, |
|||
title: null, |
|||
text: null, |
|||
callback: null, |
|||
} |
|||
|
|||
const createConfirmationStore = () => { |
|||
const store = writable(initialState) |
|||
|
|||
const showConfirmation = (title, text, callback) => { |
|||
store.set({ |
|||
showConfirmation: true, |
|||
title, |
|||
text, |
|||
callback, |
|||
}) |
|||
} |
|||
const confirm = async () => { |
|||
const state = get(store) |
|||
if (!state.showConfirmation || !state.callback) { |
|||
return |
|||
} |
|||
store.set(initialState) |
|||
await state.callback() |
|||
} |
|||
const cancel = () => { |
|||
store.set(initialState) |
|||
} |
|||
|
|||
return { |
|||
subscribe: store.subscribe, |
|||
actions: { showConfirmation, confirm, cancel }, |
|||
} |
|||
} |
|||
|
|||
export const confirmationStore = createConfirmationStore() |
|||
Loading…
Reference in new issue