mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-10 19:19:20 +08:00
🐛 fix icons page 100% cpu usage
This commit is contained in:
parent
5ca7d75c0d
commit
68ce09be4e
@ -2,34 +2,20 @@ import React from 'react';
|
|||||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||||
import { Icon, Badge } from 'antd';
|
import { Icon, Badge } from 'antd';
|
||||||
|
|
||||||
export default class CopyableIcon extends React.Component {
|
const CopyableIcon = ({ type, isNew, justCopied, onCopied }) => (
|
||||||
state = {
|
<CopyToClipboard
|
||||||
justCopied: false,
|
text={`<Icon type="${type}" />`}
|
||||||
};
|
onCopy={() => onCopied(type)}
|
||||||
|
>
|
||||||
|
<li className={justCopied === type ? 'copied' : ''}>
|
||||||
|
<Icon type={type} />
|
||||||
|
<span className="anticon-class">
|
||||||
|
<Badge dot={isNew}>
|
||||||
|
{type}
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</CopyToClipboard>
|
||||||
|
);
|
||||||
|
|
||||||
onCopied = () => {
|
export default CopyableIcon;
|
||||||
this.setState({ justCopied: true }, () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
this.setState({ justCopied: false });
|
|
||||||
}, 2000);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { type, isNew } = this.props;
|
|
||||||
const { justCopied } = this.state;
|
|
||||||
const text = `<Icon type="${type}" />`;
|
|
||||||
return (
|
|
||||||
<CopyToClipboard text={text} onCopy={this.onCopied}>
|
|
||||||
<li className={justCopied ? 'copied' : ''}>
|
|
||||||
<Icon type={type} />
|
|
||||||
<span className="anticon-class">
|
|
||||||
<Badge dot={isNew}>
|
|
||||||
{type}
|
|
||||||
</Badge>
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
</CopyToClipboard>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -7,6 +7,18 @@ export default class IconSet extends React.Component {
|
|||||||
icons: [],
|
icons: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state = {
|
||||||
|
justCopied: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
onCopied = (type) => {
|
||||||
|
this.setState({ justCopied: type }, () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.setState({ justCopied: null });
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
icons = {
|
icons = {
|
||||||
direction: ['step-backward', 'step-forward', 'fast-backward', 'fast-forward', 'shrink', 'arrows-alt', 'down', 'up', 'left', 'right', 'caret-up', 'caret-down', 'caret-left', 'caret-right', 'up-circle', 'down-circle', 'left-circle', 'right-circle', 'up-circle-o', 'down-circle-o', 'right-circle-o', 'left-circle-o', 'double-right', 'double-left', 'verticle-left', 'verticle-right', 'forward', 'backward', 'rollback', 'enter', 'retweet', 'swap', 'swap-left', 'swap-right', 'arrow-up', 'arrow-down', 'arrow-left', 'arrow-right', 'play-circle', 'play-circle-o', 'up-square', 'down-square', 'left-square', 'right-square', 'up-square-o', 'down-square-o', 'left-square-o', 'right-square-o', 'login', 'logout', 'menu-fold', 'menu-unfold'],
|
direction: ['step-backward', 'step-forward', 'fast-backward', 'fast-forward', 'shrink', 'arrows-alt', 'down', 'up', 'left', 'right', 'caret-up', 'caret-down', 'caret-left', 'caret-right', 'up-circle', 'down-circle', 'left-circle', 'right-circle', 'up-circle-o', 'down-circle-o', 'right-circle-o', 'left-circle-o', 'double-right', 'double-left', 'verticle-left', 'verticle-right', 'forward', 'backward', 'rollback', 'enter', 'retweet', 'swap', 'swap-left', 'swap-right', 'arrow-up', 'arrow-down', 'arrow-left', 'arrow-right', 'play-circle', 'play-circle-o', 'up-square', 'down-square', 'left-square', 'right-square', 'up-square-o', 'down-square-o', 'left-square-o', 'right-square-o', 'login', 'logout', 'menu-fold', 'menu-unfold'],
|
||||||
suggestion: ['question', 'question-circle-o', 'question-circle', 'plus', 'plus-circle-o', 'plus-circle', 'pause', 'pause-circle-o', 'pause-circle', 'minus', 'minus-circle-o', 'minus-circle', 'plus-square', 'plus-square-o', 'minus-square', 'minus-square-o', 'info', 'info-circle-o', 'info-circle', 'exclamation', 'exclamation-circle-o', 'exclamation-circle', 'close', 'close-circle', 'close-circle-o', 'close-square', 'close-square-o', 'check', 'check-circle', 'check-circle-o', 'check-square', 'check-square-o', 'clock-circle-o', 'clock-circle', 'warning'],
|
suggestion: ['question', 'question-circle-o', 'question-circle', 'plus', 'plus-circle-o', 'plus-circle', 'pause', 'pause-circle-o', 'pause-circle', 'minus', 'minus-circle-o', 'minus-circle', 'plus-square', 'plus-square-o', 'minus-square', 'minus-square-o', 'info', 'info-circle-o', 'info-circle', 'exclamation', 'exclamation-circle-o', 'exclamation-circle', 'close', 'close-circle', 'close-circle-o', 'close-square', 'close-square-o', 'check', 'check-circle', 'check-circle-o', 'check-square', 'check-square-o', 'clock-circle-o', 'clock-circle', 'warning'],
|
||||||
@ -24,6 +36,7 @@ export default class IconSet extends React.Component {
|
|||||||
];
|
];
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { justCopied } = this.state;
|
||||||
const { className, catigory } = this.props;
|
const { className, catigory } = this.props;
|
||||||
const listClassName = classNames({
|
const listClassName = classNames({
|
||||||
'anticons-list': true,
|
'anticons-list': true,
|
||||||
@ -33,7 +46,13 @@ export default class IconSet extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<ul className={listClassName}>
|
<ul className={listClassName}>
|
||||||
{this.icons[catigory].map(type => (
|
{this.icons[catigory].map(type => (
|
||||||
<CopyableIcon key={type} type={type} isNew={this.newIcons.indexOf(type) >= 0} />
|
<CopyableIcon
|
||||||
|
key={type}
|
||||||
|
type={type}
|
||||||
|
isNew={this.newIcons.indexOf(type) >= 0}
|
||||||
|
justCopied={justCopied}
|
||||||
|
onCopied={this.onCopied}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user