Giter Club home page Giter Club logo

vue-dialog-drag's Introduction

GitHub issues GitHub license npm

vue-dialog-drag

Simple draggable dialog

Demo

Features:

  • Drag & Drop
  • Touch support (only for drag, not for drop)
  • Drop area component
  • 'Pin mode', to lock drag.

Installation

npm install vue-dialog-drag --save

Usage

Import and register component

import DialogDrag from 'vue-dialog-drag'

export default{
  ...
  components:{
    DialogDrag
  }
}

include css

<style src='vue-dialog-drag/dist/vue-dialog-drag.css'></style>

Or import source component from: 'vue-dialog-drag/src/vue-dialog-drag.vue' And install devDependencies. (stylus and pug) see package.json)

Examples

Single file component

<template>
  <div id="app">
    <dialog-drag id="dialog-1">
      <p> Test dialog</p>
    </dialog-drag>
    <drop-area @drop='drop'>
      <p>Drop Here</p>
    </drop-area>
  </div>
</template>

<script>  
import DialogDrag from 'vue-dialog-drag'
import DropArea from 'vue-dialog-drag/dist/drop-area'
export default {
  name: 'app',
  components: {
    DialogDrag,
    DropArea
  },
  methods: {
    drop (id) {
      console.log('drop id:', id)
    }
  }
}
</script>

<style src="vue-dialog-drag/dist/vue-dialog-drag.css"></style>
<style src="vue-dialog-drag/dist/drop-area.css"></style>

<!-- optional dialog styles, see example -->
<style src="vue-dialog-drag/dist/dialog-styles.css"></style>

html

See this fiddle

Dialog Component

Slots

  • title: dialog title. If you don't need formatted title, use 'title' prop.
  • button-pin: content for pin button
  • button-pinned: content for pin button when dialog is pinned
  • button-close: content for close button

Props

  • id: Unique id for dialog
  • title: Dialog title
  • eventCb: Function(props Object)
  • options: Object
    • left: Number
    • top: Number
    • zIndex: Number
    • x: alias of left
    • y: alias of top
    • z: alias of zIndex
    • width: Number (0 or null to auto)
    • height: Number (0 or null to auto)
    • buttonPin: Boolean
    • buttonClose:Boolean
    • dragCursor: css cursor to show when drag is enabled
    • centered: "viewport" | "parent" , center dialog to viewport or parent element
    • pinned: Boolean, disable/enable drag
    • dropEnabled: Boolean, handle drag with mouse events, instead of drag events

Events

All event emits an object: { id, left, top, x, y, z, width, height, pinned } You can format it, whith 'eventCb' prop.

  • load: fired on mounted
  • focus: fired on click and touch
  • pin: fired on pin / unpin dialog
  • drag-start: fired on dragstart
  • move: fired when move dialog
  • drag-end: fired on dragend
  • close: fired when close dialogs

Css

The main container has class .dialog-drag, and .dialog-drag .fixed when dialog is pinned

You can import extra dialog styles from dist/dialog-styles.css.

view: example styles

Drop area component

Slots

Over: content rendered when the dialog is dragged over drop area.

Events

drop: fired when drop the dialog, emits dialog id.

vue-dialog-drag's People

Contributors

emiliorizzo 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  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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-dialog-drag's Issues

focus event only will triggered once

I would like to change z-index for the dialogs such that the dialog brings to top when clicked. However, focus event fires once and cannot be triggered.

Cannot interact with button on Chromium based browser with touchscreen

Hi, thanks for the great project. It appears trying to touch a button located inside the dialog box will trigger 'drag-start' event that somehow block it from interacting with any button located in the dialog box, including the 'pin' and 'close' buttons. This only happens on Chromium based browsers (i.e. Google Chrome, Chromium, Falkon) w/ touchscreen interface and works fine with Firefox (tested on Ubuntu KDE and GNOME). More than happy to make a PR if someone can provide some guidance to pinpoint the issue.

Inputs not working inside dialog

I tried having text input and radio buttons inside a dialog. The problem is only the radio buttons are working. Anything I can do on the options to fix this?

Is there a way to prevent dragging outside the browser window

For example on your Fiddle I can drag the dialogs right off the browser and drop them in my Outlook window (which causes an email with the dialog ID in the body) -- but now the dialog is GONE for good until I refresh the page. We need some way to prevent the dialog being "lost", either limit travel to a bounding DIV/window, or else "fail" back to initial position when dropped outside a bounding DIV/window. FYI there is an example of it using jQuery drag plugin here.

Drop not working on mobile

Hello.
This is a very nice components!
Any plans to make it work in mobile devices?
It creates dialog , and I can move the around. but I cant drop them.
Keep up the good work!

Patch to make dragging work in IE10

FYI - this simple patch makes the drag work in IE10. Apparently IE10 does not support for (x of y), but it is easy to substitute for (x in y) in this case.

diff --git a/src/components/vue-dialog-drag.vue b/src/components/vue-dialog-drag.vue
index cb766f5..4b601cd 100644
--- a/src/components/vue-dialog-drag.vue
+++ b/src/components/vue-dialog-drag.vue
@@ -279,9 +279,9 @@ export default {
         this.drag = (this.options.pinned) ? false : this.drag
         // available options
         let ops = this.availableOptions
-        for (let op of ops) {
+        for (let op in ops) {
           if (this.options.hasOwnProperty(op)) {
-            this.$set(this, op, this.options[op])
+            this.$set(this, ops[op], this.options[op])
           }
         }
       }

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.