1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
- // Utils
- import { createNamespace, addUnit } from '../utils';
- import { inherit } from '../utils/functional'; // Components
- import Info from '../info'; // Types
- var _createNamespace = createNamespace('icon'),
- createComponent = _createNamespace[0],
- bem = _createNamespace[1];
- function isImage(name) {
- return name ? name.indexOf('/') !== -1 : false;
- } // compatible with legacy usage, should be removed in next major version
- var LEGACY_MAP = {
- medel: 'medal',
- 'medel-o': 'medal-o',
- 'calender-o': 'calendar-o'
- };
- function correctName(name) {
- return name && LEGACY_MAP[name] || name;
- }
- function Icon(h, props, slots, ctx) {
- var _props$badge;
- var name = correctName(props.name);
- var imageIcon = isImage(name);
- if (process.env.NODE_ENV === 'development' && props.info) {
- console.warn('[Vant] Icon: "info" prop is deprecated, use "badge" prop instead.');
- }
- return h(props.tag, _mergeJSXProps([{
- "class": [props.classPrefix, imageIcon ? '' : props.classPrefix + "-" + name],
- "style": {
- color: props.color,
- fontSize: addUnit(props.size)
- }
- }, inherit(ctx, true)]), [slots.default && slots.default(), imageIcon && h("img", {
- "class": bem('image'),
- "attrs": {
- "src": name
- }
- }), h(Info, {
- "attrs": {
- "dot": props.dot,
- "info": (_props$badge = props.badge) != null ? _props$badge : props.info
- }
- })]);
- }
- Icon.props = {
- dot: Boolean,
- name: String,
- size: [Number, String],
- // @deprecated
- // should be removed in next major version
- info: [Number, String],
- badge: [Number, String],
- color: String,
- tag: {
- type: String,
- default: 'i'
- },
- classPrefix: {
- type: String,
- default: bem()
- }
- };
- export default createComponent(Icon);
|