index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. var relation_1 = require("../common/relation");
  5. var animate_1 = require("./animate");
  6. (0, component_1.VantComponent)({
  7. classes: ['title-class', 'content-class'],
  8. relation: (0, relation_1.useParent)('collapse'),
  9. props: {
  10. size: String,
  11. name: null,
  12. title: null,
  13. value: null,
  14. icon: String,
  15. label: String,
  16. disabled: Boolean,
  17. clickable: Boolean,
  18. border: {
  19. type: Boolean,
  20. value: true,
  21. },
  22. isLink: {
  23. type: Boolean,
  24. value: true,
  25. },
  26. },
  27. data: {
  28. expanded: false,
  29. },
  30. mounted: function () {
  31. this.updateExpanded();
  32. this.mounted = true;
  33. },
  34. methods: {
  35. updateExpanded: function () {
  36. if (!this.parent) {
  37. return;
  38. }
  39. var _a = this.parent.data, value = _a.value, accordion = _a.accordion;
  40. var _b = this.parent.children, children = _b === void 0 ? [] : _b;
  41. var name = this.data.name;
  42. var index = children.indexOf(this);
  43. var currentName = name == null ? index : name;
  44. var expanded = accordion
  45. ? value === currentName
  46. : (value || []).some(function (name) { return name === currentName; });
  47. if (expanded !== this.data.expanded) {
  48. (0, animate_1.setContentAnimate)(this, expanded, this.mounted);
  49. }
  50. this.setData({ index: index, expanded: expanded });
  51. },
  52. onClick: function () {
  53. if (this.data.disabled) {
  54. return;
  55. }
  56. var _a = this.data, name = _a.name, expanded = _a.expanded;
  57. var index = this.parent.children.indexOf(this);
  58. var currentName = name == null ? index : name;
  59. this.parent.switch(currentName, !expanded);
  60. },
  61. },
  62. });