diff --git a/packages/icon/index.less b/packages/icon/index.less index 2a10d872f..d5ba71728 100644 --- a/packages/icon/index.less +++ b/packages/icon/index.less @@ -2,19 +2,8 @@ @import '@vant/icons/src/index.less'; .van-icon { - &--image { + &__image { width: 1em; height: 1em; - - img { - position: absolute; - top: 0; - right: 0; - bottom: 0; - left: 0; - max-width: 100%; - max-height: 100%; - margin: auto; - } } } diff --git a/packages/icon/index.tsx b/packages/icon/index.tsx index 023cd0f42..8623e788e 100644 --- a/packages/icon/index.tsx +++ b/packages/icon/index.tsx @@ -1,6 +1,7 @@ import { use, suffixPx } from '../utils'; import { inherit } from '../utils/functional'; import Info from '../info'; +import Image from '../image'; // Types import { CreateElement, RenderContext } from 'vue/types'; @@ -19,7 +20,7 @@ export type IconEvents = { onClick?(event: Event): void; }; -const [sfc] = use('icon'); +const [sfc, bem] = use('icon'); function isImage(name?: string): boolean { return name ? name.indexOf('/') !== -1 : false; @@ -31,14 +32,11 @@ function Icon( slots: DefaultSlots, ctx: RenderContext ) { - const urlIcon = isImage(props.name); + const imageIcon = isImage(props.name); return ( {slots.default && slots.default()} - {urlIcon && } + {imageIcon && } ); @@ -63,7 +61,7 @@ Icon.props = { }, classPrefix: { type: String, - default: 'van-icon' + default: bem() } }; diff --git a/packages/icon/test/__snapshots__/index.spec.js.snap b/packages/icon/test/__snapshots__/index.spec.js.snap index 7383c5390..0b1ffa937 100644 --- a/packages/icon/test/__snapshots__/index.spec.js.snap +++ b/packages/icon/test/__snapshots__/index.spec.js.snap @@ -11,13 +11,23 @@ exports[`render icon with builtin icon name 1`] = ` `; exports[`render icon with local image 1`] = ` - - + +
+
+
+
+ +
`; exports[`render icon with url name 1`] = ` - - + +
+
+
+
+ +
`; exports[`size without unit 1`] = `