collapse.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/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. prefix,
  36. classPrefix: name,
  37. };
  38. this.observers = {
  39. 'value, expandMutex '() {
  40. this.updateExpanded();
  41. },
  42. };
  43. this.methods = {
  44. updateExpanded() {
  45. this.$children.forEach((child) => {
  46. child.updateExpanded(this.properties.value);
  47. });
  48. },
  49. switch(panelValue) {
  50. const { expandMutex, value: activeValues } = this.properties;
  51. let value = [];
  52. const hit = activeValues.indexOf(panelValue);
  53. if (hit > -1) {
  54. value = activeValues.filter((item) => item !== panelValue);
  55. }
  56. else {
  57. value = expandMutex ? [panelValue] : activeValues.concat(panelValue);
  58. }
  59. this._trigger('change', { value });
  60. },
  61. };
  62. }
  63. };
  64. Collapse = __decorate([
  65. wxComponent()
  66. ], Collapse);
  67. export default Collapse;