collapse.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. const { prefix } = config;
  11. const name = `${prefix}-collapse`;
  12. let Collapse = class Collapse extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.options = {
  16. addGlobalClass: true,
  17. };
  18. this.externalClasses = [`${prefix}-class`];
  19. this.relations = {
  20. './collapse-panel': {
  21. type: 'descendant',
  22. linked() {
  23. // this.updateExpanded();
  24. },
  25. },
  26. };
  27. this.controlledProps = [
  28. {
  29. key: 'value',
  30. event: 'change',
  31. },
  32. ];
  33. this.properties = props;
  34. this.data = {
  35. classPrefix: name,
  36. };
  37. this.observers = {
  38. 'value, expandMutex '() {
  39. this.updateExpanded();
  40. },
  41. };
  42. this.methods = {
  43. updateExpanded() {
  44. const panels = this.getRelationNodes('./collapse-panel');
  45. if (panels.length === 0)
  46. return;
  47. panels.forEach((child) => {
  48. child.updateExpanded(this.properties.value);
  49. });
  50. },
  51. switch(panelValue) {
  52. const { expandMutex, value: activeValues } = this.properties;
  53. let value = [];
  54. const hit = activeValues.indexOf(panelValue);
  55. if (hit > -1) {
  56. value = activeValues.filter((item) => item !== panelValue);
  57. }
  58. else {
  59. value = expandMutex ? [panelValue] : activeValues.concat(panelValue);
  60. }
  61. this._trigger('change', { value });
  62. },
  63. };
  64. }
  65. };
  66. Collapse = __decorate([
  67. wxComponent()
  68. ], Collapse);
  69. export default Collapse;
  70. //# sourceMappingURL=collapse.js.map