mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 11:54:02 +00:00
refactor: icon component
This commit is contained in:
55
src-next/icon/index.js
Normal file
55
src-next/icon/index.js
Normal 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>
|
||||
);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user