index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _babelHelperVueJsxMergeProps = _interopRequireDefault(require("@vue/babel-helper-vue-jsx-merge-props"));
  6. var _utils = require("../utils");
  7. var _functional = require("../utils/functional");
  8. var _info = _interopRequireDefault(require("../info"));
  9. // Utils
  10. // Components
  11. var _createNamespace = (0, _utils.createNamespace)('icon'),
  12. createComponent = _createNamespace[0],
  13. bem = _createNamespace[1];
  14. function isImage(name) {
  15. return name ? name.indexOf('/') !== -1 : false;
  16. } // compatible with legacy usage, should be removed in next major version
  17. var LEGACY_MAP = {
  18. medel: 'medal',
  19. 'medel-o': 'medal-o',
  20. 'calender-o': 'calendar-o'
  21. };
  22. function correctName(name) {
  23. return name && LEGACY_MAP[name] || name;
  24. }
  25. function Icon(h, props, slots, ctx) {
  26. var _props$badge;
  27. var name = correctName(props.name);
  28. var imageIcon = isImage(name);
  29. if (process.env.NODE_ENV === 'development' && props.info) {
  30. console.warn('[Vant] Icon: "info" prop is deprecated, use "badge" prop instead.');
  31. }
  32. return h(props.tag, (0, _babelHelperVueJsxMergeProps.default)([{
  33. "class": [props.classPrefix, imageIcon ? '' : props.classPrefix + "-" + name],
  34. "style": {
  35. color: props.color,
  36. fontSize: (0, _utils.addUnit)(props.size)
  37. }
  38. }, (0, _functional.inherit)(ctx, true)]), [slots.default && slots.default(), imageIcon && h("img", {
  39. "class": bem('image'),
  40. "attrs": {
  41. "src": name
  42. }
  43. }), h(_info.default, {
  44. "attrs": {
  45. "dot": props.dot,
  46. "info": (_props$badge = props.badge) != null ? _props$badge : props.info
  47. }
  48. })]);
  49. }
  50. Icon.props = {
  51. dot: Boolean,
  52. name: String,
  53. size: [Number, String],
  54. // @deprecated
  55. // should be removed in next major version
  56. info: [Number, String],
  57. badge: [Number, String],
  58. color: String,
  59. tag: {
  60. type: String,
  61. default: 'i'
  62. },
  63. classPrefix: {
  64. type: String,
  65. default: bem()
  66. }
  67. };
  68. var _default = createComponent(Icon);
  69. exports.default = _default;