mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-21 15:04:26 +00:00
enable the custom ClassName
This commit is contained in:
@@ -1,21 +1,38 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import classnames from 'classnames'
|
||||
import './iconfont.less'
|
||||
|
||||
const Iconfont = ({ type, colorful }) => {
|
||||
const Iconfont = ({ type, colorful, className }) => {
|
||||
const propsClassName = className;
|
||||
|
||||
const csSvg = classnames(
|
||||
{ 'colorful-icon': true },
|
||||
{ [`${propsClassName}`]: className !== undefined },
|
||||
);
|
||||
|
||||
if (colorful) {
|
||||
return (<span
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `<svg class="colorful-icon" aria-hidden="true"><use xlink:href="#${type.startsWith('#') ? type.replace(/#/, '') : type}"></use></svg>`,
|
||||
}}
|
||||
/>)
|
||||
return (
|
||||
<svg className={csSvg} aria-hidden="true">
|
||||
<use xlinkHref={`#${type.startsWith('#') ? type.replace(/#/, '') : type}`} />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
return <i className={`antdadmin icon-${type}`} />
|
||||
const csFont = classnames(
|
||||
{ antdadmin: true },
|
||||
{ [`icon-${type}`]: true },
|
||||
{ [`${propsClassName}`]: className !== undefined },
|
||||
);
|
||||
return <i className={csFont} />;
|
||||
}
|
||||
|
||||
Iconfont.propTypes = {
|
||||
type: PropTypes.string,
|
||||
type: PropTypes.string.isRequired,
|
||||
colorful: PropTypes.bool,
|
||||
}
|
||||
|
||||
Iconfont.defaultProps = {
|
||||
colorful: false,
|
||||
}
|
||||
|
||||
export default Iconfont
|
||||
|
||||
Reference in New Issue
Block a user