mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 06:09:34 +08:00
149729e524
* feat: use @ant-design/icons@4.0 * feat: use createFromIconfontCN to make site works * feat: update doc for Icon * feat: use icon in component Alert * feat: use icon in component Avatar * feat: use icon in component Breadcrumb * feat: use icon in component Button * feat: use icon in component Cascader * feat: use icon in component Collapse * feat: use icon in component Datepicker * feat: use icon in component Dropdown * feat: use icon in component Form * feat: use icon in component Input * feat: use icon in component InputNumber * feat: use icon in component Layout * feat: use icon in component Mention * feat: use icon in component Message * feat: use icon in component Modal * feat: use icon in component Notification * feat: use icon in component PageHeader * feat: use icon in component Pagination * feat: use icon in component Popconfirm * feat: use icon in component Progress * feat: use icon in component Rate * feat: use icon in component Result * feat: use icon in component Select * feat: use icon in component Step * feat: use icon in component Switch * feat: use icon in component Table * feat: use icon in component Tab * feat: use icon in component Tag * feat: handle rest component which using Icon * fix: remove unused vars * feat: use latest alpha ant design icons * fix: failed test in uploadlist.test.js * test: update snapshot for icons * doc: add Icon for site * doc: use @ant-design/icons in site * chore: use latest icons * fix: tslint issue * fix: test cases * fix: types for react * fix: lint rules for import orders * fix: use @ant-design/icons@4.0.0-alpha.5 to avoid insert css in server render * fix: eslint error in demo/**.md * inject antd icons * update snapshot * fix site * doc: update docs * fix: code snippets icon in site * feat: use latest @ant-design/icons * fix: icon props in message
175 lines
5.0 KiB
JavaScript
175 lines
5.0 KiB
JavaScript
import React from 'react';
|
|
import DocumentTitle from 'react-document-title';
|
|
import { FormattedMessage, injectIntl } from 'react-intl';
|
|
import classNames from 'classnames';
|
|
import { Row, Col, Affix, Tooltip } from 'antd';
|
|
import { getChildren } from 'jsonml.js/lib/utils';
|
|
import Demo from './Demo';
|
|
import EditButton from './EditButton';
|
|
import Icon from '../Icon';
|
|
import { ping } from '../utils';
|
|
|
|
class ComponentDoc extends React.Component {
|
|
state = {
|
|
expandAll: false,
|
|
showRiddleButton: false,
|
|
};
|
|
|
|
componentDidMount() {
|
|
this.pingTimer = ping(status => {
|
|
if (status !== 'timeout' && status !== 'error') {
|
|
this.setState({
|
|
showRiddleButton: true,
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
const { location } = this.props;
|
|
const { location: nextLocation } = nextProps;
|
|
const { expandAll, showRiddleButton } = this.state;
|
|
const { expandAll: nextExpandAll, showRiddleButton: nextShowRiddleButton } = nextState;
|
|
|
|
if (
|
|
nextLocation.pathname === location.pathname &&
|
|
expandAll === nextExpandAll &&
|
|
showRiddleButton === nextShowRiddleButton
|
|
) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
clearTimeout(this.pingTimer);
|
|
}
|
|
|
|
handleExpandToggle = () => {
|
|
const { expandAll } = this.state;
|
|
this.setState({
|
|
expandAll: !expandAll,
|
|
});
|
|
};
|
|
|
|
render() {
|
|
const {
|
|
doc,
|
|
location,
|
|
intl: { locale },
|
|
utils,
|
|
demos,
|
|
} = this.props;
|
|
const { content, meta } = doc;
|
|
const demoValues = Object.keys(demos).map(key => demos[key]);
|
|
const { expandAll, showRiddleButton } = this.state;
|
|
|
|
const isSingleCol = meta.cols === 1;
|
|
const leftChildren = [];
|
|
const rightChildren = [];
|
|
const showedDemo = demoValues.some(demo => demo.meta.only)
|
|
? demoValues.filter(demo => demo.meta.only)
|
|
: demoValues.filter(demo => demo.preview);
|
|
showedDemo
|
|
.sort((a, b) => a.meta.order - b.meta.order)
|
|
.forEach((demoData, index) => {
|
|
const demoElem = (
|
|
<Demo
|
|
{...demoData}
|
|
key={demoData.meta.filename}
|
|
utils={utils}
|
|
expand={expandAll}
|
|
location={location}
|
|
/>
|
|
);
|
|
if (index % 2 === 0 || isSingleCol) {
|
|
leftChildren.push(demoElem);
|
|
} else {
|
|
rightChildren.push(demoElem);
|
|
}
|
|
});
|
|
const expandTriggerClass = classNames({
|
|
'code-box-expand-trigger': true,
|
|
'code-box-expand-trigger-active': expandAll,
|
|
});
|
|
|
|
const jumper = showedDemo.map(demo => {
|
|
const { title } = demo.meta;
|
|
const localizeTitle = title[locale] || title;
|
|
return (
|
|
<li key={demo.meta.id} title={localizeTitle}>
|
|
<a href={`#${demo.meta.id}`}>{localizeTitle}</a>
|
|
</li>
|
|
);
|
|
});
|
|
|
|
const { title, subtitle, filename } = meta;
|
|
const articleClassName = classNames({
|
|
'show-riddle-button': showRiddleButton,
|
|
});
|
|
return (
|
|
<DocumentTitle title={`${subtitle || ''} ${title[locale] || title} - Ant Design`}>
|
|
<article className={articleClassName}>
|
|
<Affix className="toc-affix" offsetTop={16}>
|
|
<ul id="demo-toc" className="toc">
|
|
{jumper}
|
|
</ul>
|
|
</Affix>
|
|
<section className="markdown">
|
|
<h1>
|
|
{title[locale] || title}
|
|
{!subtitle ? null : <span className="subtitle">{subtitle}</span>}
|
|
<EditButton
|
|
title={<FormattedMessage id="app.content.edit-page" />}
|
|
filename={filename}
|
|
/>
|
|
</h1>
|
|
{utils.toReactComponent(
|
|
['section', { className: 'markdown' }].concat(getChildren(content)),
|
|
)}
|
|
<h2>
|
|
<FormattedMessage id="app.component.examples" />
|
|
<Tooltip
|
|
title={
|
|
<FormattedMessage
|
|
id={`app.component.examples.${expandAll ? 'collpse' : 'expand'}`}
|
|
/>
|
|
}
|
|
>
|
|
<Icon
|
|
type={`${expandAll ? 'appstore' : 'appstore-o'}`}
|
|
className={expandTriggerClass}
|
|
onClick={this.handleExpandToggle}
|
|
/>
|
|
</Tooltip>
|
|
</h2>
|
|
</section>
|
|
<Row gutter={16}>
|
|
<Col
|
|
span={isSingleCol ? 24 : 12}
|
|
className={isSingleCol ? 'code-boxes-col-1-1' : 'code-boxes-col-2-1'}
|
|
>
|
|
{leftChildren}
|
|
</Col>
|
|
{isSingleCol ? null : (
|
|
<Col className="code-boxes-col-2-1" span={12}>
|
|
{rightChildren}
|
|
</Col>
|
|
)}
|
|
</Row>
|
|
{utils.toReactComponent(
|
|
[
|
|
'section',
|
|
{
|
|
className: 'markdown api-container',
|
|
},
|
|
].concat(getChildren(doc.api || ['placeholder'])),
|
|
)}
|
|
</article>
|
|
</DocumentTitle>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default injectIntl(ComponentDoc);
|