项目中通常会运用
iconfont
作为图标显现的解决方案,这里引见下如安在项目中设置。
准备工作
起首设置好项目,症结须要注重FontClass/Symbol 前缀
和Font Family
两个设置。
当我们设置好项目以后,就能够导出款式文件,复制以下图中的css
链接中的内容备用。
正餐最先
建立Icon.js
文件。
import React from 'react';
import classNames from 'classnames';
import './iconfont.less';
// 上文中从iconfont中复制的css文件内容
import './icon.css';
const Icons = (props) => {
const {type, spin, className = '', ...others} = props;
const cls = classNames({
'unovo-iconfont': true,
[`unovo-iconfont-${type}`]: true,
'unovo-iconfont-spin': !!spin,
}, className);
return (
<i className={cls} {...others}/>
);
};
export default Icons;
建立iconfont.less
。
@keyframes icon-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@iconfont-css-prefix: unovo-iconfont;
.@{iconfont-css-prefix}-spin:before {
display: inline-block;
animation: icon-spin infinite 1s linear;
}
然后如许运用
<Icons type={type} spin />