Giter Site home page Giter Site logo

djaler / vue-promise-dialogs Goto Github PK

View Code? Open in Web Editor NEW
48.0 3.0 3.0 615 KB

A tiny & modern library that allows you to work with dialogs as with asynchronous functions.

Home Page: https://djaler.github.io/vue-promise-dialogs/

License: Other

JavaScript 2.20% TypeScript 81.31% HTML 1.00% Vue 15.49%
vue dialogs promises async

vue-promise-dialogs's Introduction

npm npm bundle size demo

Vue Promise Dialogs

A tiny & modern library that allows you to work with dialogs as with asynchronous functions.

Why?

Because many dialogs work exactly as promises. They are opened (called) and then closed with some result (resolved) or canceled (rejected).

Install

From version 2.0.0 it works for Vue 2 and Vue 3 within a single package by the power of vue-demi ๐Ÿ”ฅ

Vue 3

npm install vue-promise-dialogs

Vue 2

npm install vue-promise-dialogs @vue/composition-api

Usage

Main requirements:

  1. You should mount exactly one PromiseDialogsWrapper somewhere in your application root.
  2. The dialog component should accept params props.
  3. The dialog component should emit resolve or reject events when the user makes a decision.
import { createPromiseDialog } from "vue-promise-dialogs"

interface BooleanDialogParams {
    text: string;
}

const BooleanDialog = defineComponent({
    template: `
      <div class="dialog">
          <p>{{ params.text }}</p>
          <button name="true" @click="$emit('resolve', true)">True</button>
          <button name="false" @click="$emit('resolve', false)">False</button>
          <button name="cancel" @click="$emit('reject', 'cancel')">Cancel</button>
      </div>
    `,
    props: {
        params: {
            type: Object as PropType<BooleanDialogParams>,
            required: true,
        },
    },
});

// First type argument is the type of params prop that will be passed to component
// Second type argument is the type of value with which the promise will be fulfilled
const openDialog = createPromiseDialog<BooleanDialogParams, boolean>(BooleanDialog);

// When you call this function, dialog will be mounted to `PromiseDialogsWrapper`.
// When user press any button and resolve/reject event emitted, promise will be settled and dialog will be destroyed.
const result: boolean = await openDialog({ text: 'Some text' });

Unmount delay

By default, a dialog is unmounted immediately right after resolve/reject, but maybe you want to change this behaviour, for example, to play the close animation.

You have two options here:

  1. Specify the unmount delay (in ms) using unmountDelay prop in PromiseDialogsWrapper.
  2. Specify the unmount delay (in ms) as a second argument when emitting resolve/reject event. This option will override unmountDelay prop if both are provided.

Close all

In some cases you may want to close all opened dialogs. For example, on route change.

You can use closeAllDialogs for this. All you need is to set a reason, which will be used in promises reject.

TODO

  • Fallback to mount dialogs without PromiseDialogsWrapper

vue-promise-dialogs's People

Contributors

djaler avatar editicalu avatar renovate-bot avatar renovate[bot] 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-promise-dialogs's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • build(deps): update dependency vite to v2.9.16
  • ci(deps): update jamesives/github-pages-deploy-action action to v4.4.3
  • chore(deps): update dependency eslint-import-resolver-typescript to v3.6.1
  • chore(deps): update dependency simple-git-hooks to v2.9.0
  • chore(deps): update dependency vue to v2.7.14
  • chore(deps): update pnpm to v7.33.6
  • fix(deps): update dependency vue-demi to ^0.14.0
  • test(deps): update dependency vitest to v0.34.6
  • build(deps): update dependency @rollup/plugin-replace to v5
  • build(deps): update dependency @vitejs/plugin-vue to v4
  • build(deps): update dependency typescript to v5
  • build(deps): update dependency vite to v4
  • chore(deps): update dependency agadoo to v3
  • chore(deps): update dependency commit-and-tag-version to v11
  • chore(deps): update dependency jsdom to v22
  • chore(deps): update pnpm to v8
  • ci(deps): update actions/checkout action to v4
  • test(deps): update dependency @vue/test-utils to v2.4.1
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/checks.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • reviewdog/action-eslint v1
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
.github/workflows/demo.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • JamesIves/github-pages-deploy-action v4.4.1
.github/workflows/release.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
  • filipstefansson/set-npm-token-action v1
npm
package.json
  • @djaler/conventional-changelog-standard 1.2.0
  • @djaler/eslint-config-typescript 0.0.9
  • commit-and-tag-version 10.1.0
  • conventional-github-releaser 3.1.5
  • eslint 8.21.0
  • eslint-import-resolver-typescript 3.5.5
  • nano-staged 0.8.0
  • simple-git-hooks 2.8.1
  • typescript 4.4.2
  • pnpm 7.11.0
packages/core/package.json
  • vue-demi ^0.13.4
  • @rollup/plugin-replace 4.0.0
  • agadoo 2.0.0
  • clean-publish 4.0.0
  • es-check 7.1.1
  • vite 2.9.15
  • vue 3.2.37
  • vue2 2.6.12
  • @vue/composition-api ^1.1.0
  • vue ^2.6.4 || ^3.2.0
packages/demo/package.json
  • @picocss/pico 1.5.10
  • vue 3.2.37
  • @vitejs/plugin-vue 2.3.4
  • @vue/compiler-sfc 3.2.37
  • vite 2.9.15
packages/tests-base/package.json
  • vitest 0.22.1
  • vitest 0.22.1
packages/tests-vue2/package.json
  • @vue/composition-api 1.7.0
  • @vue/test-utils 1.3.0
  • jsdom 20.0.0
  • vitest 0.22.1
  • vue 2.6.12
  • vue-template-compiler 2.6.12
packages/tests-vue3/package.json
  • @vue/test-utils 2.0.2
  • jsdom 20.0.0
  • vitest 0.22.1
  • vue 3.2.37

  • Check this box to trigger a request for Renovate to run again on this repository

How add more props?

I want to have a more understandable component, but that's hard to achieve when the source of truth is the object.

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.