2017-08-15 17:17:59 +08:00
|
|
|
/* eslint jsx-a11y/no-noninteractive-element-interactions: 0 */
|
2016-02-29 14:08:40 +08:00
|
|
|
import React from 'react';
|
2016-05-27 11:48:08 +08:00
|
|
|
import ReactDOM from 'react-dom';
|
2019-08-08 12:35:48 +08:00
|
|
|
import { FormattedMessage, injectIntl } from 'react-intl';
|
2017-02-24 11:55:24 +08:00
|
|
|
import CopyToClipboard from 'react-copy-to-clipboard';
|
2016-03-25 15:03:53 +08:00
|
|
|
import classNames from 'classnames';
|
2017-12-29 17:02:45 +08:00
|
|
|
import LZString from 'lz-string';
|
2019-12-11 14:15:45 +08:00
|
|
|
import { Tooltip, Alert } from 'antd';
|
2019-11-28 12:34:33 +08:00
|
|
|
import { SnippetsOutlined, CheckOutlined, ThunderboltOutlined } from '@ant-design/icons';
|
2019-11-13 17:29:46 +08:00
|
|
|
import stackblitzSdk from '@stackblitz/sdk';
|
2019-06-23 12:49:28 +08:00
|
|
|
import CodePreview from './CodePreview';
|
|
|
|
import EditButton from '../EditButton';
|
|
|
|
import BrowserFrame from '../../BrowserFrame';
|
2020-06-28 22:41:59 +08:00
|
|
|
import CodeSandboxIcon from './CodeSandboxIcon';
|
|
|
|
import CodePenIcon from './CodePenIcon';
|
|
|
|
import RiddleIcon from './RiddleIcon';
|
2016-05-11 11:36:47 +08:00
|
|
|
|
2019-12-11 14:15:45 +08:00
|
|
|
const { ErrorBoundary } = Alert;
|
|
|
|
|
2017-12-29 17:02:45 +08:00
|
|
|
function compress(string) {
|
|
|
|
return LZString.compressToBase64(string)
|
|
|
|
.replace(/\+/g, '-') // Convert '+' to '-'
|
|
|
|
.replace(/\//g, '_') // Convert '/' to '_'
|
|
|
|
.replace(/=+$/, ''); // Remove ending '='
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:35:48 +08:00
|
|
|
class Demo extends React.Component {
|
2020-01-02 17:54:11 +08:00
|
|
|
iframeRef = React.createRef();
|
|
|
|
|
2020-06-28 22:41:59 +08:00
|
|
|
codeSandboxIconRef = React.createRef();
|
|
|
|
|
|
|
|
riddleIconRef = React.createRef();
|
|
|
|
|
|
|
|
codepenIconRef = React.createRef();
|
|
|
|
|
2018-08-02 16:25:47 +08:00
|
|
|
state = {
|
|
|
|
codeExpand: false,
|
|
|
|
copied: false,
|
|
|
|
copyTooltipVisible: false,
|
|
|
|
};
|
2016-03-01 14:53:32 +08:00
|
|
|
|
2017-01-13 14:59:14 +08:00
|
|
|
componentDidMount() {
|
|
|
|
const { meta, location } = this.props;
|
|
|
|
if (meta.id === location.hash.slice(1)) {
|
|
|
|
this.anchor.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-28 15:00:03 +08:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
const { codeExpand, copied, copyTooltipVisible } = this.state;
|
2020-07-06 12:11:37 +08:00
|
|
|
const { expand, theme, showRiddleButton } = this.props;
|
2018-12-07 16:17:45 +08:00
|
|
|
return (
|
|
|
|
(codeExpand || expand) !== (nextState.codeExpand || nextProps.expand) ||
|
|
|
|
copied !== nextState.copied ||
|
2019-12-18 20:06:36 +08:00
|
|
|
copyTooltipVisible !== nextState.copyTooltipVisible ||
|
2020-07-06 12:11:37 +08:00
|
|
|
nextProps.theme !== theme ||
|
|
|
|
nextProps.showRiddleButton !== showRiddleButton
|
2018-12-07 16:17:45 +08:00
|
|
|
);
|
2018-11-28 15:00:03 +08:00
|
|
|
}
|
|
|
|
|
2018-10-30 16:01:21 +08:00
|
|
|
getSourceCode() {
|
2019-12-09 23:26:27 +08:00
|
|
|
const { highlightedCodes } = this.props;
|
2018-10-31 13:15:40 +08:00
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
const div = document.createElement('div');
|
2019-12-09 23:26:27 +08:00
|
|
|
div.innerHTML = highlightedCodes.jsx;
|
2018-10-31 13:15:40 +08:00
|
|
|
return div.textContent;
|
|
|
|
}
|
|
|
|
return '';
|
2018-10-30 16:01:21 +08:00
|
|
|
}
|
|
|
|
|
2019-04-04 15:33:56 +08:00
|
|
|
handleCodeExpand = demo => {
|
2018-06-22 21:05:13 +08:00
|
|
|
const { codeExpand } = this.state;
|
|
|
|
this.setState({ codeExpand: !codeExpand });
|
2019-04-04 15:33:56 +08:00
|
|
|
this.track({
|
|
|
|
type: 'expand',
|
|
|
|
demo,
|
|
|
|
});
|
2018-12-07 16:17:45 +08:00
|
|
|
};
|
2016-03-25 15:03:53 +08:00
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
saveAnchor = anchor => {
|
2017-01-13 14:59:14 +08:00
|
|
|
this.anchor = anchor;
|
2018-12-07 16:17:45 +08:00
|
|
|
};
|
2017-01-13 14:59:14 +08:00
|
|
|
|
2019-04-04 15:33:56 +08:00
|
|
|
handleCodeCopied = demo => {
|
2017-03-02 15:08:42 +08:00
|
|
|
this.setState({ copied: true });
|
2019-04-04 15:33:56 +08:00
|
|
|
this.track({
|
|
|
|
type: 'copy',
|
|
|
|
demo,
|
|
|
|
});
|
2018-12-07 16:17:45 +08:00
|
|
|
};
|
2017-03-02 15:08:42 +08:00
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
onCopyTooltipVisibleChange = visible => {
|
2017-03-02 15:08:42 +08:00
|
|
|
if (visible) {
|
|
|
|
this.setState({
|
|
|
|
copyTooltipVisible: visible,
|
|
|
|
copied: false,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
copyTooltipVisible: visible,
|
|
|
|
});
|
2018-12-07 16:17:45 +08:00
|
|
|
};
|
2017-03-02 15:08:42 +08:00
|
|
|
|
2020-04-03 15:02:11 +08:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
2019-04-04 15:33:56 +08:00
|
|
|
track({ type, demo }) {
|
|
|
|
if (!window.gtag) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.gtag('event', 'demo', {
|
|
|
|
event_category: type,
|
|
|
|
event_label: demo,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-02 17:54:11 +08:00
|
|
|
handleIframeReady = () => {
|
|
|
|
const { theme, setIframeTheme } = this.props;
|
|
|
|
if (this.iframeRef.current) {
|
|
|
|
setIframeTheme(this.iframeRef.current, theme);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-29 14:08:40 +08:00
|
|
|
render() {
|
2017-10-09 13:23:20 +08:00
|
|
|
const { state } = this;
|
|
|
|
const { props } = this;
|
2019-06-23 12:49:28 +08:00
|
|
|
const {
|
|
|
|
meta,
|
|
|
|
src,
|
|
|
|
content,
|
|
|
|
preview,
|
|
|
|
highlightedCodes,
|
|
|
|
style,
|
|
|
|
highlightedStyle,
|
|
|
|
expand,
|
2019-08-12 13:34:23 +08:00
|
|
|
utils,
|
|
|
|
intl: { locale },
|
2019-12-18 20:06:36 +08:00
|
|
|
theme,
|
2020-06-28 22:41:59 +08:00
|
|
|
showRiddleButton,
|
2019-06-23 12:49:28 +08:00
|
|
|
} = props;
|
2019-08-12 13:34:23 +08:00
|
|
|
const { copied, copyTooltipVisible } = state;
|
2016-10-13 16:52:24 +08:00
|
|
|
if (!this.liveDemo) {
|
2018-12-07 16:17:45 +08:00
|
|
|
this.liveDemo = meta.iframe ? (
|
|
|
|
<BrowserFrame>
|
2020-01-02 17:54:11 +08:00
|
|
|
<iframe
|
|
|
|
ref={this.iframeRef}
|
|
|
|
onLoad={this.handleIframeReady}
|
|
|
|
src={src}
|
|
|
|
height={meta.iframe}
|
|
|
|
title="demo"
|
|
|
|
className="iframe-demo"
|
|
|
|
/>
|
2018-12-07 16:17:45 +08:00
|
|
|
</BrowserFrame>
|
|
|
|
) : (
|
|
|
|
preview(React, ReactDOM)
|
|
|
|
);
|
2016-10-13 16:52:24 +08:00
|
|
|
}
|
2019-08-08 12:35:48 +08:00
|
|
|
const codeExpand = this.state.codeExpand || expand;
|
2019-03-21 09:48:50 +08:00
|
|
|
const codeBoxClass = classNames('code-box', {
|
2016-03-25 15:03:53 +08:00
|
|
|
expand: codeExpand,
|
2019-03-21 09:48:50 +08:00
|
|
|
'code-box-debug': meta.debug,
|
2016-03-25 15:03:53 +08:00
|
|
|
});
|
2016-05-27 11:48:08 +08:00
|
|
|
const localizedTitle = meta.title[locale] || meta.title;
|
|
|
|
const localizeIntro = content[locale] || content;
|
2019-08-08 12:35:48 +08:00
|
|
|
const introChildren = utils.toReactComponent(['div'].concat(localizeIntro));
|
2016-05-27 11:48:08 +08:00
|
|
|
|
|
|
|
const highlightClass = classNames({
|
|
|
|
'highlight-wrapper': true,
|
|
|
|
'highlight-wrapper-expand': codeExpand,
|
|
|
|
});
|
2017-07-07 16:09:02 +08:00
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
const prefillStyle = `@import 'antd/dist/antd.css';\n\n${style || ''}`.replace(
|
|
|
|
new RegExp(`#${meta.id}\\s*`, 'g'),
|
|
|
|
'',
|
|
|
|
);
|
2020-03-17 21:17:49 +08:00
|
|
|
const html = `<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
|
|
<meta name="theme-color" content="#000000">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="container" style="padding: 24px" />
|
|
|
|
<script>var mountNode = document.getElementById('container');</script>
|
|
|
|
</body>
|
|
|
|
</html>`;
|
2017-07-10 22:17:52 +08:00
|
|
|
|
2018-10-30 16:01:21 +08:00
|
|
|
const sourceCode = this.getSourceCode();
|
|
|
|
|
2017-07-07 16:09:02 +08:00
|
|
|
const codepenPrefillConfig = {
|
|
|
|
title: `${localizedTitle} - Ant Design Demo`,
|
2017-12-29 17:02:45 +08:00
|
|
|
html,
|
2018-10-30 16:01:21 +08:00
|
|
|
js: sourceCode
|
2020-04-03 15:02:11 +08:00
|
|
|
.replace(/import\s+{(\s+[^}]*\s+)}\s+from\s+'antd';/, 'const { $1 } = antd;')
|
2020-05-18 13:51:56 +08:00
|
|
|
.replace(/import\s+{(\s+[^}]*\s+)}\s+from\s+'@ant-design\/icons';/, 'const { $1 } = icons;')
|
2018-11-06 16:35:21 +08:00
|
|
|
.replace("import moment from 'moment';", '')
|
2020-04-03 15:02:11 +08:00
|
|
|
.replace(/import\s+{\s+(.*)\s+}\s+from\s+'react-router';/, 'const { $1 } = ReactRouter;')
|
2018-12-07 16:17:45 +08:00
|
|
|
.replace(
|
2020-04-03 15:02:11 +08:00
|
|
|
/import\s+{\s+(.*)\s+}\s+from\s+'react-router-dom';/,
|
2018-12-07 16:17:45 +08:00
|
|
|
'const { $1 } = ReactRouterDOM;',
|
|
|
|
)
|
2020-04-03 15:02:11 +08:00
|
|
|
.replace(/([A-Za-z]*)\s+as\s+([A-Za-z]*)/, '$1:$2'),
|
2017-07-10 22:17:52 +08:00
|
|
|
css: prefillStyle,
|
2017-07-07 16:09:02 +08:00
|
|
|
editors: '001',
|
2020-02-10 17:55:45 +08:00
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
css_external: `https://unpkg.com/antd@${antdReproduceVersion}/dist/antd.css`,
|
2017-07-07 16:09:02 +08:00
|
|
|
js_external: [
|
2018-08-27 13:28:41 +08:00
|
|
|
'react@16.x/umd/react.development.js',
|
|
|
|
'react-dom@16.x/umd/react-dom.development.js',
|
2017-07-07 16:09:02 +08:00
|
|
|
'moment/min/moment-with-locales.js',
|
2020-02-10 17:55:45 +08:00
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
`antd@${antdReproduceVersion}/dist/antd-with-locales.js`,
|
2020-03-01 18:22:53 +08:00
|
|
|
`@ant-design/icons/dist/index.umd.js`,
|
2018-11-06 16:35:21 +08:00
|
|
|
'react-router-dom/umd/react-router-dom.min.js',
|
|
|
|
'react-router@3.x/umd/ReactRouter.min.js',
|
2018-12-07 16:17:45 +08:00
|
|
|
]
|
|
|
|
.map(url => `https://unpkg.com/${url}`)
|
|
|
|
.join(';'),
|
2017-07-07 16:09:02 +08:00
|
|
|
js_pre_processor: 'typescript',
|
|
|
|
};
|
2017-07-10 22:17:52 +08:00
|
|
|
const riddlePrefillConfig = {
|
|
|
|
title: `${localizedTitle} - Ant Design Demo`,
|
2018-10-30 16:01:21 +08:00
|
|
|
js: sourceCode,
|
2017-07-10 22:17:52 +08:00
|
|
|
css: prefillStyle,
|
|
|
|
};
|
2018-12-07 16:17:45 +08:00
|
|
|
const dependencies = sourceCode.split('\n').reduce(
|
|
|
|
(acc, line) => {
|
|
|
|
const matches = line.match(/import .+? from '(.+)';$/);
|
2018-12-20 16:47:11 +08:00
|
|
|
if (matches && matches[1] && !line.includes('antd')) {
|
2020-02-10 17:55:45 +08:00
|
|
|
const paths = matches[1].split('/');
|
|
|
|
|
|
|
|
if (paths.length) {
|
|
|
|
const dep = paths[0].startsWith('@') ? `${paths[0]}/${paths[1]}` : paths[0];
|
2019-05-10 15:45:51 +08:00
|
|
|
acc[dep] = 'latest';
|
|
|
|
}
|
2018-12-07 16:17:45 +08:00
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
},
|
2019-12-13 15:49:52 +08:00
|
|
|
// eslint-disable-next-line no-undef
|
2020-03-17 21:17:49 +08:00
|
|
|
{ antd: antdReproduceVersion },
|
2018-12-07 16:17:45 +08:00
|
|
|
);
|
2020-01-22 12:11:49 +08:00
|
|
|
|
2020-03-01 18:22:53 +08:00
|
|
|
dependencies['@ant-design/icons'] = 'latest';
|
2020-02-10 17:55:45 +08:00
|
|
|
|
2020-01-22 12:11:49 +08:00
|
|
|
// Reorder source code
|
|
|
|
let parsedSourceCode = sourceCode;
|
|
|
|
let importReactContent = "import React from 'react';";
|
|
|
|
|
|
|
|
const importReactReg = /import(\D*)from 'react';/;
|
|
|
|
const matchImportReact = parsedSourceCode.match(importReactReg);
|
|
|
|
if (matchImportReact) {
|
2020-06-08 18:01:50 +08:00
|
|
|
[importReactContent] = matchImportReact;
|
2020-01-22 12:11:49 +08:00
|
|
|
parsedSourceCode = parsedSourceCode.replace(importReactReg, '').trim();
|
|
|
|
}
|
|
|
|
|
2019-11-13 17:29:46 +08:00
|
|
|
const indexJsContent = `
|
2020-01-21 18:17:53 +08:00
|
|
|
${importReactContent}
|
2017-12-29 17:02:45 +08:00
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import 'antd/dist/antd.css';
|
|
|
|
import './index.css';
|
2020-01-22 12:11:49 +08:00
|
|
|
${parsedSourceCode.replace('mountNode', "document.getElementById('container')")}
|
|
|
|
`.trim();
|
2020-05-18 13:51:56 +08:00
|
|
|
const indexCssContent = (style || '')
|
|
|
|
.trim()
|
|
|
|
.replace(new RegExp(`#${meta.id}\\s*`, 'g'), '')
|
|
|
|
.replace('</style>', '')
|
|
|
|
.replace('<style>', '');
|
2020-03-17 21:17:49 +08:00
|
|
|
|
|
|
|
const codesandboxPackage = {
|
|
|
|
name: `${localizedTitle} - Ant Design Demo`,
|
|
|
|
version: '1.0.0',
|
|
|
|
main: 'index.js',
|
|
|
|
dependencies: {
|
|
|
|
...dependencies,
|
|
|
|
react: '^16.12.0',
|
|
|
|
'react-dom': '^16.12.0',
|
|
|
|
'react-scripts': '^3.0.1',
|
|
|
|
},
|
|
|
|
devDependencies: {
|
|
|
|
typescript: '^3.8.2',
|
|
|
|
},
|
|
|
|
scripts: {
|
|
|
|
start: 'react-scripts start',
|
|
|
|
build: 'react-scripts build',
|
|
|
|
test: 'react-scripts test --env=jsdom',
|
|
|
|
eject: 'react-scripts eject',
|
|
|
|
},
|
|
|
|
browserslist: ['>0.2%', 'not dead', 'not ie <= 11', 'not op_mini all'],
|
|
|
|
};
|
2019-11-13 17:29:46 +08:00
|
|
|
const codesanboxPrefillConfig = {
|
|
|
|
files: {
|
2020-03-17 21:17:49 +08:00
|
|
|
'package.json': { content: codesandboxPackage },
|
2019-11-13 17:29:46 +08:00
|
|
|
'index.css': { content: indexCssContent },
|
|
|
|
'index.js': { content: indexJsContent },
|
2017-12-29 17:02:45 +08:00
|
|
|
'index.html': {
|
|
|
|
content: html,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2019-11-13 17:29:46 +08:00
|
|
|
const stackblitzPrefillConfig = {
|
|
|
|
title: `${localizedTitle} - Ant Design Demo`,
|
|
|
|
template: 'create-react-app',
|
|
|
|
dependencies,
|
|
|
|
files: {
|
|
|
|
'index.css': indexCssContent,
|
|
|
|
'index.js': indexJsContent,
|
|
|
|
'index.html': html,
|
|
|
|
},
|
|
|
|
};
|
2016-02-29 14:08:40 +08:00
|
|
|
return (
|
2019-12-23 17:16:26 +08:00
|
|
|
<section className={codeBoxClass} id={meta.id}>
|
2016-02-29 14:08:40 +08:00
|
|
|
<section className="code-box-demo">
|
2018-12-07 16:17:45 +08:00
|
|
|
<ErrorBoundary>{this.liveDemo}</ErrorBoundary>
|
2020-05-18 13:51:56 +08:00
|
|
|
{style ? <style dangerouslySetInnerHTML={{ __html: style }} /> : null}
|
2016-02-29 14:08:40 +08:00
|
|
|
</section>
|
|
|
|
<section className="code-box-meta markdown">
|
|
|
|
<div className="code-box-title">
|
2019-03-21 09:48:50 +08:00
|
|
|
<Tooltip title={meta.debug ? <FormattedMessage id="app.demo.debug" /> : ''}>
|
|
|
|
<a href={`#${meta.id}`} ref={this.saveAnchor}>
|
|
|
|
{localizedTitle}
|
|
|
|
</a>
|
|
|
|
</Tooltip>
|
2018-12-07 16:17:45 +08:00
|
|
|
<EditButton
|
2019-04-03 16:27:10 +08:00
|
|
|
title={<FormattedMessage id="app.content.edit-demo" />}
|
2018-12-07 16:17:45 +08:00
|
|
|
filename={meta.filename}
|
|
|
|
/>
|
2016-02-29 14:08:40 +08:00
|
|
|
</div>
|
2019-04-03 16:27:10 +08:00
|
|
|
<div className="code-box-description">{introChildren}</div>
|
2019-03-21 09:48:50 +08:00
|
|
|
<div className="code-box-actions">
|
2020-06-28 22:41:59 +08:00
|
|
|
{showRiddleButton ? (
|
|
|
|
<form
|
|
|
|
className="code-box-code-action"
|
|
|
|
action="//riddle.alibaba-inc.com/riddles/define"
|
|
|
|
method="POST"
|
|
|
|
target="_blank"
|
|
|
|
ref={this.riddleIconRef}
|
|
|
|
onClick={() => {
|
|
|
|
this.track({ type: 'riddle', demo: meta.id });
|
|
|
|
this.riddleIconRef.current.submit();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<input type="hidden" name="data" value={JSON.stringify(riddlePrefillConfig)} />
|
|
|
|
<Tooltip title={<FormattedMessage id="app.demo.riddle" />}>
|
|
|
|
<RiddleIcon className="code-box-riddle" />
|
|
|
|
</Tooltip>
|
|
|
|
</form>
|
|
|
|
) : null}
|
2019-04-04 15:33:56 +08:00
|
|
|
<form
|
2020-06-28 22:41:59 +08:00
|
|
|
className="code-box-code-action"
|
2020-04-01 11:11:59 +08:00
|
|
|
action="https://codesandbox.io/api/v1/sandboxes/define"
|
|
|
|
method="POST"
|
|
|
|
target="_blank"
|
2020-06-28 22:41:59 +08:00
|
|
|
ref={this.codeSandboxIconRef}
|
|
|
|
onClick={() => {
|
|
|
|
this.track({ type: 'codesandbox', demo: meta.id });
|
|
|
|
this.codeSandboxIconRef.current.submit();
|
|
|
|
}}
|
2020-04-01 11:11:59 +08:00
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="hidden"
|
|
|
|
name="parameters"
|
|
|
|
value={compress(JSON.stringify(codesanboxPrefillConfig))}
|
|
|
|
/>
|
2019-03-21 09:48:50 +08:00
|
|
|
<Tooltip title={<FormattedMessage id="app.demo.codesandbox" />}>
|
2020-06-28 22:41:59 +08:00
|
|
|
<CodeSandboxIcon className="code-box-codesandbox" />
|
2019-03-21 09:48:50 +08:00
|
|
|
</Tooltip>
|
|
|
|
</form>
|
2020-03-17 21:17:49 +08:00
|
|
|
<form
|
2020-06-28 22:41:59 +08:00
|
|
|
className="code-box-code-action"
|
2020-03-17 21:17:49 +08:00
|
|
|
action="https://codepen.io/pen/define"
|
|
|
|
method="POST"
|
|
|
|
target="_blank"
|
2020-06-28 22:41:59 +08:00
|
|
|
ref={this.codepenIconRef}
|
|
|
|
onClick={() => {
|
|
|
|
this.track({ type: 'codepen', demo: meta.id });
|
|
|
|
this.codepenIconRef.current.submit();
|
|
|
|
}}
|
2020-03-17 21:17:49 +08:00
|
|
|
style={{
|
|
|
|
display: sourceCode ? '' : 'none',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<input type="hidden" name="data" value={JSON.stringify(codepenPrefillConfig)} />
|
|
|
|
<Tooltip title={<FormattedMessage id="app.demo.codepen" />}>
|
2020-06-28 22:41:59 +08:00
|
|
|
<CodePenIcon className="code-box-codepen" />
|
2020-03-17 21:17:49 +08:00
|
|
|
</Tooltip>
|
|
|
|
</form>
|
2019-11-13 17:29:46 +08:00
|
|
|
<Tooltip title={<FormattedMessage id="app.demo.stackblitz" />}>
|
|
|
|
<span
|
|
|
|
className="code-box-code-action"
|
|
|
|
onClick={() => {
|
2019-11-15 17:30:05 +08:00
|
|
|
this.track({ type: 'stackblitz', demo: meta.id });
|
2019-11-13 17:29:46 +08:00
|
|
|
stackblitzSdk.openProject(stackblitzPrefillConfig);
|
|
|
|
}}
|
|
|
|
>
|
2020-06-28 22:41:59 +08:00
|
|
|
<ThunderboltOutlined className="code-box-stackblitz" />
|
2019-11-13 17:29:46 +08:00
|
|
|
</span>
|
|
|
|
</Tooltip>
|
2019-04-04 15:33:56 +08:00
|
|
|
<CopyToClipboard text={sourceCode} onCopy={() => this.handleCodeCopied(meta.id)}>
|
2019-03-21 09:48:50 +08:00
|
|
|
<Tooltip
|
2019-08-08 12:35:48 +08:00
|
|
|
visible={copyTooltipVisible}
|
2019-03-21 09:48:50 +08:00
|
|
|
onVisibleChange={this.onCopyTooltipVisibleChange}
|
|
|
|
title={<FormattedMessage id={`app.demo.${copied ? 'copied' : 'copy'}`} />}
|
|
|
|
>
|
2019-11-28 12:34:33 +08:00
|
|
|
{React.createElement(
|
|
|
|
copied && copyTooltipVisible ? CheckOutlined : SnippetsOutlined,
|
|
|
|
{
|
2020-06-28 22:41:59 +08:00
|
|
|
className: 'code-box-code-copy code-box-code-action',
|
2019-11-28 12:34:33 +08:00
|
|
|
},
|
|
|
|
)}
|
2019-03-21 09:48:50 +08:00
|
|
|
</Tooltip>
|
|
|
|
</CopyToClipboard>
|
2019-04-03 16:27:10 +08:00
|
|
|
<Tooltip
|
|
|
|
title={<FormattedMessage id={`app.demo.code.${codeExpand ? 'hide' : 'show'}`} />}
|
|
|
|
>
|
2020-06-28 22:41:59 +08:00
|
|
|
<span className="code-expand-icon code-box-code-action">
|
2019-03-21 09:48:50 +08:00
|
|
|
<img
|
|
|
|
alt="expand code"
|
2019-12-23 16:36:40 +08:00
|
|
|
src={
|
|
|
|
theme === 'dark'
|
2020-01-09 15:28:52 +08:00
|
|
|
? 'https://gw.alipayobjects.com/zos/antfincdn/btT3qDZn1U/wSAkBuJFbdxsosKKpqyq.svg'
|
2019-12-23 16:36:40 +08:00
|
|
|
: 'https://gw.alipayobjects.com/zos/rmsportal/wSAkBuJFbdxsosKKpqyq.svg'
|
|
|
|
}
|
2019-03-21 09:48:50 +08:00
|
|
|
className={codeExpand ? 'code-expand-icon-hide' : 'code-expand-icon-show'}
|
2019-04-04 15:33:56 +08:00
|
|
|
onClick={() => this.handleCodeExpand(meta.id)}
|
2019-03-21 09:48:50 +08:00
|
|
|
/>
|
|
|
|
<img
|
|
|
|
alt="expand code"
|
2019-12-23 16:36:40 +08:00
|
|
|
src={
|
|
|
|
theme === 'dark'
|
2020-01-09 15:28:52 +08:00
|
|
|
? 'https://gw.alipayobjects.com/zos/antfincdn/CjZPwcKUG3/OpROPHYqWmrMDBFMZtKF.svg'
|
2019-12-23 16:36:40 +08:00
|
|
|
: 'https://gw.alipayobjects.com/zos/rmsportal/OpROPHYqWmrMDBFMZtKF.svg'
|
|
|
|
}
|
2019-03-21 09:48:50 +08:00
|
|
|
className={codeExpand ? 'code-expand-icon-show' : 'code-expand-icon-hide'}
|
2019-04-04 15:33:56 +08:00
|
|
|
onClick={() => this.handleCodeExpand(meta.id)}
|
2019-03-21 09:48:50 +08:00
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
2016-03-25 17:07:00 +08:00
|
|
|
</div>
|
2019-03-21 09:48:50 +08:00
|
|
|
</section>
|
|
|
|
<section className={highlightClass} key="code">
|
2019-06-23 12:49:28 +08:00
|
|
|
<CodePreview toReactComponent={props.utils.toReactComponent} codes={highlightedCodes} />
|
2018-12-07 16:17:45 +08:00
|
|
|
{highlightedStyle ? (
|
|
|
|
<div key="style" className="highlight">
|
|
|
|
<pre>
|
2019-01-29 18:14:03 +08:00
|
|
|
<code className="css" dangerouslySetInnerHTML={{ __html: highlightedStyle }} />
|
2018-12-07 16:17:45 +08:00
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2016-03-25 17:07:00 +08:00
|
|
|
</section>
|
2016-02-29 14:08:40 +08:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-08 12:35:48 +08:00
|
|
|
|
|
|
|
export default injectIntl(Demo);
|