collapse.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.externalClasses = [`${prefix}-class`];
  16. this.relations = {
  17. '../collapse-panel/collapse-panel': {
  18. type: 'descendant',
  19. },
  20. };
  21. this.controlledProps = [
  22. {
  23. key: 'value',
  24. event: 'change',
  25. },
  26. ];
  27. this.properties = props;
  28. this.data = {
  29. prefix,
  30. classPrefix: name,
  31. };
  32. this.observers = {
  33. 'value, expandMutex '() {
  34. this.updateExpanded();
  35. },
  36. };
  37. this.methods = {
  38. updateExpanded() {
  39. this.$children.forEach((child) => {
  40. child.updateExpanded(this.properties.value);
  41. });
  42. },
  43. switch(panelValue) {
  44. const { expandMutex, value: activeValues } = this.properties;
  45. let value = [];
  46. const hit = activeValues.indexOf(panelValue);
  47. if (hit > -1) {
  48. value = activeValues.filter((item) => item !== panelValue);
  49. }
  50. else {
  51. value = expandMutex ? [panelValue] : activeValues.concat(panelValue);
  52. }
  53. this._trigger('change', { value });
  54. },
  55. };
  56. }
  57. };
  58. Collapse = __decorate([
  59. wxComponent()
  60. ], Collapse);
  61. export default Collapse;