Code Monkey home page Code Monkey logo

vuetify-use-dialog's Introduction

vuetify-use-dialog

Confirming user choice is a good thing to do, it should also be easy to do.

A module that simplifies the creation of dialogs and snackbars in Vuetify.

Demo: StackBlitz

Installation

npm install vuetify-use-dialog

Usage

Install the plugin (after vuetify)

import { createApp } from 'vue'
import { createVuetify } from 'vuetify'
import VuetifyUseDialog from 'vuetify-use-dialog'

import App from './App.vue'

const app = createApp(App)
const vuetify = createVuetify()

app.use(vuetify)
app.use(VuetifyUseDialog)

app.mount('#app')

Call the useConfirm or useSnackbar composable anywhere:

<script setup lang="ts">
import { useConfirm, useSnackbar } from 'vuetify-use-dialog'

const createConfirm = useConfirm()
const createSnackbar = useSnackbar()

async function handleConfirm() {
  const isConfirmed = await createConfirm({ content: 'This action is permanent!' })

  if (!isConfirmed)
    return

  createSnackbar({ text: 'Confirmed' })
}
</script>

<template>
  <VBtn @click="handleConfirm">
    Confirm
  </VBtn>
</template>

Check this if you're using Options API.

Options

useConfirm

Name Type Default Description
title string 'Are you sure?' Dialog title.
titleComponent Component Custom title component.
titleComponentProps object {} Custom title component props.
content string '' Dialog content.
contentComponent Component Custom content component.
contentComponentProps object {} Custom content component props.
confirmationText string 'Ok' Confirmation button caption.
cancellationText string 'Cancel' Cancellation button caption.
dialogProps object {} VDialog props.
cardProps object {} VCard props.
confirmationButtonProps object {} VBtn props for the confirmation button.
cancellationButtonProps object {} VBtn props for the cancellation button.
cardTitleProps object {} VCardTitle props for the dialog title.
cardTextProps object {} VCardText props for the dialog content.
confirmationKeyword string undefined If provided the confirmation button will be disabled by default and an additional textfield will be rendered. The confirmation button will only be enabled when the contents of the textfield match the value of confirmationKeyword.
confirmationKeywordTextFieldProps object {} VTextField props for the confirmation keyword textfield.
cardActionsProps object {} VCardActions props.
actionsContentComponent Component {} Custom actions content component.

useSnackbar

Name Type Default Description
text string '' Snackbar text.
snackbarProps object {} VSnackbar props.
showCloseButton boolean true Show the close button.
closeButtonText string 'Close' Close button text
closeButtonProps object {} VBtn props.

Global options:

app.use(VuetifyUseDialog, {
  confirmDialog: {
    // useConfirm options
    title: 'Are you sure?'
  },
  snackbar: {
    // useSnackbar options
    snackbarProps: {
      timeout: 2000,
    }
  }
})

Looking for a stackable toast component? Check out Vuetify Sonner.

License

MIT

vuetify-use-dialog's People

Contributors

iuri-gg avatar kadirgun avatar wobsoriano avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

vuetify-use-dialog's Issues

ConfirmDialog injection doesn't work in bundled version

Hello,
First of all, thanks for this package, I'm in the middle of an upgrade and this saved a bunch of time porting my vue 2 dialog/snackbar code over.

I'm seeing an issue whereby ConfirmDialog is unable to inject on mount, with the warning:

[Vue warn]: injection "Symbol(ConfirmDialogKey)" not found. 
  at <ConfirmDialog dialogProps=

Naturally this results in the dialog not working properly as the promise is never resolved.
If I vendor this package within my codebase the issue goes away, thus the issue is limited to the version distributed on npm.

useTheme must be called from inside a setup function

I have a vuetify 2 project I am trying to migrate to v3.
In v2 I was using vuetify-confirm

In my v3 project I want to use vuetify-use-dialog in a plugin like this (similiar to vuetify-confirm):

this.$confirm(someProps).then(res => { // .. Do stuff })

But I am getting this error:
Error: [Vuetify] useTheme must be called from inside a setup function

Is it possible to achieve this functionality or is there an alternative way to implement it?

new dialogs open successive when press Enter

After clicking the button, a dialog opens. When the "Enter" key is pressed, a new dialog opens and is placed on top of the previous one. This behavior can be observed on the demo page.

clicked on a delete button for first time:

image

then press enter:
image

I believe the reason for this behavior is that the delete button remains focused after being clicked. To address this, we can manually disable the button or prevent the "Enter" key press using the "@keydown.enter.prevent" directive. Another option is to unfocus the button when it is clicked. However, i personally prefer not to make any changes and want library does it. is there any way to solve this built in?

CreateSnackbar blocks router.back?

When i use CreateSnackbar, router.back stopped working for the time snackbar showed, but router.replace , router.push worked fine.

This is very strange. Does anyone know what's going on?

Package is broken when customizing vite extensions

node: v16.18.1
vue: 3.2.45
vuetify: 3.1.2
vite: 4.0.4
vuetify-use-dialog: 0.1.8

When run in development environment vite fails on an import validation check.

$ npm run dev

[plugin:vite:import-analysis] Failed to resolve import "./utils" from "node_modules\vuetify-use-dialog\dist\ConfirmDialog.vue". Does the file exist?
C:/Project/client/node_modules/vuetify-use-dialog/dist/ConfirmDialog.vue:4:33
2  |  import { VBtn, VCard, VCardActions, VCardText, VCardTitle, VDialog, VSpacer, VThemeProvider } from "vuetify/components";
3  |  import { computed, inject, onMounted, ref } from "vue";
4  |  import { ConfirmDialogKey } from "./utils";
   |                                    ^
5  |  const _sfc_main = /* @__PURE__ */ _defineComponent({
6  |    __name: "ConfirmDialog",
    at formatError (file:///C:/Project/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41235:46)
    at TransformContext.error (file:///C:/Project/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41231:19)
    at normalizeUrl (file:///C:/Project/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39540:33)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async TransformContext.transform (file:///C:/Project/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39673:47)
    at async Object.transform (file:///C:/Project/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41506:30)
    at async loadAndTransform (file:///C:/Project/client/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:39313:29

TypeError: Cannot read properties of null (reading '_vnode')

Describe the bug

I have automated test that now are failing with error TypeError: Cannot read properties of null (reading '_vnode'). When I try to use it in dev mode, I don't see any errors, but in test I get error every single time.

Everything working fine including v0.6.8 and fails reliably in CI with v0.6.9. Probably related to #24.

Reproduction

Looking at stack trace following render call is causing the error

runtime-core.esm-bundler.js:6652 Uncaught TypeError: Cannot read properties of null (reading '_vnode')
    at Object.render2 [as render] (runtime-core.esm-bundler.js:6652:21)
    at render (runtime-dom.esm-bundler.js:1490:20)
    at vuetify-use-dialog.js:310:11
render2	@	runtime-core.esm-bundler.js:6652
render	@	runtime-dom.esm-bundler.js:1490
(anonymous)	@	vuetify-use-dialog.js:310

it is called from this PR

          setTimeout(() => {
            render(null, app._container.firstElementChild)
          }, 150)

Looking at the Object.render2 [as render] (runtime-core.esm-bundler.js:6652:21) I see following code:

  const render = (vnode, container, namespace) => {
    if (vnode == null) {
      if (container._vnode) {
        unmount(container._vnode, null, null, true);
      }
    } else {

Error happens at if (container._vnode) { - container is null (app._container.firstElementChild?)

Logs

No response

System Info

System:
    OS: macOS 14.4
    CPU: (10) arm64 Apple M1 Max
    Memory: 3.00 GB / 32.00 GB
    Shell: 5.2.26 - /opt/homebrew/bin/bash
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.10.0/bin/npm
  Browsers:
    Chrome: 122.0.6261.129
    Safari: 17.4
  npmPackages:
    vue: ^3.4.21 => 3.4.21
    vuetify: ^3.5.9 => 3.5.9

Severity

blocking an upgrade

Can't render custom title component

Using the titleComponent prop I get this error, but with contentComponent it works as expected.

"Extraneous non-props attributes (titleComponent) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. "

Custom card actions props

Hello ! I would like to customize my card actions, but the slot override seems not working. Here is my code :

this.confirm({
  title: 'My title',
  content: "My content",
  cardActionsProps: {
    "v-slot:default": () => createElementVNode('div', {}, [h('div', {id: 'myDiv', innerHTML: 'My div text'})])
  }
})

In my DOM, popup card actions appears like this :
image

I work with Typescript v4.7.4, Vue v3.2.38, Vuetify v3.3.7 and vuetify-vue-dialog v0.6.0

Thanks by advance !

template overrides

It would be great if we could override the template in some way.

Specifically we have a requirement to add an icon, and change the color of the card title in the dialog - but there's no exposed property to allow this - nor does Vuetify really expose any props to do with title color. So one option might be to provide a way to provide your own template.

createConfirm Button Text Props not working

createConfirm({
        title:'请确认操作',
        content: '的n is permanent!',
        dialogProps: {
          'max-width': '500px'
        },
        cancellationButtonProps: {
          'text': 'No'
        },
        confirmationButtonProps: {
          'text': 'Sure'
        }
      }).then(isConfirmed => {
        if (!isConfirmed) return
        else this.createSnackbar({ text: 'Confirmed' })
      })

button text always show CANCEL & OK

snackbarProps and closeButtonProps should be merged with defaults

I've defined the following defaults for the snackbar props

 app.use(VuetifyUseDialog, {
    snackbar: {
      theme: 'light',
      snackbarProps: {
        timeout: -1,
        location: 'top',
        color: 'success'
      },
      closeButtonProps: {
        variant: 'text'
      }
    }
  })

If I call this.$toast({ text: 'Event updated'}) it works as expected. However, if I call

this.$toast({ text: 'Event updated', snackbarProps: { color: 'warning' } })

Then I expect the snackbarProps in this call to be merged with the defaults. In other words, the call above should be the same as

this.$toast({ text: 'Event updated', snackbarProps: { color: 'warning', timeout: -1, location: 'top' } })

But what actually happens is that all of the default snackbarProps are ignored, so the call above is effectively the same as

this.$toast({ text: 'Event updated', snackbarProps: { color: 'warning', timeout: 5000, location: 'bottom' } })

In order to get the behaviour I want, I have to explicitly call

this.$toast({ text: 'Event updated', snackbarProps: { color: 'warning', timeout: -1, location: 'top' } })

Would it be possible to merge the snackbarProps (and closeButtonProps) in the call with the defaults instead?

Error in console when using confirm

I've observed that when using the confirmation in vuetify, the package causes the following error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'classList')
    at Object.blockScrollStrategy [as block] (scrollStrategies.ts:85:22)
    at scrollStrategies.ts:57:47
    at EffectScope.run (chunk-FEPXYT3V.js:1291:20)
    at scrollStrategies.ts:53:27

It doesn't seem to affect the behavior, but it is noisy and might indicate bigger issues under the hood.

Uncaught RangeError: Maximum call stack size exceeded when opening v-dialog

I am encountering a "Maximum call stack size exceeded" error when attempting to open a dialog using Vuetify's v-dialog component. This issue arises specifically during the dialog's focus management process, as indicated by the repeated error messages in the console.

Trigger the opening of a v-dialog component.
Click on either the "Cancel" or "OK" button within the dialog.
The error occurs specifically when these buttons are clicked, during the focus management process.

Uncaught RangeError: Maximum call stack size exceeded.
at HTMLDocument.onFocusin (vuetify-use-dialog.js?v=9ee267a8:13917:23)
at HTMLDocument.onFocusin (vuetify_lib_components_VDialog_index__mjs.js?v=9ee267a8:96:23)
at HTMLDocument.onFocusin (vuetify-use-dialog.js?v=9ee267a8:13917:23)
at HTMLDocument.onFocusin (vuetify_lib_components_VDialog_index__mjs.js?v=9ee267a8:98:24)
at HTMLDocument.onFocusin (vuetify-use-dialog.js?v=9ee267a8:13917:23)
at HTMLDocument.onFocusin (vuetify_lib_components_VDialog_index__mjs.js?v=9ee267a8:96:23)
at HTMLDocument.onFocusin (vuetify-use-dialog.js?v=9ee267a8:13917:23)
at HTMLDocument.onFocusin (vuetify_lib_components_VDialog_index__mjs.js?v=9ee267a8:98:24)
at HTMLDocument.onFocusin (vuetify-use-dialog.js?v=9ee267a8:13917:23)
at HTMLDocument.onFocusin (vuetify_lib_components_VDialog_index__mjs.js?v=9ee267a8:96:23)

Could not resolve "useTheme" in latest release

Great repository!

For the latest release, I get the following error when starting up the server:

✘ [ERROR] Could not resolve "/Users/wobsoriano/tmp/vuetify-use-dialog/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/vuetify/lib/framework.mjs"

    node_modules/vuetify-use-dialog/dist/vuetify-use-dialog.js:2:30:
      2 │ ... { useTheme as F } from "/Users/wobsoriano/tmp/vuetify-use-dialog/node_modules/.pnpm/[email protected][email protected]_vite-plugin-vuet...

Seems that there is something wrong with the build of the latest release.

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.