docs: fix Tag demo (#24245)

close #24231
This commit is contained in:
偏右 2020-05-18 13:51:56 +08:00 committed by GitHub
parent b10f4cffd9
commit 551763e768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 25 deletions

View File

@ -232,12 +232,17 @@ Array [
`; `;
exports[`renders ./components/tag/demo/colorful.md correctly 1`] = ` exports[`renders ./components/tag/demo/colorful.md correctly 1`] = `
<div> Array [
<h4 <div
style="margin-bottom:16px" class="ant-divider ant-divider-horizontal ant-divider-with-text ant-divider-with-text-left"
role="separator"
> >
Presets: <span
</h4> class="ant-divider-inner-text"
>
Presets
</span>
</div>,
<div> <div>
<span <span
class="ant-tag ant-tag-magenta" class="ant-tag ant-tag-magenta"
@ -294,12 +299,17 @@ exports[`renders ./components/tag/demo/colorful.md correctly 1`] = `
> >
purple purple
</span> </span>
</div> </div>,
<h4 <div
style="margin:16px 0" class="ant-divider ant-divider-horizontal ant-divider-with-text ant-divider-with-text-left"
role="separator"
> >
Custom: <span
</h4> class="ant-divider-inner-text"
>
Custom
</span>
</div>,
<div> <div>
<span <span
class="ant-tag ant-tag-has-color" class="ant-tag ant-tag-has-color"
@ -325,8 +335,8 @@ exports[`renders ./components/tag/demo/colorful.md correctly 1`] = `
> >
#108ee9 #108ee9
</span> </span>
</div> </div>,
</div> ]
`; `;
exports[`renders ./components/tag/demo/control.md correctly 1`] = ` exports[`renders ./components/tag/demo/control.md correctly 1`] = `

View File

@ -14,11 +14,11 @@ title:
We preset a series of colorful tag styles for use in different situations. You can also set it to a hex color string for custom color. We preset a series of colorful tag styles for use in different situations. You can also set it to a hex color string for custom color.
```jsx ```jsx
import { Tag } from 'antd'; import { Tag, Divider } from 'antd';
ReactDOM.render( ReactDOM.render(
<div> <>
<h4 style={{ marginBottom: 16 }}>Presets:</h4> <Divider orientation="left">Presets</Divider>
<div> <div>
<Tag color="magenta">magenta</Tag> <Tag color="magenta">magenta</Tag>
<Tag color="red">red</Tag> <Tag color="red">red</Tag>
@ -32,14 +32,14 @@ ReactDOM.render(
<Tag color="geekblue">geekblue</Tag> <Tag color="geekblue">geekblue</Tag>
<Tag color="purple">purple</Tag> <Tag color="purple">purple</Tag>
</div> </div>
<h4 style={{ margin: '16px 0' }}>Custom:</h4> <Divider orientation="left">Custom</Divider>
<div> <div>
<Tag color="#f50">#f50</Tag> <Tag color="#f50">#f50</Tag>
<Tag color="#2db7f5">#2db7f5</Tag> <Tag color="#2db7f5">#2db7f5</Tag>
<Tag color="#87d068">#87d068</Tag> <Tag color="#87d068">#87d068</Tag>
<Tag color="#108ee9">#108ee9</Tag> <Tag color="#108ee9">#108ee9</Tag>
</div> </div>
</div>, </>,
mountNode, mountNode,
); );
``` ```

View File

@ -181,10 +181,7 @@ class Demo extends React.Component {
html, html,
js: sourceCode js: sourceCode
.replace(/import\s+{(\s+[^}]*\s+)}\s+from\s+'antd';/, 'const { $1 } = antd;') .replace(/import\s+{(\s+[^}]*\s+)}\s+from\s+'antd';/, 'const { $1 } = antd;')
.replace( .replace(/import\s+{(\s+[^}]*\s+)}\s+from\s+'@ant-design\/icons';/, 'const { $1 } = icons;')
/import\s+{(\s+[^}]*\s+)}\s+from\s+'@ant-design\/icons';/,
'const { $1 } = icons;',
)
.replace("import moment from 'moment';", '') .replace("import moment from 'moment';", '')
.replace(/import\s+{\s+(.*)\s+}\s+from\s+'react-router';/, 'const { $1 } = ReactRouter;') .replace(/import\s+{\s+(.*)\s+}\s+from\s+'react-router';/, 'const { $1 } = ReactRouter;')
.replace( .replace(
@ -252,7 +249,11 @@ import 'antd/dist/antd.css';
import './index.css'; import './index.css';
${parsedSourceCode.replace('mountNode', "document.getElementById('container')")} ${parsedSourceCode.replace('mountNode', "document.getElementById('container')")}
`.trim(); `.trim();
const indexCssContent = (style || '').replace(new RegExp(`#${meta.id}\\s*`, 'g'), ''); const indexCssContent = (style || '')
.trim()
.replace(new RegExp(`#${meta.id}\\s*`, 'g'), '')
.replace('</style>', '')
.replace('<style>', '');
const codesandboxPackage = { const codesandboxPackage = {
name: `${localizedTitle} - Ant Design Demo`, name: `${localizedTitle} - Ant Design Demo`,
@ -299,9 +300,7 @@ ${parsedSourceCode.replace('mountNode', "document.getElementById('container')")}
<section className={codeBoxClass} id={meta.id}> <section className={codeBoxClass} id={meta.id}>
<section className="code-box-demo"> <section className="code-box-demo">
<ErrorBoundary>{this.liveDemo}</ErrorBoundary> <ErrorBoundary>{this.liveDemo}</ErrorBoundary>
{style ? ( {style ? <style dangerouslySetInnerHTML={{ __html: style }} /> : null}
<style dangerouslySetInnerHTML={{ __html: style }} />
) : null}
</section> </section>
<section className="code-box-meta markdown"> <section className="code-box-meta markdown">
<div className="code-box-title"> <div className="code-box-title">