index.js 1.8 KB

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