index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { createNamespace } from '../utils';
  3. import { route, routeProps } from '../utils/router';
  4. import { ChildrenMixin } from '../mixins/relation';
  5. import Info from '../info';
  6. import Icon from '../icon';
  7. var _createNamespace = createNamespace('goods-action-icon'),
  8. createComponent = _createNamespace[0],
  9. bem = _createNamespace[1];
  10. export default createComponent({
  11. mixins: [ChildrenMixin('vanGoodsAction')],
  12. props: _extends({}, routeProps, {
  13. dot: Boolean,
  14. text: String,
  15. icon: String,
  16. color: String,
  17. // @deprecated
  18. info: [Number, String],
  19. badge: [Number, String],
  20. iconClass: null
  21. }),
  22. methods: {
  23. onClick: function onClick(event) {
  24. this.$emit('click', event);
  25. route(this.$router, this);
  26. },
  27. genIcon: function genIcon() {
  28. var _this$badge;
  29. var h = this.$createElement;
  30. var slot = this.slots('icon');
  31. var info = (_this$badge = this.badge) != null ? _this$badge : this.info;
  32. if (process.env.NODE_ENV === 'development' && this.info) {
  33. console.warn('[Vant] GoodsActionIcon: "info" prop is deprecated, use "badge" prop instead.');
  34. }
  35. if (slot) {
  36. return h("div", {
  37. "class": bem('icon')
  38. }, [slot, h(Info, {
  39. "attrs": {
  40. "dot": this.dot,
  41. "info": info
  42. }
  43. })]);
  44. }
  45. return h(Icon, {
  46. "class": [bem('icon'), this.iconClass],
  47. "attrs": {
  48. "tag": "div",
  49. "dot": this.dot,
  50. "name": this.icon,
  51. "badge": info,
  52. "color": this.color
  53. }
  54. });
  55. }
  56. },
  57. render: function render() {
  58. var h = arguments[0];
  59. return h("div", {
  60. "attrs": {
  61. "role": "button",
  62. "tabindex": "0"
  63. },
  64. "class": bem(),
  65. "on": {
  66. "click": this.onClick
  67. }
  68. }, [this.genIcon(), this.slots() || this.text]);
  69. }
  70. });