popup.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. import { classNames } from '../common/utils';
  11. const { prefix } = config;
  12. const name = `${prefix}-popup`;
  13. const defaultTransitionProps = {
  14. name: `${name}--transition`,
  15. durations: [300, 300],
  16. appear: false,
  17. };
  18. let Popup = class Popup extends SuperComponent {
  19. constructor() {
  20. super(...arguments);
  21. this.externalClasses = ['t-class', 't-class-overlay', 't-class-content'];
  22. this.options = {
  23. multipleSlots: true,
  24. styleIsolation: 'shared',
  25. };
  26. this.properties = props;
  27. this.data = {
  28. prefix,
  29. classPrefix: name,
  30. className: name,
  31. dataTransitionProps: Object.assign({}, defaultTransitionProps),
  32. };
  33. this.lifetimes = {
  34. attached() {
  35. this.setClass();
  36. this.setTransitionProps();
  37. },
  38. };
  39. }
  40. setClass() {
  41. const { placement, showOverlay } = this.properties;
  42. const className = classNames(name, 't-class', `${name}--position-${placement}`, {
  43. [`${name}--overlay-transparent`]: !showOverlay,
  44. });
  45. this.setData({
  46. className,
  47. });
  48. }
  49. setTransitionProps() {
  50. if (!this.properties.transitionProps) {
  51. return;
  52. }
  53. const transitionProps = Object.assign(Object.assign({}, defaultTransitionProps), this.properties.transitionProps);
  54. this.setData({
  55. dataTransitionProps: transitionProps,
  56. });
  57. }
  58. onOverlayClick() {
  59. const { closeOnOverlayClick } = this.properties;
  60. if (closeOnOverlayClick) {
  61. this.triggerEvent('visible-change', { visible: false });
  62. }
  63. }
  64. onCloseClick() {
  65. this.triggerEvent('visible-change', { visible: false });
  66. }
  67. preventEvent() { }
  68. };
  69. Popup = __decorate([
  70. wxComponent()
  71. ], Popup);
  72. export default Popup;
  73. //# sourceMappingURL=popup.js.map