[improvement] Icon: jsx (#2514)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { use } from '../utils';
|
||||
import Info from '../info';
|
||||
import isSrc from '../utils/validate/src';
|
||||
|
||||
const [sfc] = use('icon');
|
||||
|
||||
export default sfc({
|
||||
props: {
|
||||
name: String,
|
||||
size: String,
|
||||
color: String,
|
||||
info: [String, Number],
|
||||
classPrefix: {
|
||||
type: String,
|
||||
default: 'van-icon'
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
isSrc() {
|
||||
return isSrc(this.name);
|
||||
}
|
||||
},
|
||||
|
||||
render(h) {
|
||||
return (
|
||||
<i
|
||||
class={[
|
||||
this.classPrefix,
|
||||
this.isSrc ? 'van-icon--image' : `${this.classPrefix}-${this.name}`
|
||||
]}
|
||||
style={{
|
||||
color: this.color,
|
||||
fontSize: this.size
|
||||
}}
|
||||
{...{ on: this.$listeners }}
|
||||
>
|
||||
{this.$slots.default}
|
||||
{this.isSrc && <img src={name} />}
|
||||
<Info info={this.info} />
|
||||
</i>
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -1,52 +0,0 @@
|
||||
<template>
|
||||
<i
|
||||
v-on="$listeners"
|
||||
:class="[classPrefix, isSrc ? 'van-icon--image' : `${classPrefix}-${name}`]"
|
||||
:style="style"
|
||||
>
|
||||
<slot />
|
||||
<img
|
||||
v-if="isSrc"
|
||||
:src="name"
|
||||
>
|
||||
<van-info :info="info" />
|
||||
</i>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Info from '../info';
|
||||
import create from '../utils/create-basic';
|
||||
import isSrc from '../utils/validate/src';
|
||||
|
||||
export default create({
|
||||
name: 'icon',
|
||||
|
||||
components: {
|
||||
[Info.name]: Info
|
||||
},
|
||||
|
||||
props: {
|
||||
name: String,
|
||||
size: String,
|
||||
color: String,
|
||||
info: [String, Number],
|
||||
classPrefix: {
|
||||
type: String,
|
||||
default: 'van-icon'
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
style() {
|
||||
return {
|
||||
color: this.color,
|
||||
fontSize: this.size
|
||||
};
|
||||
},
|
||||
|
||||
isSrc() {
|
||||
return isSrc(this.name);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user