0
cnpm start
后是这样子
![](https://img.haomeiwen.com/i3004133/8dad728ddf1880b0.png)
没错,就是官网的样子,url路径即是文件夹路径,我之前都是复制页面上特殊的文字去找文件...
![](https://img.haomeiwen.com/i3004133/aa158c60ebd8e89c.png)
网页中的信息来自这个md文档,github显示的也是它
import { Helmet } from 'react-helmet-async';
import { FormattedMessage, injectIntl } from 'react-intl'; //多语言
import classNames from 'classnames';//处理类名
site\theme\template\Content\ComponentDoc.jsx
,这个文件用来组织文档内容在网页上的呈现方式
![](https://img.haomeiwen.com/i3004133/46d3f24e38c7372c.png)
这段代码是改变<title>
、<meta>
标签的,为了SEO
![](https://img.haomeiwen.com/i3004133/ea8ea5be480fc884.png)
这段代码生成右侧目录
![](https://img.haomeiwen.com/i3004133/d0b388ee3357b1df.png)
1
![](https://img.haomeiwen.com/i3004133/00bb094cc721c51d.png)
上面这部分以及方向性图标、提示建议性图标 等对应md中的
![](https://img.haomeiwen.com/i3004133/692f869eb0d8b001.png)
![](https://img.haomeiwen.com/i3004133/0974144e0938fc82.png)
fields.ts
![](https://img.haomeiwen.com/i3004133/e70746c0ad790697.png)
以数组形式承载 图标名称
arr.indexOf(n) === i
数组去重
![](https://img.haomeiwen.com/i3004133/849d89835b4796e6.png)
注意 下面的代码
export type Categories = typeof categories;
export type CategoriesKeys = keyof Categories;
![](https://img.haomeiwen.com/i3004133/19158ac0e70d4fc6.png)
![](https://img.haomeiwen.com/i3004133/f506ac1b0f6c97c3.png)
Category.tsx
绘制方向性图标 、提示建议性图标 等
![](https://img.haomeiwen.com/i3004133/e3d06e71cc541155.png)
难怪我搜索不到
'app.docs.components.icon.category.suggestion': '提示建议性图标',
![](https://img.haomeiwen.com/i3004133/67d5a323f789bf97.png)
justCopied
是用来控制样式的
这段代码 服务于 复制图标的效果
![](https://img.haomeiwen.com/i3004133/4dd331ad929a955b.png)
![](https://img.haomeiwen.com/i3004133/b688a604058a96f3.png)
在 CopyableIcon.tsx
中
import CopyToClipboard from 'react-copy-to-clipboard';
![](https://img.haomeiwen.com/i3004133/001c4844860db6ac.png)
注意React.createElement(allIcons[name])
import * as AntdIcons from '@ant-design/icons';
const allIcons: {
[key: string]: any;
} = AntdIcons;
直接 {allIcons[name]}
是不行的
这个组件用了Hooks
const CopyableIcon: React.FC<CopyableIconProps> = ({
而React.FC
的定义文件是
type FC<P = {}> = FunctionComponent<P>;
interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
propTypes?: WeakValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: Partial<P>;
displayName?: string;
}
我看了半天,才想到可以
CopyableIcon.defaultProps
index.tsx
中将上面的资源整合在一起
![](https://img.haomeiwen.com/i3004133/4ea24ac67b2b4607.png)
autoFocus={true}
导致点击"展开全部代码"滚动条会回到顶部
![](https://img.haomeiwen.com/i3004133/4e691a2669f74a73.png)
我在github上提了一个issue,因为这个问题足够清晰,感兴趣的小伙伴可以关注下大佬们如何解决问题,方便以后参与到开源社区的维护,Icon 图表-代码演示-点击"展开全部代码"滚动条会回到顶部
3
IconPicSearcher.tsx
就是那个搜索框
当您使用截图搜索时,会动态加载一个脚本
loadModel = () => {
const script = document.createElement('script');
script.onload = async () => {
await window.antdIconClassifier.load();
this.setState({ modelLoaded: true });
document.addEventListener('paste', this.onPaste);
};
script.src = 'https://cdn.jsdelivr.net/gh/lewis617/antd-icon-classifier@0.0/dist/main.js';
document.head.appendChild(script);
};
![](https://img.haomeiwen.com/i3004133/c74b44e20b19cbed.png)
还可以看到customRequest
的用法示例
uploadFile = (file: File) => {
this.setState(() => ({ loading: true }));
const reader: FileReader = new FileReader();
reader.onload = () => {
this.toImage(reader.result).then(this.predict);
this.setState(() => ({
fileList: [{ uid: 1, name: file.name, status: 'done', url: reader.result }],
}));
};
reader.readAsDataURL(file);
};
用Promise
避免传递回调函数 让实现更优雅,同时也是异步获取图片的示例代码
toImage = (url: any) => {
return new Promise(resolve => {
const img = new Image();
img.setAttribute('crossOrigin', 'anonymous');
img.src = url;
img.onload = function onload() {
resolve(img);
};
});
};
处理黏贴行为的示例代码
onPaste = (event: ClipboardEvent) => {
const items = event.clipboardData && event.clipboardData.items;
let file = null;
if (items && items.length) {
for (let i = 0; i < items.length; i += 1) {
if (items[i].type.indexOf('image') !== -1) {
file = items[i].getAsFile();
break;
}
}
}
if (file) this.uploadFile(file);
};
TS 扩展window
declare global {
interface Window {
antdIconClassifier: AntdIconClassifier;
}
}
如何正确的使用Spin
![](https://img.haomeiwen.com/i3004133/85899b80b997ae9e.png)
4
"代码演示" 部分在ComponentDoc.jsx
![](https://img.haomeiwen.com/i3004133/df0eb5ed54615081.png)
对应文件夹
![](https://img.haomeiwen.com/i3004133/54669c5b27893426.png)
也是通过md方式呈现的
ComponentDoc.jsx
展开折叠代码![](https://img.haomeiwen.com/i3004133/a6b9a755117bf4c9.png)
API、FAQ这些还是在index.zh-CN.md
表格
![](https://img.haomeiwen.com/i3004133/cd2c9ec30485fff5.png)
逻辑简单的直接写在md 中
![](https://img.haomeiwen.com/i3004133/af8a459002d2eee9.png)
完
我一直以为是叫antd ,知道今天才知道是叫ant,难怪之前在覆盖样式的时候第一次都不行...
在windows上跑起来antd遇到了很多困难,强烈建议使用cnpm
**如果包都安装完最后报的错先不理会,直接试一试cnpm run start能不能跑起来
这个过程还会报ess相关的错误,过程十分缓慢,甚至浏览器都提示网站无法连接...,只要脚本没退出就请耐心等待。
这些问题可能是前面一连串原因引起的,但是我根据报错信息提示的去解决,依然没用...
网友评论