Git Product home page Git Product logo

vuetify3-dialog's Introduction

Vuetify 3 Dialog Javascript Typescript Vue.js

Lite Vue plugin working with Vuetify, allowing you to show dialogs or snackbars programatically.

Inspired by vuetify-dialog (@yariksav)

Summary

Install it

First, run npm install vuetify3-dialog.
⚠️You must have Vuetify installed on your project. If you don't have installed yet, please follow this link : Install Vuetify

Then, install this plugin in your app entry point (main.js or main.ts) like following :

//main.js

import { createApp } from 'vue'
import App from './App.vue'
import vuetifyInstance from './plugins/vuetify' //Or wherever you have your vuetify instance
import {Vuetify3Dialog} from 'vuetify3-dialog'

const app = createApp(App)
app.use(Vuetify3Dialog, {
  vuetify: vuetifyInstance, //You must pass your vuetify instance as an option
  defaults: {
    //You can pass default options for dialogs, dialog's card, snackbars or bottom-sheets here
  }
})
app.mount('#app')

Usage

You can now use the plugin in your components. There is two main variable available in all your project : $dialog and $notify. Each of them have methods to create full personalized dialogs or snackbars, and other ones to create simple dialogs or snackbars with a message and a title, by precizing level of severity. Let's see how to use them.

Dialogs

You can create a fully personalized dialog with the following method :

this.$dialog.create({
  title: "My title",
  text: "My dialog message",
  buttons: [
    { title: 'My first button', key: 'button1', /* any v-btn api option */ },
    ...
  ],
  cardOptions: {
    //any v-card api options
  },
  dialogOptions: {
    //any v-dialog api options
  }
}).then((anwser) => {
  //Do something with the anwser corresponding to the key of the clicked button
})


NEW (V1.4.0)

You can pass a custom component to render inside the dialog, with it props binded! Here's how to do it :

this.$dialog.create({
  ..., //other options
  customComponent: {
    component: MyCustomComponent,
    props: { myComponentProp: 'Hello world!' }
  },
}).then(() => {
})

Warning

⚠ If you declare a persistent dialog option, take care that your component emit a closeDialog event when you want to close it.



this.$dialog also have a confirm method, which is a shortcut for the previous method with only two buttons : "Yes" and "No".

this.$dialog.confirm({title: "My title", text: "My dialog message", cancelText: "No", confirmationText: "Yes", cancelButtonOptions: ..., confirmationButtonOptions: ...})
.then((anwser) => {
  //Do something with the boolean anwser
})

You can also create a simple dialog with a message and a title, by precizing level of severity :

this.$dialog.info({ 
  title: "My title",
  text: "My dialog message",
  cardOptions: ..., 
  buttonOptions: ...
}).then(() => {
  //Do something when the user close the dialog
})

There is 4 levels of severity : info, success, warning and error.

Usefull links:

Snackbars

You can create a fully personalized snackbar with the following method :

//message, timeout, level, variant, rounded, position
this.$notify.create({
  text: "My snackbar message",
  level: 'success',
  location: 'top right',
  notifyOptions: {
    //any v-snackbar api options
  }
})
.then(() => {
  //Do something with the anwser corresponding to the key of the clicked button
})

You can also create a simple snackbar with a message and a title, by precizing level of severity :

this.$notify.info(
  "My snackbar message",
  { variant: 'outlined' } // any v-snackbar api options
).then(() => {
  //Do something when the user close the snackbar
})

There is 4 levels of severity : info, success, warning and error.

Usefull links:

Bottom sheets

Warning

⚠ This feature requires Vuetify 3.4.0 or higher

You can create a fully personalized bottom sheet with a contained list or a card dialog. To stay consistent, these two features cannot be used at same time.
Here is an example with a list :

this.$bottomSheet.create({
  title: "My title",
  text: "My bottom sheet message",
  bottomSheetOptions: {
    // any v-bottom-sheet api options
  },
  items: [
    { title: "Item 1", value: "item1", ... /* any v-list-item api option */ },
    { title: "Item 2", value: "item2" },
    { title: "Item 3", value: "item3" }
  ]
}).then((anwser) => {
  //Do something with the anwser corresponding to the value of the clicked item
})

Here is an example with a card :

this.$bottomSheet.create({
  bottomSheetOptions: {
    // any v-bottom-sheet api options
  },
  dialogOptions: {
    //same arguments as $dialog.create()
    title: "My bottom-sheet card dialog",
    text: "Hello world!",
    buttons: [
      { title: 'My first button', key: 'button1', /* any v-btn api option */ },
      ...
    ]
  }
}).then((anwser) => {
  //Do something with the anwser corresponding to the key of the clicked button
})

SFC compatibility

If you want to use this plugin in an SFC component, some methods are available. Working principe is the same as previous methods, and arguments are the same.

<script setup>
import { createDialog, warnDialog, confirmDialog } from 'vuetify3-dialog'
import { createNotification, notifySuccess } from 'vuetify3-dialog'
import { createBottomSheet } from 'vuetify3-dialog'

if(true){
  createDialog({ title: "My title", text: "My dialog message" })
  .then((anwser) => {
    //Do something with the anwser corresponding to the key of the clicked button
  })

  notifySuccess("My snackbar message").then(() => {})

  createBottomSheet({ title: "My bottomsheet title", text: "My bottomsheet message" })
  .then(() => {})
}
</script>

Developers

If you want to contribute to this project, you can clone it and run npm install to install dependencies.

Then, you need to test your changes. A demo project is located at cypress/test-server of this repository. You can launch it with npm run test-server.
If you have the following error : [vite] Internal server error: Failed to resolve entry for package "vuetify3-dialog". The package may have incorrect main/module/exports specified in its package.json., make sure you have run npm run build before to build the plugin and make it available for the demo project.

Finally, when you will have finish your changes, make sure all tests are passing with npm run test, thanks in advance !

vuetify3-dialog's People

Contributors

quantumstudioofficial avatar shaxine avatar thomasleconte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vuetify3-dialog's Issues

Vuetify 3.5.17 breaks Snackbar/notify

It seems that Vuetify 3.5.17 added (VSnackbar): position based on app layout: vuetifyjs/vuetify@cbb945d which breaks the mount of the snakbar component.

[Vue warn]: injection "Symbol(vuetify:layout)" not found. 
  at <VSnackbar class="vuetify3-dialog-snackbar" timeout=3000 location="top right"  ... > 
  at <Snackbar text="Hello world!" level=undefined location="top right"  ... > [runtime-core.esm-bundler.js:47:12](http://localhost:3000/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js)

[Vue warn]: Unhandled error during execution of setup function 
  at <VSnackbar class="vuetify3-dialog-snackbar" timeout=3000 location="top right"  ... > 
  at <Snackbar text="Hello world!" level=undefined location="top right"  ... > [runtime-core.esm-bundler.js:47:12](http://localhost:3000/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js)

Uncaught (in promise) Error: [Vuetify] Could not find injected layout
    useLayout layout.ts:92
    setup VSnackbar.tsx:99
    setup defineComponent.tsx:121
...

I could reproduce the error after upgrading vuetify version of the test setup to 3.5.17.

Closing custom dialog has no animation

I made a dialog with a custom component, but when I call $emit("closeDialog") it closes the dialog immediately and doesn't do the fade animation. I think the issue is happening here:

resolve(value);
_app.unmount();
document.body.removeChild(div);

Perhaps it needs some sort of delay before removing from the document dom?

export pluginOptions type

Please export type pluginOptions.
I would like to create a nuxt module for your project, but I need the plugin options for typesafe configuring the module.

How to modify the dialog's style?

Excellent component.
How should I modify the dialog's style? For example, remove the icon from the card title bar and align the buttons to the right in the card actions bar.
Thanks.

Stack multiple notifications

It would be nice to support a stack of notifications when multiple are presented at once. Currently when you receive multiple notifications they fall on top of each other, but having a vertical stack would be nice so you can see more than one.

I'll try and work on this - but for now just starting a ticket.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.