A customizable Vue.js dialog component library with support for success, error, warning, and confirmation dialogs.
- Customizable dialog types: success, error, warning, and confirm.
- Supports both options API and composition API.
- Promise-based API for handling user responses.
- Customizable CSS class names for styling flexibility.
- Built with Vite for fast and modern development.
Install the plugin using npm:
npm install @draftscripts/vue
Or using yarn:
yarn add @draftscripts/vue
In your main application file (e.g., main.js or main.ts), register the plugin:
import { createApp } from 'vue';
import App from './App.vue';
import { DialogPlugin } from '@draftscripts/vue';
const app = createApp(App);
const options = {
// Custom options here
};
app.use(DialogPlugin, options);
app.mount('#app');
To open a dialog using the Options API:
export default {
methods: {
showDialog() {
this.$openDialog('Message', { type: 'success' });
},
showConfirmDialog() {
this.$openDialog('Message', { type: 'confirm' }).then((action) => {
if (action) {
console.log('Confirmed');
}
}).catch(() => {
console.log('Rejected');
});
}
}
};
To open a dialog using the Composition API:
import { inject } from 'vue';
export default {
setup() {
const openDialog = inject('openDialog');
const showDialog = () => {
openDialog('Message', { type: 'success' });
};
const showConfirmDialog = () => {
openDialog('Message', { type: 'confirm' }).then((action) => {
if (action) {
console.log('Confirmed');
}
}).catch(() => {
console.log('Rejected');
});
};
return {
showDialog,
showConfirmDialog
};
}
};