index.js 2.0KB

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