Skip to content

Commit 292c0a8

Browse files
authored
fix(docs): some docs layout (#58)
* fix: Tag doc issue * chore: remove code block * fix: update Drawer doc * fix: some doc layout
1 parent d9cb8fc commit 292c0a8

19 files changed

Lines changed: 104 additions & 322 deletions

File tree

apps/docs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"codesandbox": "^2.2.3",
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
19-
"react-live": "^4.1.0",
2019
"react-router-dom": "^6.0.0",
2120
"react-runner": "^1.0.5"
2221
},

apps/docs/src/components/code-block/code-block.scss

Lines changed: 0 additions & 90 deletions
This file was deleted.

apps/docs/src/components/code-block/index.tsx

Lines changed: 0 additions & 135 deletions
This file was deleted.
File renamed without changes.

apps/docs/src/components/demo-block/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useCallback, useRef } from 'react';
22
import { useRunner } from 'react-runner';
33
import { Highlight, themes } from 'prism-react-renderer';
4-
import { LightCodeTheme, DarkCodeTheme } from '../code-block/code-theme';
4+
import { LightCodeTheme, DarkCodeTheme } from './code-theme';
55
import * as TinyDesign from '@tiny-design/react';
66
import * as TinyIcons from '@tiny-design/icons';
77
import CollapseTransition from '@tiny-design/react/collapse-transition';
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Highlight, Prism, PrismTheme } from 'prism-react-renderer';
2+
import { DarkCodeTheme, LightCodeTheme } from '../demo-block/code-theme';
3+
import { useTheme } from '@tiny-design/react';
4+
5+
// Register bash/shell grammar (not included in prism-react-renderer's default bundle)
6+
Prism.languages.bash = Prism.languages.shell = {
7+
comment: { pattern: /(^|[^"{\\$])#.*/, lookbehind: true },
8+
'shell-symbol': { pattern: /^\$(?=\s)/m, alias: 'punctuation' },
9+
string: [
10+
{ pattern: /\$'(?:[^'\\]|\\[\s\S])*'/, greedy: true },
11+
{ pattern: /(^|[^\\])"(?:[^"\\]|\\.)*"/, lookbehind: true, greedy: true },
12+
{ pattern: /(^|[^\\])'[^']*'/, lookbehind: true, greedy: true },
13+
],
14+
variable: [/\$\{[^}]+\}/, /\$\([^)]+\)/, /\$(?:\w+|[!#?*@_])/],
15+
keyword: /\b(?:if|then|else|elif|fi|for|do|done|case|esac|while|until|function|in|select|return|exit)\b/,
16+
function:
17+
/\b(?:npm|npx|node|yarn|pnpm|bun|git|curl|wget|mkdir|cp|mv|rm|ls|cat|grep|sed|awk|chmod|chown|sudo|apt|brew|pip|python|ruby|go|cargo|make|docker|cd|echo|export|source|touch)\b/,
18+
'flag': { pattern: /(^|\s)--?[\w-]+/, lookbehind: true, alias: 'keyword' },
19+
number: /\b\d+\b/,
20+
operator: /&&|\|\||[|;]/,
21+
punctuation: /[{}[\]()]/,
22+
};
23+
24+
export const HighlightedCode = ({ className, children }: { className: string, children: string }) => {
25+
const { resolvedTheme } = useTheme();
26+
const codeTheme = resolvedTheme === 'dark' ? DarkCodeTheme : LightCodeTheme;
27+
28+
let language = 'markup';
29+
if (className != null) {
30+
language = className.replace(/language-/, '');
31+
}
32+
33+
const code = String(children ?? '').trim();
34+
35+
return (
36+
<Highlight code={code} language={language} theme={codeTheme as PrismTheme}>
37+
{({ className: preClassName, style, tokens, getLineProps, getTokenProps }) => (
38+
<pre className={preClassName} style={{ ...style, padding: '10px 12px' }}>
39+
<code>
40+
{tokens.map((line, i) => {
41+
const { key: _lk, ...lineProps } = getLineProps({ line });
42+
return (
43+
<div key={i} {...lineProps}>
44+
{line.map((token, j) => {
45+
const { key: _tk, ...tokenProps } = getTokenProps({ token });
46+
return <span key={j} {...tokenProps} />;
47+
})}
48+
</div>
49+
);
50+
})}
51+
</code>
52+
</pre>
53+
)}
54+
</Highlight>
55+
);
56+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './HighlightedCode';

apps/docs/src/components/markdown-tag/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*/
44
import React from 'react';
55
import './md-tag.scss';
6-
import { CodeBlock } from '../code-block';
76
import { DemoBlock } from '../demo-block';
7+
import { HighlightedCode } from '../highlighted-code';
88

99
const slugifyLink = (name) => {
1010
if (name.includes(' ')) {
@@ -49,14 +49,14 @@ export const components = {
4949
const { className, children: code } = children.props;
5050
return (
5151
<div className="markdown__pre-container">
52-
<CodeBlock className={className} live>{code}</CodeBlock>
52+
<HighlightedCode className={className}>{code}</HighlightedCode>
5353
</div>
5454
);
5555
}
5656
return <div {...rest} className="markdown__pre-container">{children}</div>;
5757
},
5858
code: ({ className, ...props }) =>
59-
className ? <CodeBlock className={className} {...props} /> : <code {...props} className="markdown__inline-code" />,
59+
className ? <HighlightedCode className={className} {...props} /> : <code {...props} className="markdown__inline-code" />,
6060
// Customised tags (PascalCase for MDX v3 provider resolution)
6161
Layout: (props) => <div {...props} className="markdown__layout" />,
6262
Column: (props) => <div {...props} className="markdown__column" />,

packages/react/src/drawer/demo/Basic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function BasicDemo() {
1313
header="Basic Drawer"
1414
placement="right"
1515
onClose={() => setVisible(false)}
16-
open={visible}
16+
visible={visible}
1717
>
1818
<div>Some contents...</div>
1919
<div>Some contents...</div>

packages/react/src/drawer/demo/MultiLevel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function MultiLevelDemo() {
1515
size={520}
1616
closable={false}
1717
onClose={() => setVisible(false)}
18-
open={visible}
18+
visible={visible}
1919
>
2020
<Button btnType="primary" onClick={() => setChildVisible(true)}>
2121
Two-level drawer
@@ -25,7 +25,7 @@ export default function MultiLevelDemo() {
2525
size={320}
2626
closable={false}
2727
onClose={() => setChildVisible(false)}
28-
open={childVisible}
28+
visible={childVisible}
2929
>
3030
This is two-level drawer
3131
</Drawer>

0 commit comments

Comments
 (0)