mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Image): add icon-size prop (#8395)
This commit is contained in:
parent
49430a1ef6
commit
6d428345d7
@ -1,4 +1,3 @@
|
|||||||
// Utils
|
|
||||||
import {
|
import {
|
||||||
ref,
|
ref,
|
||||||
watch,
|
watch,
|
||||||
@ -9,6 +8,8 @@ import {
|
|||||||
defineComponent,
|
defineComponent,
|
||||||
getCurrentInstance,
|
getCurrentInstance,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
|
||||||
|
// Utils
|
||||||
import {
|
import {
|
||||||
isDef,
|
isDef,
|
||||||
addUnit,
|
addUnit,
|
||||||
@ -36,6 +37,7 @@ export default defineComponent({
|
|||||||
height: [Number, String],
|
height: [Number, String],
|
||||||
radius: [Number, String],
|
radius: [Number, String],
|
||||||
lazyLoad: Boolean,
|
lazyLoad: Boolean,
|
||||||
|
iconSize: [Number, String],
|
||||||
iconPrefix: String,
|
iconPrefix: String,
|
||||||
showError: {
|
showError: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@ -110,6 +112,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Icon
|
<Icon
|
||||||
|
size={props.iconSize}
|
||||||
name={props.loadingIcon}
|
name={props.loadingIcon}
|
||||||
class={bem('loading-icon')}
|
class={bem('loading-icon')}
|
||||||
classPrefix={props.iconPrefix}
|
classPrefix={props.iconPrefix}
|
||||||
@ -124,6 +127,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Icon
|
<Icon
|
||||||
|
size={props.iconSize}
|
||||||
name={props.errorIcon}
|
name={props.errorIcon}
|
||||||
class={bem('error-icon')}
|
class={bem('error-icon')}
|
||||||
classPrefix={props.iconPrefix}
|
classPrefix={props.iconPrefix}
|
||||||
|
@ -81,6 +81,7 @@ app.use(Lazyload);
|
|||||||
| show-loading | Whether to show loading placeholder | _boolean_ | `true` |
|
| show-loading | Whether to show loading placeholder | _boolean_ | `true` |
|
||||||
| error-icon | Error icon | _string_ | `photo-fail` |
|
| error-icon | Error icon | _string_ | `photo-fail` |
|
||||||
| loading-icon | Loading icon | _string_ | `photo` |
|
| loading-icon | Loading icon | _string_ | `photo` |
|
||||||
|
| icon-size `v3.0.11` | Icon size | _number \| string_ | `32px` |
|
||||||
| icon-prefix | Icon className prefix | _string_ | `van-icon` |
|
| icon-prefix | Icon className prefix | _string_ | `van-icon` |
|
||||||
|
|
||||||
### fit optional value
|
### fit optional value
|
||||||
|
@ -113,6 +113,7 @@ app.use(Lazyload);
|
|||||||
| show-loading | 是否展示图片加载中提示 | _boolean_ | `true` |
|
| show-loading | 是否展示图片加载中提示 | _boolean_ | `true` |
|
||||||
| error-icon | 失败时提示的[图标名称](#/zh-CN/icon)或图片链接 | _string_ | `photo-fail` |
|
| error-icon | 失败时提示的[图标名称](#/zh-CN/icon)或图片链接 | _string_ | `photo-fail` |
|
||||||
| loading-icon | 加载时提示的[图标名称](#/zh-CN/icon)或图片链接 | _string_ | `photo` |
|
| loading-icon | 加载时提示的[图标名称](#/zh-CN/icon)或图片链接 | _string_ | `photo` |
|
||||||
|
| icon-size `v3.0.11` | 加载图标和失败图标的大小 | _number \| string_ | `32px` |
|
||||||
| icon-prefix | 图标类名前缀,同 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
| icon-prefix | 图标类名前缀,同 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
||||||
|
|
||||||
### 图片填充模式
|
### 图片填充模式
|
||||||
|
@ -137,6 +137,30 @@ test('should change border radius when using border-radius prop', () => {
|
|||||||
expect(wrapper.style.borderRadius).toEqual('3px');
|
expect(wrapper.style.borderRadius).toEqual('3px');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should change loading icon size when using icon-size prop', () => {
|
||||||
|
const wrapper = mount(VanImage, {
|
||||||
|
props: {
|
||||||
|
iconSize: '3rem',
|
||||||
|
loadingIcon: 'success',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(wrapper.find('.van-image__loading-icon').style.fontSize).toEqual(
|
||||||
|
'3rem'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should change error icon size when using icon-size prop', async () => {
|
||||||
|
const wrapper = mount(VanImage, {
|
||||||
|
props: {
|
||||||
|
src: IMAGE_URL,
|
||||||
|
iconSize: '3rem',
|
||||||
|
errorIcon: 'error',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await wrapper.find('img').trigger('error');
|
||||||
|
expect(wrapper.find('.van-image__error-icon').style.fontSize).toEqual('3rem');
|
||||||
|
});
|
||||||
|
|
||||||
test('should render default slot correctly', () => {
|
test('should render default slot correctly', () => {
|
||||||
const wrapper = mount(VanImage, {
|
const wrapper = mount(VanImage, {
|
||||||
props: {
|
props: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user