UNPKG

lulouis-vant

Version:

Lightweight Mobile UI Components built on Vue

212 lines (197 loc) 4.73 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.default = void 0; var _utils = require("../utils"); var _event = require("../utils/event"); var _Key = _interopRequireDefault(require("./Key")); var _use = (0, _utils.use)('number-keyboard'), sfc = _use[0], bem = _use[1], t = _use[2]; var CLOSE_KEY_TYPE = ['blue', 'big']; var DELETE_KEY_TYPE = ['delete', 'big', 'gray']; var _default = sfc({ props: { show: Boolean, title: String, closeButtonText: String, deleteButtonText: String, theme: { type: String, default: 'default' }, extraKey: { type: String, default: '' }, zIndex: { type: Number, default: 100 }, transition: { type: Boolean, default: true }, showDeleteKey: { type: Boolean, default: true }, hideOnClickOutside: { type: Boolean, default: true } }, mounted: function mounted() { this.handler(true); }, destroyed: function destroyed() { this.handler(false); }, activated: function activated() { this.handler(true); }, deactivated: function deactivated() { this.handler(false); }, watch: { show: function show() { if (!this.transition) { this.$emit(this.show ? 'show' : 'hide'); } } }, computed: { keys: function keys() { var keys = []; for (var i = 1; i <= 9; i++) { keys.push({ text: i }); } switch (this.theme) { case 'default': keys.push({ text: this.extraKey, type: ['gray'] }, { text: 0 }, { text: this.deleteText, type: ['gray', 'delete'] }); break; case 'custom': keys.push({ text: 0, type: ['middle'] }, { text: this.extraKey }); break; } return keys; }, deleteText: function deleteText() { return this.deleteButtonText || t('delete'); } }, methods: { handler: function handler(action) { /* istanbul ignore if */ if (this.$isServer) { return; } if (action !== this.handlerStatus && this.hideOnClickOutside) { this.handlerStatus = action; document.body[(action ? 'add' : 'remove') + 'EventListener']('touchstart', this.onBlur); } }, onBlur: function onBlur() { this.$emit('blur'); }, onClose: function onClose() { this.$emit('close'); this.onBlur(); }, onAnimationEnd: function onAnimationEnd() { this.$emit(this.show ? 'show' : 'hide'); }, onPress: function onPress(text) { if (text === '') { return; } if (text === this.deleteText) { this.$emit('delete'); } else if (text === this.closeButtonText) { this.onClose(); } else { this.$emit('input', text); } } }, render: function render(h) { var theme = this.theme, onPress = this.onPress, closeButtonText = this.closeButtonText; var showTitleClose = closeButtonText && theme === 'default'; return h("transition", { "attrs": { "name": this.transition ? 'van-slide-up' : '' } }, [h("div", { "directives": [{ name: "show", value: this.show }], "style": { zIndex: this.zIndex }, "class": bem([theme]), "on": { "touchstart": _event.stop, "animationend": this.onAnimationEnd, "webkitAnimationEnd": this.onAnimationEnd } }, [(this.title || showTitleClose) && h("div", { "class": [bem('title'), 'van-hairline--top'] }, [h("span", [this.title]), showTitleClose && h("span", { "class": bem('close'), "on": { "click": this.onClose } }, [closeButtonText])]), h("div", { "class": bem('body') }, [this.keys.map(function (key) { return h(_Key.default, { "key": key.text, "attrs": { "text": key.text, "type": key.type }, "on": { "press": onPress } }); })]), theme === 'custom' && h("div", { "class": bem('sidebar') }, [h(_Key.default, { "attrs": { "text": this.deleteText, "type": DELETE_KEY_TYPE }, "on": { "press": onPress } }), h(_Key.default, { "attrs": { "text": closeButtonText, "type": CLOSE_KEY_TYPE }, "on": { "press": onPress } })])])]); } }); exports.default = _default;