mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 19:06:36 +08:00
feat(Toast): add iconSize option (#8338)
This commit is contained in:
parent
6877dabe6a
commit
7a14991b16
@ -97,7 +97,7 @@ import 'vant/lib/icon/local.css';
|
|||||||
| dot | 是否显示图标右上角小红点 | _boolean_ | `false` |
|
| dot | 是否显示图标右上角小红点 | _boolean_ | `false` |
|
||||||
| badge | 图标右上角徽标的内容 | _number \| string_ | - |
|
| badge | 图标右上角徽标的内容 | _number \| string_ | - |
|
||||||
| color | 图标颜色 | _string_ | `inherit` |
|
| color | 图标颜色 | _string_ | `inherit` |
|
||||||
| size | 图标大小,如 `20px` `2em`,默认单位为`px` | _number \| string_ | `inherit` |
|
| size | 图标大小,如 `20px` `2em`,默认单位为 `px` | _number \| string_ | `inherit` |
|
||||||
| class-prefix | 类名前缀,用于使用自定义图标 | _string_ | `van-icon` |
|
| class-prefix | 类名前缀,用于使用自定义图标 | _string_ | `van-icon` |
|
||||||
| tag | HTML 标签 | _string_ | `i` |
|
| tag | HTML 标签 | _string_ | `i` |
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ Toast.resetDefaultOptions('loading');
|
|||||||
| position | Can be set to `top` `middle` `bottom` | _string_ | `middle` |
|
| position | Can be set to `top` `middle` `bottom` | _string_ | `middle` |
|
||||||
| message | Message | _string_ | `''` |
|
| message | Message | _string_ | `''` |
|
||||||
| icon | Custom icon | _string_ | - |
|
| icon | Custom icon | _string_ | - |
|
||||||
|
| iconSize | Custom icon size | _number \| string_ | `36px` |
|
||||||
| iconPrefix | Icon className prefix | _string_ | `van-icon` |
|
| iconPrefix | Icon className prefix | _string_ | `van-icon` |
|
||||||
| overlay | Whether to show overlay | _boolean_ | `false` |
|
| overlay | Whether to show overlay | _boolean_ | `false` |
|
||||||
| forbidClick | Whether to forbid click background | _boolean_ | `false` |
|
| forbidClick | Whether to forbid click background | _boolean_ | `false` |
|
||||||
|
@ -166,6 +166,7 @@ Toast.resetDefaultOptions('loading');
|
|||||||
| position | 位置,可选值为 `top` `bottom` | _string_ | `middle` |
|
| position | 位置,可选值为 `top` `bottom` | _string_ | `middle` |
|
||||||
| message | 文本内容,支持通过`\n`换行 | _string_ | `''` | - |
|
| message | 文本内容,支持通过`\n`换行 | _string_ | `''` | - |
|
||||||
| icon | 自定义图标,支持传入[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - |
|
| icon | 自定义图标,支持传入[图标名称](#/zh-CN/icon)或图片链接 | _string_ | - |
|
||||||
|
| iconSize | 自定义图标大小,如 `20px` `2em`,默认单位为 `px` | _number \| string_ | `36px` |
|
||||||
| iconPrefix | 图标类名前缀,同 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
| iconPrefix | 图标类名前缀,同 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
||||||
| overlay | 是否显示背景遮罩层 | _boolean_ | `false` |
|
| overlay | 是否显示背景遮罩层 | _boolean_ | `false` |
|
||||||
| forbidClick | 是否禁止背景点击 | _boolean_ | `false` |
|
| forbidClick | 是否禁止背景点击 | _boolean_ | `false` |
|
||||||
|
@ -29,6 +29,7 @@ export default defineComponent({
|
|||||||
show: Boolean,
|
show: Boolean,
|
||||||
overlay: Boolean,
|
overlay: Boolean,
|
||||||
message: [Number, String],
|
message: [Number, String],
|
||||||
|
iconSize: [Number, String],
|
||||||
className: UnknownProp,
|
className: UnknownProp,
|
||||||
iconPrefix: String,
|
iconPrefix: String,
|
||||||
loadingType: String as PropType<LoadingType>,
|
loadingType: String as PropType<LoadingType>,
|
||||||
@ -89,6 +90,7 @@ export default defineComponent({
|
|||||||
return (
|
return (
|
||||||
<Icon
|
<Icon
|
||||||
name={icon || type}
|
name={icon || type}
|
||||||
|
size={props.iconSize}
|
||||||
class={bem('icon')}
|
class={bem('icon')}
|
||||||
classPrefix={iconPrefix}
|
classPrefix={iconPrefix}
|
||||||
/>
|
/>
|
||||||
|
@ -14,6 +14,7 @@ export type ToastOptions = {
|
|||||||
overlay?: boolean;
|
overlay?: boolean;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
teleport?: TeleportProps['to'];
|
teleport?: TeleportProps['to'];
|
||||||
|
iconSize?: number | string;
|
||||||
position?: ToastPosition;
|
position?: ToastPosition;
|
||||||
className?: unknown;
|
className?: unknown;
|
||||||
transition?: string;
|
transition?: string;
|
||||||
@ -36,6 +37,7 @@ const defaultOptions: ToastOptions = {
|
|||||||
onOpened: undefined,
|
onOpened: undefined,
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
teleport: 'body',
|
teleport: 'body',
|
||||||
|
iconSize: undefined,
|
||||||
iconPrefix: undefined,
|
iconPrefix: undefined,
|
||||||
position: 'middle',
|
position: 'middle',
|
||||||
transition: 'van-fade',
|
transition: 'van-fade',
|
||||||
|
@ -61,3 +61,16 @@ test('create a forbidClick toast', async () => {
|
|||||||
document.body.classList.contains('van-toast--unclickable')
|
document.body.classList.contains('van-toast--unclickable')
|
||||||
).toBeFalsy();
|
).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should change icon size when using icon-size prop', async () => {
|
||||||
|
const wrapper = mount(Toast, {
|
||||||
|
props: {
|
||||||
|
show: true,
|
||||||
|
icon: 'success',
|
||||||
|
iconSize: '10',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await later();
|
||||||
|
expect(wrapper.find('.van-icon').style.fontSize).toEqual('10px');
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user