diff --git a/demo/client_side_rendering/src/App.vue b/demo/client_side_rendering/src/App.vue index 88e15a3..32c2c5c 100644 --- a/demo/client_side_rendering/src/App.vue +++ b/demo/client_side_rendering/src/App.vue @@ -58,27 +58,18 @@ - - - + \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 8b35690..66f6e77 100644 --- a/dist/index.js +++ b/dist/index.js @@ -566,6 +566,10 @@ exports.default = { type: [Boolean, String], default: false }, + scrollable: { + type: Boolean, + default: false + }, reset: { type: Boolean, default: false @@ -612,6 +616,10 @@ exports.default = { default: 300, validator: function validator(value) { if (typeof value === 'string') { + if (value === 'auto') { + return true; + } + var height = (0, _parser2.default)(value); return (height.type === '%' || height.type === 'px') && height.value > 0; } @@ -672,7 +680,6 @@ exports.default = { if (value) { this.visibility.overlay = true; - setTimeout(function () { _this.visibility.modal = true; _this.$nextTick(function () { @@ -709,44 +716,74 @@ exports.default = { window.addEventListener('resize', this.onWindowResize); this.onWindowResize(); + + if (this.scrollable && !this.isAutoHeight) { + console.warn('Modal "' + this.name + '" has scrollable flag set to true ' + ('but height is not "auto" (' + this.height + ')')); + } }, beforeDestroy: function beforeDestroy() { window.removeEventListener('resize', this.onWindowResize); }, computed: { + isAutoHeight: function isAutoHeight() { + return this.modal.heightType === 'auto'; + }, position: function position() { var window = this.window, modal = this.modal, - shift = this.shift; + shift = this.shift, + pivotX = this.pivotX, + pivotY = this.pivotY, + trueModalWidth = this.trueModalWidth, + trueModalHeight = this.trueModalHeight, + isAutoHeight = this.isAutoHeight; - var maxLeft = window.width - this.trueModalWidth; - var maxTop = window.height - this.trueModalHeight; + var maxLeft = window.width - trueModalWidth; + var maxTop = window.height - trueModalHeight; - var left = shift.left + this.pivotX * (window.width - this.trueModalWidth); - var top = shift.top + this.pivotY * (window.height - this.trueModalHeight); + var minTop = this.scrollable ? Number.NEGATIVE_INFINITY : 0; + + var left = shift.left + pivotX * maxLeft; + var top = shift.top + pivotY * maxTop; return { left: (0, _util.inRange)(0, maxLeft, left), - top: (0, _util.inRange)(0, maxTop, top) + top: (0, _util.inRange)(minTop, maxTop, top) }; }, trueModalWidth: function trueModalWidth() { var window = this.window, - modal = this.modal; + modal = this.modal, + adaptive = this.adaptive, + minWidth = this.minWidth; + var value = modal.widthType === '%' ? window.width / 100 * modal.width : modal.width; - return this.adaptive ? (0, _util.inRange)(this.minWidth, this.window.width, value) : value; + return adaptive ? (0, _util.inRange)(minWidth, window.width, value) : value; }, trueModalHeight: function trueModalHeight() { var window = this.window, - modal = this.modal; + modal = this.modal, + isAutoHeight = this.isAutoHeight, + adaptive = this.adaptive; + var value = modal.heightType === '%' ? window.height / 100 * modal.height : modal.height; - return this.adaptive ? (0, _util.inRange)(this.minHeight, this.window.height, value) : value; + if (isAutoHeight) { + return 0; + } + + return adaptive ? (0, _util.inRange)(this.minHeight, this.window.height, value) : value; + }, + overlayClass: function overlayClass() { + return { + 'v--modal-overlay': true, + 'scrollable': this.scrollable && this.isAutoHeight + }; }, modalClass: function modalClass() { return ['v--modal-box', this.classes]; @@ -756,7 +793,7 @@ exports.default = { top: this.position.top + 'px', left: this.position.left + 'px', width: this.trueModalWidth + 'px', - height: this.trueModalHeight + 'px' + height: this.isAutoHeight ? 'auto' : this.trueModalHeight + 'px' }; } }, @@ -1034,6 +1071,13 @@ var types = [{ }]; var getType = function getType(value) { + if (value === 'auto') { + return { + type: value, + value: 0 + }; + } + for (var i = 0; i < types.length; i++) { var type = types[i]; if (type.regexp.test(value)) { @@ -1072,7 +1116,7 @@ exports = module.exports = __webpack_require__(2)(); // module -exports.push([module.i, "\n.v--modal-overlay {\n position: fixed;\n left: 0;\n top: 0;\n width: 100vw;\n height: 100vh;\n background: rgba(0, 0, 0, 0.2);\n z-index: 999;\n opacity: 1;\n}\n.v--modal-overlay .v--modal-box {\n position: relative;\n overflow: hidden;\n box-sizing: border-box;\n}\n.v--modal {\n background-color: white;\n text-align: left;\n border-radius: 3px;\n box-shadow: 0 20px 60px -2px rgba(27, 33, 58, .4);\n padding: 0;\n}\n.v--modal.v--modal-fullscreen {\n width: 100vw;\n height: 100vh;\n margin: 0;\n left: 0;\n top: 0;\n}\n.v--modal-top-right {\n display: block;\n position: absolute;\n right: 0;\n top: 0;\n}\n.overlay-fade-enter-active, .overlay-fade-leave-active {\n transition: all 0.2s;\n}\n.overlay-fade-enter, .overlay-fade-leave-active {\n opacity: 0;\n}\n.nice-modal-fade-enter-active, .nice-modal-fade-leave-active {\n transition: all 0.4s;\n}\n.nice-modal-fade-enter, .nice-modal-fade-leave-active {\n opacity: 0;\n transform: translateY(-20px);\n}\n", "", {"version":3,"sources":["/./src/Modal.vue?17bbad80"],"names":[],"mappings":";AAwaA;EACA,gBAAA;EACA,QAAA;EACA,OAAA;EACA,aAAA;EACA,cAAA;EACA,+BAAA;EACA,aAAA;EACA,WAAA;CACA;AAEA;EACA,mBAAA;EACA,iBAAA;EACA,uBAAA;CACA;AAEA;EACA,wBAAA;EACA,iBAAA;EACA,mBAAA;EACA,kDAAA;EACA,WAAA;CACA;AAEA;EACA,aAAA;EACA,cAAA;EACA,UAAA;EACA,QAAA;EACA,OAAA;CACA;AAEA;EACA,eAAA;EACA,mBAAA;EACA,SAAA;EACA,OAAA;CACA;AAEA;EACA,qBAAA;CACA;AAEA;EACA,WAAA;CACA;AAEA;EACA,qBAAA;CACA;AAEA;EACA,WAAA;EACA,6BAAA;CACA","file":"Modal.vue","sourcesContent":["\n\n\n"],"sourceRoot":"webpack://"}]); +exports.push([module.i, "\n.v--modal-overlay {\n position: fixed;\n box-sizing: border-box;\n left: 0;\n top: 0;\n width: 100vw;\n height: 100vh;\n background: rgba(0, 0, 0, 0.2);\n z-index: 999;\n opacity: 1;\n}\n.v--modal-overlay.scrollable {\n height: 100%;\n min-height: 100vh;\n overflow-y: auto;\n padding-bottom: 10px;\n}\n.v--modal-overlay .v--modal-box {\n position: relative;\n overflow: hidden;\n box-sizing: border-box;\n}\n.v--modal-overlay.scrollable .v--modal-box {\n margin-bottom: 10px;\n}\n.v--modal {\n background-color: white;\n text-align: left;\n border-radius: 3px;\n box-shadow: 0 20px 60px -2px rgba(27, 33, 58, .4);\n padding: 0;\n}\n.v--modal.v--modal-fullscreen {\n width: 100vw;\n height: 100vh;\n margin: 0;\n left: 0;\n top: 0;\n}\n.v--modal-top-right {\n display: block;\n position: absolute;\n right: 0;\n top: 0;\n}\n.overlay-fade-enter-active, .overlay-fade-leave-active {\n transition: all 0.2s;\n}\n.overlay-fade-enter, .overlay-fade-leave-active {\n opacity: 0;\n}\n.nice-modal-fade-enter-active, .nice-modal-fade-leave-active {\n transition: all 0.4s;\n}\n.nice-modal-fade-enter, .nice-modal-fade-leave-active {\n opacity: 0;\n transform: translateY(-20px);\n}\n", "", {"version":3,"sources":["/./src/Modal.vue?79cb8c95"],"names":[],"mappings":";AA0cA;EACA,gBAAA;EACA,uBAAA;EACA,QAAA;EACA,OAAA;EACA,aAAA;EACA,cAAA;EACA,+BAAA;EACA,aAAA;EACA,WAAA;CACA;AAEA;EACA,aAAA;EACA,kBAAA;EACA,iBAAA;EACA,qBAAA;CACA;AAEA;EACA,mBAAA;EACA,iBAAA;EACA,uBAAA;CACA;AAEA;EACA,oBAAA;CACA;AAEA;EACA,wBAAA;EACA,iBAAA;EACA,mBAAA;EACA,kDAAA;EACA,WAAA;CACA;AAEA;EACA,aAAA;EACA,cAAA;EACA,UAAA;EACA,QAAA;EACA,OAAA;CACA;AAEA;EACA,eAAA;EACA,mBAAA;EACA,SAAA;EACA,OAAA;CACA;AAEA;EACA,qBAAA;CACA;AAEA;EACA,WAAA;CACA;AAEA;EACA,qBAAA;CACA;AAEA;EACA,WAAA;EACA,6BAAA;CACA","file":"Modal.vue","sourcesContent":["\n\n\n"],"sourceRoot":"webpack://"}]); // exports @@ -1140,7 +1184,7 @@ module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c } }, [(_vm.visibility.overlay) ? _c('div', { ref: "overlay", - staticClass: "v--modal-overlay", + class: _vm.overlayClass, attrs: { "aria-expanded": _vm.visible.toString(), "data-modal": _vm.name @@ -1166,7 +1210,7 @@ module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c $event.stopPropagation(); } } - }, [_vm._t("default"), _vm._v(" "), (_vm.resizable) ? _c('resizer', { + }, [_vm._t("default"), _vm._v(" "), (_vm.resizable && !_vm.isAutoHeight) ? _c('resizer', { attrs: { "min-width": _vm.minWidth, "min-height": _vm.minHeight diff --git a/src/Modal.vue b/src/Modal.vue index f583092..7b84761 100644 --- a/src/Modal.vue +++ b/src/Modal.vue @@ -2,7 +2,7 @@
@@ -16,7 +16,7 @@ :style="modalStyle" @mousedown.stop> - @@ -55,6 +55,10 @@ type: [Boolean, String], default: false }, + scrollable: { + type: Boolean, + default: false + }, reset: { type: Boolean, default: false @@ -102,6 +106,10 @@ default: 300, validator (value) { if (typeof value === 'string') { + if (value === 'auto') { + return true + } + let height = parseNumber(value) return (height.type === '%' || height.type === 'px') && height.value > 0 @@ -159,7 +167,6 @@ visible (value) { if (value) { this.visibility.overlay = true - // this.adaptSize() setTimeout(() => { this.visibility.modal = true @@ -195,50 +202,75 @@ window.addEventListener('resize', this.onWindowResize) this.onWindowResize() + + if (this.scrollable && !this.isAutoHeight) { + console.warn(`Modal "${this.name}" has scrollable flag set to true ` + + `but height is not "auto" (${this.height})`) + } }, beforeDestroy () { window.removeEventListener('resize', this.onWindowResize) }, computed: { + isAutoHeight () { + return this.modal.heightType === 'auto' + }, + position () { - const { window, modal, shift } = this + const { window, modal, shift, pivotX, pivotY, + trueModalWidth, trueModalHeight, isAutoHeight } = this - const maxLeft = window.width - this.trueModalWidth - const maxTop = window.height - this.trueModalHeight + const maxLeft = window.width - trueModalWidth + const maxTop = window.height - trueModalHeight - const left = shift.left + - this.pivotX * (window.width - this.trueModalWidth) - const top = shift.top + - this.pivotY * (window.height - this.trueModalHeight) + const minTop = this.scrollable + ? Number.NEGATIVE_INFINITY + : 0 + + const left = shift.left + pivotX * maxLeft + const top = shift.top + pivotY * maxTop return { left: inRange(0, maxLeft, left), - top: inRange(0, maxTop, top) + top: inRange(minTop, maxTop, top) } }, trueModalWidth () { - const { window, modal } = this + const { window, modal, adaptive, minWidth } = this + const value = modal.widthType === '%' ? window.width / 100 * modal.width : modal.width - return this.adaptive - ? inRange(this.minWidth, this.window.width, value) + return adaptive + ? inRange(minWidth, window.width, value) : value }, trueModalHeight () { - const { window, modal } = this + const { window, modal, isAutoHeight, adaptive } = this + const value = (modal.heightType === '%') ? window.height / 100 * modal.height : modal.height - return this.adaptive + if (isAutoHeight) { + return 0 + } + + return adaptive ? inRange(this.minHeight, this.window.height, value) : value }, + overlayClass () { + return { + 'v--modal-overlay': true, + 'scrollable': this.scrollable && this.isAutoHeight + } + }, + modalClass () { return ['v--modal-box', this.classes] }, @@ -248,7 +280,9 @@ top: this.position.top + 'px', left: this.position.left + 'px', width: this.trueModalWidth + 'px', - height: this.trueModalHeight + 'px' + height: this.isAutoHeight + ? 'auto' + : (this.trueModalHeight + 'px') } } }, @@ -424,6 +458,7 @@