index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  6. var _utils = require("../utils");
  7. var _relation = require("../mixins/relation");
  8. var _router = require("../utils/router");
  9. var _createNamespace = (0, _utils.createNamespace)('tab'),
  10. createComponent = _createNamespace[0],
  11. bem = _createNamespace[1];
  12. var _default = createComponent({
  13. mixins: [(0, _relation.ChildrenMixin)('vanTabs')],
  14. props: (0, _extends2.default)({}, _router.routeProps, {
  15. dot: Boolean,
  16. name: [Number, String],
  17. // @deprecated
  18. info: [Number, String],
  19. badge: [Number, String],
  20. title: String,
  21. titleStyle: null,
  22. titleClass: null,
  23. disabled: Boolean
  24. }),
  25. data: function data() {
  26. return {
  27. inited: false
  28. };
  29. },
  30. computed: {
  31. computedName: function computedName() {
  32. var _this$name;
  33. return (_this$name = this.name) != null ? _this$name : this.index;
  34. },
  35. isActive: function isActive() {
  36. var active = this.computedName === this.parent.currentName;
  37. if (active) {
  38. this.inited = true;
  39. }
  40. return active;
  41. }
  42. },
  43. watch: {
  44. title: function title() {
  45. this.parent.setLine();
  46. this.parent.scrollIntoView();
  47. },
  48. inited: function inited(val) {
  49. var _this = this;
  50. if (this.parent.lazyRender && val) {
  51. this.$nextTick(function () {
  52. _this.parent.$emit('rendered', _this.computedName, _this.title);
  53. });
  54. }
  55. }
  56. },
  57. render: function render(h) {
  58. var slots = this.slots,
  59. parent = this.parent,
  60. isActive = this.isActive;
  61. var slotContent = slots();
  62. if (process.env.NODE_ENV === 'development' && this.info) {
  63. console.warn('[Vant] Tab: "info" prop is deprecated, use "badge" prop instead.');
  64. }
  65. if (!slotContent && !parent.animated) {
  66. return;
  67. }
  68. var show = parent.scrollspy || isActive;
  69. var shouldRender = this.inited || parent.scrollspy || !parent.lazyRender;
  70. var Content = shouldRender ? slotContent : h();
  71. if (parent.animated) {
  72. return h("div", {
  73. "attrs": {
  74. "role": "tabpanel",
  75. "aria-hidden": !isActive
  76. },
  77. "class": bem('pane-wrapper', {
  78. inactive: !isActive
  79. })
  80. }, [h("div", {
  81. "class": bem('pane')
  82. }, [Content])]);
  83. }
  84. return h("div", {
  85. "directives": [{
  86. name: "show",
  87. value: show
  88. }],
  89. "attrs": {
  90. "role": "tabpanel"
  91. },
  92. "class": bem('pane')
  93. }, [Content]);
  94. }
  95. });
  96. exports.default = _default;