index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 _info = _interopRequireDefault(require("../info"));
  10. var _icon = _interopRequireDefault(require("../icon"));
  11. var _createNamespace = (0, _utils.createNamespace)('goods-action-icon'),
  12. createComponent = _createNamespace[0],
  13. bem = _createNamespace[1];
  14. var _default = createComponent({
  15. mixins: [(0, _relation.ChildrenMixin)('vanGoodsAction')],
  16. props: (0, _extends2.default)({}, _router.routeProps, {
  17. dot: Boolean,
  18. text: String,
  19. icon: String,
  20. color: String,
  21. // @deprecated
  22. info: [Number, String],
  23. badge: [Number, String],
  24. iconClass: null
  25. }),
  26. methods: {
  27. onClick: function onClick(event) {
  28. this.$emit('click', event);
  29. (0, _router.route)(this.$router, this);
  30. },
  31. genIcon: function genIcon() {
  32. var _this$badge;
  33. var h = this.$createElement;
  34. var slot = this.slots('icon');
  35. var info = (_this$badge = this.badge) != null ? _this$badge : this.info;
  36. if (process.env.NODE_ENV === 'development' && this.info) {
  37. console.warn('[Vant] GoodsActionIcon: "info" prop is deprecated, use "badge" prop instead.');
  38. }
  39. if (slot) {
  40. return h("div", {
  41. "class": bem('icon')
  42. }, [slot, h(_info.default, {
  43. "attrs": {
  44. "dot": this.dot,
  45. "info": info
  46. }
  47. })]);
  48. }
  49. return h(_icon.default, {
  50. "class": [bem('icon'), this.iconClass],
  51. "attrs": {
  52. "tag": "div",
  53. "dot": this.dot,
  54. "name": this.icon,
  55. "badge": info,
  56. "color": this.color
  57. }
  58. });
  59. }
  60. },
  61. render: function render() {
  62. var h = arguments[0];
  63. return h("div", {
  64. "attrs": {
  65. "role": "button",
  66. "tabindex": "0"
  67. },
  68. "class": bem(),
  69. "on": {
  70. "click": this.onClick
  71. }
  72. }, [this.genIcon(), this.slots() || this.text]);
  73. }
  74. });
  75. exports.default = _default;