[new feature] Icon: add tag prop (#2986)
This commit is contained in:
@@ -62,7 +62,7 @@ import 'vant/lib/icon/local.css';
|
||||
| color | Icon color | `String` | `inherit` |
|
||||
| size | Icon size | `String` | `inherit` |
|
||||
| class-prefix | ClassName prefix | `String` | `van-icon` |
|
||||
|
||||
| tag | HTML Tag | `String` | `i` |
|
||||
|
||||
### Event
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { CreateElement, RenderContext } from 'vue/types';
|
||||
import { DefaultSlots } from '../utils/use/sfc';
|
||||
|
||||
export type IconProps = {
|
||||
tag: keyof HTMLElementTagNameMap;
|
||||
name: string;
|
||||
size?: string;
|
||||
color?: string;
|
||||
@@ -30,7 +31,7 @@ function Icon(
|
||||
const urlIcon = isSrc(props.name);
|
||||
|
||||
return (
|
||||
<i
|
||||
<props.tag
|
||||
class={[
|
||||
props.classPrefix,
|
||||
urlIcon ? 'van-icon--image' : `${props.classPrefix}-${props.name}`
|
||||
@@ -44,7 +45,7 @@ function Icon(
|
||||
{slots.default && slots.default()}
|
||||
{urlIcon && <img src={props.name} />}
|
||||
<Info info={props.info} />
|
||||
</i>
|
||||
</props.tag>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,6 +54,10 @@ Icon.props = {
|
||||
size: String,
|
||||
color: String,
|
||||
info: [String, Number],
|
||||
tag: {
|
||||
type: String,
|
||||
default: 'i'
|
||||
},
|
||||
classPrefix: {
|
||||
type: String,
|
||||
default: 'van-icon'
|
||||
|
||||
@@ -14,3 +14,9 @@ exports[`render icon with url name 1`] = `
|
||||
<i class="van-icon van-icon--image"><img src="https://img.yzcdn.com/icon.jpg">
|
||||
<!----></i>
|
||||
`;
|
||||
|
||||
exports[`tag prop 1`] = `
|
||||
<div class="van-icon van-icon-undefined">
|
||||
<!---->
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -27,3 +27,12 @@ test('render icon default slot', () => {
|
||||
});
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('tag prop', () => {
|
||||
const wrapper = mount(Icon, {
|
||||
propsData: {
|
||||
tag: 'div'
|
||||
}
|
||||
});
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
@@ -65,10 +65,10 @@ import 'vant/lib/icon/local.css';
|
||||
| color | 图标颜色 | `String` | `inherit` | 1.1.3 |
|
||||
| size | 图标大小,如 `20px` `2em` | `String` | `inherit` | 1.1.15 |
|
||||
| class-prefix | 类名前缀 | `String` | `van-icon` | 1.2.1 |
|
||||
| tag | HTML 标签 | `String` | `i` | 1.6.10 |
|
||||
|
||||
### Event
|
||||
|
||||
| 事件名 | 说明 | 参数 |
|
||||
|------|------|------|
|
||||
| click | 点击图标时触发 | - |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user