-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
849 additions
and
18 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const importAll = (requireContext: __WebpackModuleApi.RequireContext) => requireContext.keys().forEach(requireContext); | ||
try { | ||
importAll(require.context('./svg', true, /\.svg$/)); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
export {}; // 默认导出,ts如若不导出,会警告 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## SvgIcon (Svg 图标) | ||
|
||
### 说明 | ||
|
||
- svg-sprite-loader 制作 svg-symbol, | ||
- 直接使用 svg-use。 | ||
- 使用 svgo-loader 优化 svg。 | ||
- 使 Icon 组件化,使用 require.context 一次引入所有文件。 | ||
|
||
### API | ||
|
||
| 属性 | 类型 | 默认值 | 说明 | | ||
| -------- | ------ | ------ | --------------------- | | ||
| svgName | string | 无 | svg 名字 (svg 文件名) | | ||
| svgClass | string | 无 | 样式类名 | | ||
| color | string | 无 | 填充颜色 | |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.svg-class { | ||
display: inline-block; | ||
width: 1em; | ||
min-width: 14px; | ||
height: 1em; | ||
overflow: hidden; | ||
font-size: 50px; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React, {FC} from 'react'; | ||
import './index.less'; | ||
|
||
interface SvgIconProps { | ||
svgName: string; // svg名字 | ||
svgClass?: string; // 自定义类名 | ||
color?: string; // 填充颜色 | ||
} | ||
|
||
const SvgIcon: FC<SvgIconProps> = (props) => { | ||
const {svgName, color, svgClass} = props; | ||
return ( | ||
<i aria-hidden='true'> | ||
<svg className={`svg-class ${svgClass}`}> | ||
<use xlinkHref={'#icon-' + svgName} fill={color} /> | ||
</svg> | ||
</i> | ||
); | ||
}; | ||
|
||
export default SvgIcon; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,8 @@ | |
font-size: 50px; | ||
background: #c6e2ff; | ||
border-radius: 10px; | ||
|
||
.icon-my { | ||
font-size: 100px; | ||
} | ||
} |
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
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
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
Oops, something went wrong.