refactor: icon component

This commit is contained in:
chenjiahan
2020-07-04 22:39:13 +08:00
parent 425ffb87eb
commit 3bc6495b04
9 changed files with 611 additions and 8 deletions

55
src-next/icon/index.js Normal file
View File

@@ -0,0 +1,55 @@
// Utils
import { addUnit, isDef } from '../../src/utils';
import { createNamespace } from '../utils/create';
// Components
import Info from '../info';
const [createComponent, bem] = createNamespace('icon');
function isImage(name) {
return name ? name.indexOf('/') !== -1 : false;
}
export default createComponent({
props: {
dot: Boolean,
name: String,
size: [Number, String],
badge: [Number, String],
color: String,
tag: {
type: String,
default: 'i',
},
classPrefix: {
type: String,
default: bem(),
},
},
render() {
const { name } = this;
const imageIcon = isImage(name);
return (
<this.tag
class={[
this.classPrefix,
imageIcon ? '' : `${this.classPrefix}-${name}`,
]}
style={{
color: this.color,
fontSize: addUnit(this.size),
}}
>
{/* {slots.default && slots.default()} */}
{imageIcon && <img class={bem('image')} src={name} />}
<Info
dot={this.dot}
info={this.badge}
/>
</this.tag>
);
}
});