-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
123 additions
and
16 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
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
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,26 @@ | ||
<template> | ||
<div class="container"> | ||
<div class="row mb-3"> | ||
<div class="col"> | ||
<button type="button" class="btn btn-primary" @click="$modal.show('modal1')">Open named modal 1</button> | ||
<button type="button" class="btn btn-primary ml-2" @click="$modal.show('modal2')">Open named modal 2</button> | ||
</div> | ||
</div> | ||
|
||
<Modal name="modal1" title="My first modal"> | ||
<p>Modal 1 content goes here...</p> | ||
</Modal> | ||
|
||
<Modal name="modal2" title="My second modal"> | ||
<p>Modal 2 content goes here...</p> | ||
</Modal> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data: function () { | ||
return {} | ||
} | ||
} | ||
</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,7 @@ | ||
import Modal from './Modal.vue' | ||
import { modalPlugin } from './modalPlugin' | ||
import { useModal } from './useModal' | ||
|
||
export default Modal | ||
|
||
export { modalPlugin, useModal } |
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,7 @@ | ||
import { useModal } from './useModal' | ||
|
||
export const modalPlugin = { | ||
install(app) { | ||
app.config.globalProperties.$modal = useModal() | ||
} | ||
} |
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,23 @@ | ||
import { reactive } from 'vue' | ||
|
||
const state = reactive({ | ||
modals: {} | ||
}) | ||
|
||
export const useModal = () => { | ||
const show = (name) => { | ||
state.modals[name] = true | ||
} | ||
|
||
const hide = (name) => { | ||
delete state.modals[name] | ||
} | ||
|
||
const hideAll = () => { | ||
Object.keys(state.modals).forEach((modalName) => { | ||
hide(modalName) | ||
}) | ||
} | ||
|
||
return { state, show, hide, hideAll } | ||
} |
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