index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _utils = require("../utils");
  6. var _popup = require("../mixins/popup");
  7. var _icon = _interopRequireDefault(require("../icon"));
  8. var _createNamespace = (0, _utils.createNamespace)('popup'),
  9. createComponent = _createNamespace[0],
  10. bem = _createNamespace[1];
  11. var _default = createComponent({
  12. mixins: [(0, _popup.PopupMixin)()],
  13. props: {
  14. round: Boolean,
  15. duration: [Number, String],
  16. closeable: Boolean,
  17. transition: String,
  18. safeAreaInsetBottom: Boolean,
  19. closeIcon: {
  20. type: String,
  21. default: 'cross'
  22. },
  23. closeIconPosition: {
  24. type: String,
  25. default: 'top-right'
  26. },
  27. position: {
  28. type: String,
  29. default: 'center'
  30. },
  31. overlay: {
  32. type: Boolean,
  33. default: true
  34. },
  35. closeOnClickOverlay: {
  36. type: Boolean,
  37. default: true
  38. }
  39. },
  40. beforeCreate: function beforeCreate() {
  41. var _this = this;
  42. var createEmitter = function createEmitter(eventName) {
  43. return function (event) {
  44. return _this.$emit(eventName, event);
  45. };
  46. };
  47. this.onClick = createEmitter('click');
  48. this.onOpened = createEmitter('opened');
  49. this.onClosed = createEmitter('closed');
  50. },
  51. methods: {
  52. onClickCloseIcon: function onClickCloseIcon(event) {
  53. this.$emit('click-close-icon', event);
  54. this.close();
  55. }
  56. },
  57. render: function render() {
  58. var _bem;
  59. var h = arguments[0];
  60. if (!this.shouldRender) {
  61. return;
  62. }
  63. var round = this.round,
  64. position = this.position,
  65. duration = this.duration;
  66. var isCenter = position === 'center';
  67. var transitionName = this.transition || (isCenter ? 'van-fade' : "van-popup-slide-" + position);
  68. var style = {};
  69. if ((0, _utils.isDef)(duration)) {
  70. var key = isCenter ? 'animationDuration' : 'transitionDuration';
  71. style[key] = duration + "s";
  72. }
  73. return h("transition", {
  74. "attrs": {
  75. "appear": this.transitionAppear,
  76. "name": transitionName
  77. },
  78. "on": {
  79. "afterEnter": this.onOpened,
  80. "afterLeave": this.onClosed
  81. }
  82. }, [h("div", {
  83. "directives": [{
  84. name: "show",
  85. value: this.value
  86. }],
  87. "style": style,
  88. "class": bem((_bem = {
  89. round: round
  90. }, _bem[position] = position, _bem['safe-area-inset-bottom'] = this.safeAreaInsetBottom, _bem)),
  91. "on": {
  92. "click": this.onClick
  93. }
  94. }, [this.slots(), this.closeable && h(_icon.default, {
  95. "attrs": {
  96. "role": "button",
  97. "tabindex": "0",
  98. "name": this.closeIcon
  99. },
  100. "class": bem('close-icon', this.closeIconPosition),
  101. "on": {
  102. "click": this.onClickCloseIcon
  103. }
  104. })])]);
  105. }
  106. });
  107. exports.default = _default;