Created
February 7, 2018 06:17
-
-
Save liuwenzhuang/e63fe9de0f30ef491c5b9009fb8ac4e8 to your computer and use it in GitHub Desktop.
React应用使用iconfont图标(使用CSS Modules)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 首先在http://iconfont.cn/新建图标项目,根据http://iconfont.cn/help/detail?spm=a313x.7781069.1998910419.d8cf4382a&helptype=code | |
* 文档下载配置相应字体文件、js文件、css文件等。 | |
* 使用方式: | |
* 单色图标:<IconFont type='ICON_NAME' /> | |
* 多色图标:<IconFont type='MULTI_COLOR_ICON' symbol /> | |
*/ | |
import PropTypes from 'prop-types'; | |
import styles from "./IconFont.less"; | |
const IconFont = ({type, symbol = false, className = '', ...other}) => { | |
return symbol ? | |
( | |
<svg className={`${styles.symbolIcon} ${className}`} {...other} aria-hidden="true"> | |
<use xlinkHref={`#icon-${type}`}></use> | |
</svg> | |
) : | |
(<i className={`iconfont icon-${type} ${className}`} {...other} />); | |
}; | |
IconFont.propTypes = { | |
type: PropTypes.string.isRequired, | |
symbol: PropTypes.bool, | |
className: PropTypes.string, | |
}; | |
export default IconFont; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:global(.symbolIcon) { | |
width: 1em; | |
height: 1em; | |
vertical-align: -0.15em; | |
fill: currentColor; | |
overflow: hidden; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment