-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added custom tag #15
added custom tag #15
Changes from 1 commit
305a560
b90c6f1
d32bfb0
b7fc68d
7100ba8
eedf47b
6e49379
eea1291
f281ec3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,21 +10,25 @@ interface IProps { | |
color?: string; | ||
size?: string; | ||
classPrefix?: string; | ||
tag?: string; | ||
tag?: 'a'; | ||
url?: string; | ||
replace: boolean; | ||
} | ||
|
||
const baseClass = 'vant-icon'; | ||
|
||
// TODO Accept custom tag element | ||
|
||
export default function Icon({ | ||
name, | ||
dot, | ||
badge, | ||
color, | ||
size, | ||
classPrefix = baseClass | ||
classPrefix = baseClass, | ||
tag, | ||
url, | ||
replace | ||
}: IProps) { | ||
const CustomTag = tag || 'a'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. custom icon tag should be 'i' by default |
||
const containerProps = { | ||
className: classnames(`${classPrefix}__container`, [ | ||
{ | ||
|
@@ -55,12 +59,26 @@ export default function Icon({ | |
} | ||
}); | ||
} | ||
if (url && tag === 'a') { | ||
Object.assign(iconProps, { | ||
href: url | ||
}); | ||
if (replace) { | ||
Object.assign(iconProps, { | ||
target: '_self' | ||
}); | ||
} else { | ||
Object.assign(iconProps, { | ||
target: '_blank' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these don't belong here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. I just think maybe one day we need the icon to be an 'a' tag. I will delete these codes. |
||
}); | ||
} | ||
} | ||
|
||
return ( | ||
<div {...containerProps}> | ||
<CustomTag {...containerProps}> | ||
<i {...iconProps} /> | ||
{dot && !badge && <span className={`${classPrefix}--dot`} />} | ||
{badge && <span className={`${classPrefix}--badge`}>{badge}</span>} | ||
</div> | ||
</CustomTag> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
icons shouldn't have url and replace