index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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,
  39. value = _a.value,
  40. accordion = _a.accordion;
  41. var _b = this.parent.children,
  42. children = _b === void 0 ? [] : _b;
  43. var name = this.data.name;
  44. var index = children.indexOf(this);
  45. var currentName = name == null ? index : name;
  46. var expanded = accordion
  47. ? value === currentName
  48. : (value || []).some(function (name) {
  49. return name === currentName;
  50. });
  51. if (expanded !== this.data.expanded) {
  52. animate_1.setContentAnimate(this, expanded, this.mounted);
  53. }
  54. this.setData({ index: index, expanded: expanded });
  55. },
  56. onClick: function () {
  57. if (this.data.disabled) {
  58. return;
  59. }
  60. var _a = this.data,
  61. name = _a.name,
  62. expanded = _a.expanded;
  63. var index = this.parent.children.indexOf(this);
  64. var currentName = name == null ? index : name;
  65. this.parent.switch(currentName, !expanded);
  66. },
  67. },
  68. });