fab.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 useCustomNavbar from '../mixins/using-custom-navbar';
  11. import { unitConvert, systemInfo } from '../common/utils';
  12. const { prefix } = config;
  13. const name = `${prefix}-fab`;
  14. const baseButtonProps = {
  15. size: 'large',
  16. shape: 'circle',
  17. theme: 'primary',
  18. tClass: `${prefix}-fab__button`,
  19. };
  20. let Fab = class Fab extends SuperComponent {
  21. constructor() {
  22. super(...arguments);
  23. this.behaviors = [useCustomNavbar];
  24. this.properties = props;
  25. this.externalClasses = [`class`, `${prefix}-class`, `${prefix}-class-button`];
  26. this.data = {
  27. prefix,
  28. classPrefix: name,
  29. buttonData: baseButtonProps,
  30. moveStyle: null,
  31. };
  32. this.observers = {
  33. 'buttonProps.**, icon, text, ariaLabel, yBounds'() {
  34. var _a;
  35. this.setData({
  36. buttonData: Object.assign(Object.assign(Object.assign(Object.assign({}, baseButtonProps), { shape: this.properties.text ? 'round' : 'circle', icon: this.properties.icon }), this.properties.buttonProps), { content: this.properties.text, ariaLabel: this.properties.ariaLabel }),
  37. }, (_a = this.computedSize) === null || _a === void 0 ? void 0 : _a.bind(this));
  38. },
  39. };
  40. this.methods = {
  41. onTplButtonTap(e) {
  42. this.triggerEvent('click', e);
  43. },
  44. onStart(e) {
  45. this.triggerEvent('dragstart', e.detail.e);
  46. },
  47. onMove(e) {
  48. const { yBounds } = this.properties;
  49. const { distanceTop } = this.data;
  50. const { x, y, rect } = e.detail;
  51. const maxX = systemInfo.windowWidth - rect.width;
  52. const maxY = systemInfo.windowHeight - Math.max(distanceTop, unitConvert(yBounds[0])) - rect.height;
  53. const right = Math.max(0, Math.min(x, maxX));
  54. const bottom = Math.max(0, unitConvert(yBounds[1]), Math.min(y, maxY));
  55. this.setData({
  56. moveStyle: `right: ${right}px; bottom: ${bottom}px;`,
  57. });
  58. },
  59. onEnd(e) {
  60. this.triggerEvent('dragend', e.detail.e);
  61. },
  62. computedSize() {
  63. var _a, _b;
  64. if (!this.properties.draggable)
  65. return;
  66. const insChild = this.selectComponent('#draggable');
  67. if ((_b = (_a = this.properties) === null || _a === void 0 ? void 0 : _a.yBounds) === null || _b === void 0 ? void 0 : _b[1]) {
  68. this.setData({ moveStyle: `bottom: ${unitConvert(this.properties.yBounds[1])}px` }, insChild.computedRect);
  69. }
  70. else {
  71. insChild.computedRect();
  72. }
  73. },
  74. };
  75. }
  76. };
  77. Fab = __decorate([
  78. wxComponent()
  79. ], Fab);
  80. export default Fab;