index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. parentBorder: true,
  30. },
  31. mounted: function () {
  32. this.updateExpanded();
  33. this.mounted = true;
  34. },
  35. methods: {
  36. updateExpanded: function () {
  37. if (!this.parent) {
  38. return;
  39. }
  40. var _a = this.parent.data, value = _a.value, accordion = _a.accordion, border = _a.border;
  41. var _b = this.parent.children, children = _b === void 0 ? [] : _b;
  42. var name = this.data.name;
  43. var index = children.indexOf(this);
  44. var currentName = name == null ? index : name;
  45. var expanded = accordion
  46. ? value === currentName
  47. : (value || []).some(function (name) { return name === currentName; });
  48. if (expanded !== this.data.expanded) {
  49. (0, animate_1.setContentAnimate)(this, expanded, this.mounted);
  50. }
  51. this.setData({ index: index, expanded: expanded, parentBorder: border });
  52. },
  53. onClick: function () {
  54. if (this.data.disabled) {
  55. return;
  56. }
  57. var _a = this.data, name = _a.name, expanded = _a.expanded;
  58. var index = this.parent.children.indexOf(this);
  59. var currentName = name == null ? index : name;
  60. this.parent.switch(currentName, !expanded);
  61. },
  62. },
  63. });