index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 _router = require("../utils/router");
  8. var _relation = require("../mixins/relation");
  9. var _icon = _interopRequireDefault(require("../icon"));
  10. var _info = _interopRequireDefault(require("../info"));
  11. // Utils
  12. // Mixins
  13. // Components
  14. var _createNamespace = (0, _utils.createNamespace)('tabbar-item'),
  15. createComponent = _createNamespace[0],
  16. bem = _createNamespace[1];
  17. var _default = createComponent({
  18. mixins: [(0, _relation.ChildrenMixin)('vanTabbar')],
  19. props: (0, _extends2.default)({}, _router.routeProps, {
  20. dot: Boolean,
  21. icon: String,
  22. name: [Number, String],
  23. // @deprecated
  24. info: [Number, String],
  25. badge: [Number, String],
  26. iconPrefix: String
  27. }),
  28. data: function data() {
  29. return {
  30. active: false
  31. };
  32. },
  33. computed: {
  34. routeActive: function routeActive() {
  35. var to = this.to,
  36. $route = this.$route;
  37. if (to && $route) {
  38. var config = (0, _utils.isObject)(to) ? to : {
  39. path: to
  40. };
  41. var pathMatched = config.path === $route.path;
  42. var nameMatched = (0, _utils.isDef)(config.name) && config.name === $route.name;
  43. return pathMatched || nameMatched;
  44. }
  45. }
  46. },
  47. methods: {
  48. onClick: function onClick(event) {
  49. this.parent.onChange(this.name || this.index);
  50. this.$emit('click', event);
  51. (0, _router.route)(this.$router, this);
  52. },
  53. genIcon: function genIcon(active) {
  54. var h = this.$createElement;
  55. var slot = this.slots('icon', {
  56. active: active
  57. });
  58. if (slot) {
  59. return slot;
  60. }
  61. if (this.icon) {
  62. return h(_icon.default, {
  63. "attrs": {
  64. "name": this.icon,
  65. "classPrefix": this.iconPrefix
  66. }
  67. });
  68. }
  69. }
  70. },
  71. render: function render() {
  72. var _this$badge;
  73. var h = arguments[0];
  74. var active = this.parent.route ? this.routeActive : this.active;
  75. var color = this.parent[active ? 'activeColor' : 'inactiveColor'];
  76. if (process.env.NODE_ENV === 'development' && this.info) {
  77. console.warn('[Vant] TabbarItem: "info" prop is deprecated, use "badge" prop instead.');
  78. }
  79. return h("div", {
  80. "class": bem({
  81. active: active
  82. }),
  83. "style": {
  84. color: color
  85. },
  86. "on": {
  87. "click": this.onClick
  88. }
  89. }, [h("div", {
  90. "class": bem('icon')
  91. }, [this.genIcon(active), h(_info.default, {
  92. "attrs": {
  93. "dot": this.dot,
  94. "info": (_this$badge = this.badge) != null ? _this$badge : this.info
  95. }
  96. })]), h("div", {
  97. "class": bem('text')
  98. }, [this.slots('default', {
  99. active: active
  100. })])]);
  101. }
  102. });
  103. exports.default = _default;