mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[bugfix] Icon: should support render local image
This commit is contained in:
parent
6e4b82249b
commit
c6a32879ec
@ -1,7 +1,6 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
import { inherit } from '../utils/functional';
|
import { inherit } from '../utils/functional';
|
||||||
import Info from '../info';
|
import Info from '../info';
|
||||||
import { isSrc } from '../utils/validate/src';
|
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
@ -22,13 +21,17 @@ export type IconEvents = {
|
|||||||
|
|
||||||
const [sfc] = use('icon');
|
const [sfc] = use('icon');
|
||||||
|
|
||||||
|
function isImage(name?: string): boolean {
|
||||||
|
return name ? name.indexOf('/') !== -1 : false;
|
||||||
|
}
|
||||||
|
|
||||||
function Icon(
|
function Icon(
|
||||||
h: CreateElement,
|
h: CreateElement,
|
||||||
props: IconProps,
|
props: IconProps,
|
||||||
slots: DefaultSlots,
|
slots: DefaultSlots,
|
||||||
ctx: RenderContext<IconProps>
|
ctx: RenderContext<IconProps>
|
||||||
) {
|
) {
|
||||||
const urlIcon = isSrc(props.name);
|
const urlIcon = isImage(props.name);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<props.tag
|
<props.tag
|
||||||
|
@ -10,6 +10,11 @@ exports[`render icon with builtin icon name 1`] = `
|
|||||||
<!----></i>
|
<!----></i>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`render icon with local image 1`] = `
|
||||||
|
<i class="van-icon van-icon--image"><img src="/assets/icon.jpg">
|
||||||
|
<!----></i>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`render icon with url name 1`] = `
|
exports[`render icon with url name 1`] = `
|
||||||
<i class="van-icon van-icon--image"><img src="https://img.yzcdn.com/icon.jpg">
|
<i class="van-icon van-icon--image"><img src="https://img.yzcdn.com/icon.jpg">
|
||||||
<!----></i>
|
<!----></i>
|
||||||
|
@ -19,6 +19,15 @@ test('render icon with url name', () => {
|
|||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('render icon with local image', () => {
|
||||||
|
const wrapper = mount(Icon, {
|
||||||
|
propsData: {
|
||||||
|
name: '/assets/icon.jpg'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
test('render icon default slot', () => {
|
test('render icon default slot', () => {
|
||||||
const wrapper = mount({
|
const wrapper = mount({
|
||||||
render(h) {
|
render(h) {
|
||||||
|
@ -2,7 +2,6 @@ import { deepClone } from '../deep-clone';
|
|||||||
import { isAndroid, isDef, camelize, get } from '..';
|
import { isAndroid, isDef, camelize, get } from '..';
|
||||||
import { raf, cancel } from '../raf';
|
import { raf, cancel } from '../raf';
|
||||||
import { later } from '../../../test/utils';
|
import { later } from '../../../test/utils';
|
||||||
import { isSrc } from '../validate/src';
|
|
||||||
import { isEmail } from '../validate/email';
|
import { isEmail } from '../validate/email';
|
||||||
import { isMobile } from '../validate/mobile';
|
import { isMobile } from '../validate/mobile';
|
||||||
import { isNumber } from '../validate/number';
|
import { isNumber } from '../validate/number';
|
||||||
@ -77,16 +76,3 @@ test('is-number', () => {
|
|||||||
expect(isNumber('abc')).toBeFalsy();
|
expect(isNumber('abc')).toBeFalsy();
|
||||||
expect(isNumber('1b2')).toBeFalsy();
|
expect(isNumber('1b2')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is-src', () => {
|
|
||||||
expect(isSrc('http://img.cdn.com')).toBeTruthy();
|
|
||||||
expect(isSrc('https://img.cdn.com')).toBeTruthy();
|
|
||||||
expect(isSrc('//img.cdn.com')).toBeTruthy();
|
|
||||||
expect(isSrc('data:image/jpeg;base64,/9j/4AAQSkZ')).toBeTruthy();
|
|
||||||
expect(isSrc('img.cdn.com')).toBeFalsy();
|
|
||||||
expect(isSrc('name')).toBeFalsy();
|
|
||||||
expect(isSrc('')).toBeFalsy();
|
|
||||||
expect(isSrc('blob:http://img.cdn.com')).toBeTruthy();
|
|
||||||
expect(isSrc('blob:https://img.cdn.com')).toBeTruthy();
|
|
||||||
expect(isSrc('xdata:image/jpeg;base64,/9j/4AAQSkZ')).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
/**
|
|
||||||
* Is image source
|
|
||||||
*/
|
|
||||||
export function isSrc(url: string): boolean {
|
|
||||||
return /^(((blob:)?https?:)?\/\/|data:image)/.test(url);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user