Skip to content

Commit

Permalink
Metal-modal-deprecate#9: make modal draggable
Browse files Browse the repository at this point in the history
Metal-modal-deprecate#9: customize starting modal height
  • Loading branch information
antoniorhee committed Aug 2, 2017
1 parent 4a9f479 commit 520ba50
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
6 changes: 4 additions & 2 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ <h1>Modal</h1>
<button type="button" class="btn btn-primary openModal">Open Modal</button>
<script type="text/javascript">
window.modal = new metal.Modal({
body: 'One fine body...',
disableDrag: false,
element: '.modal',
footer: '<button type="button" class="btn btn-primary">OK</button>',
header: '<h4 class="modal-title">Modal header</h4>',
body: 'One fine body...',
footer: '<button type="button" class="btn btn-primary">OK</button>'
offsetTop: 200
});

document.querySelector('.openModal').addEventListener('click', function() {
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
"modal"
],
"dependencies": {
"metal": "^2.0.0",
"metal-component": "^2.0.0",
"metal-dom": "^2.0.0",
"metal-events": "^2.0.0",
"metal-soy": "^2.0.0"
"metal-component": "^1.0.0-rc.11",
"metal-drag-drop": "^2.0.1",
"metal-soy": "^1.0.0-rc.11"
},
"devDependencies": {
"bootstrap": "^3.3.6",
Expand Down
24 changes: 24 additions & 0 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import core from 'metal';
import dom from 'metal-dom';
import { Drag } from 'metal-drag-drop';
import { EventHandler } from 'metal-events';
import templates from './Modal.soy.js';
import Component from 'metal-component';
Expand All @@ -18,6 +19,13 @@ class Modal extends Component {
*/
created() {
this.eventHandler_ = new EventHandler();

this.drag_ = new Drag({
disabled: this.get('disableDrag'),
handles: '.modal-header',
sources: '.modal',
useShim: false
});
}

/**
Expand Down Expand Up @@ -219,6 +227,15 @@ Modal.STATE = {
validator: core.isString
},

/**
* Boolean to determine whether modal will be draggable.
* @type {Boolean}
*/
disableDrag: {
validator: core.isBoolean,
value: false
},

/**
* Content to be placed inside modal footer. Can be either an html string or
* a function that calls incremental-dom to render the footer.
Expand Down Expand Up @@ -263,6 +280,13 @@ Modal.STATE = {
value: false
},

/**
* Number indicating the vertical position of modal in pixels.
* @type {number}
*/
offsetTop: {
},

/**
* Whether overlay should be visible when modal is visible.
* @type {boolean}
Expand Down
11 changes: 6 additions & 5 deletions src/Modal.soy
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
{@param? header: html|string}
{@param? headerId: string}
{@param? noCloseButton: bool}
{@param? offsetTop: number}
{@param? role: string}
{@param? visible: bool}
<div
class="modal{$elementClasses ? ' ' + $elementClasses : ''}"
style="display: {$visible ? 'block' : 'none'}">
<div
aria-describedby="{$bodyId}"
aria-labelledby="{$headerId}"
class="modal-dialog{$dialogClasses ? ' ' + $dialogClasses : ''}"
tabindex="0"
role="{$role ? $role : 'dialog'}"
aria-labelledby="{$headerId}"
aria-describedby="{$bodyId}">
<div class="modal-content">
tabindex="0">
<div class="modal-content" style="top: {$offsetTop}px">
<header class="modal-header">
{if $header}
{if not $noCloseButton}
<button type="button" class="close" data-onclick="hide" aria-label="Close">
<button aria-label="Close" class="close" data-onclick="hide" type="button">
<span aria-hidden="true">×</span>
</button>
{/if}
Expand Down

0 comments on commit 520ba50

Please sign in to comment.