index.js 1.8 KB

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