diff --git a/package.json b/package.json
index 37005e0..82ed69e 100644
--- a/package.json
+++ b/package.json
@@ -36,6 +36,8 @@
},
"license": "MIT",
"devDependencies": {
+ "@types/react": "~18.2.0",
+ "@types/react-dom": "~18.2.0",
"react": "~18.2.0",
"react-dom": "~18.2.0",
"husky": "~9.1.6",
diff --git a/pkg-example/README.md b/pkg-example/README.md
index 0a3faea..f990352 100644
--- a/pkg-example/README.md
+++ b/pkg-example/README.md
@@ -1,6 +1,8 @@
Example
===
+Add an example of loading EMS package dependencies
+
```jsx mdx:preview
import React from "react";
import Example from 'pkg-example';
diff --git a/website/package.json b/website/package.json
index 80249f8..eab15bf 100644
--- a/website/package.json
+++ b/website/package.json
@@ -31,9 +31,8 @@
"@kkt/less-modules": "~7.5.5",
"@kkt/raw-modules": "~7.5.5",
"@kkt/scope-plugin-options": "~7.5.5",
- "@types/react": "^18.2.0",
- "@types/react-dom": "^18.2.0",
"kkt": "~7.5.5",
+ "pkg-example": "2.1.9",
"markdown-react-code-preview-loader": "2.1.9"
},
"eslintConfig": {
diff --git a/website/src/App.tsx b/website/src/App.tsx
index d9921f8..3ed47a6 100644
--- a/website/src/App.tsx
+++ b/website/src/App.tsx
@@ -3,6 +3,7 @@ import { HashRouter, Routes, Route } from 'react-router-dom';
import { Layout } from './Layout';
import { HomePage } from './pages/docs';
import { ExamplePage } from './pages/example';
+import { PkgExamplePage } from './pages/pkg';
export default function App() {
return (
@@ -11,6 +12,7 @@ export default function App() {
}>
} />
} />
+ } />
diff --git a/website/src/Layout.tsx b/website/src/Layout.tsx
index 7d60cc5..9db2383 100644
--- a/website/src/Layout.tsx
+++ b/website/src/Layout.tsx
@@ -19,6 +19,9 @@ export function Layout() {
{i18next.t('example')}
+
+ {i18next.t('pkg-example')}
+
diff --git a/website/src/language/locale/en.json b/website/src/language/locale/en.json
index 4f434b9..b416bd2 100644
--- a/website/src/language/locale/en.json
+++ b/website/src/language/locale/en.json
@@ -3,5 +3,6 @@
"zh": "chinese",
"en": "english",
"docuemnt": "Docuemnt",
- "example": "Example"
+ "example": "Example",
+ "pkg-example": "PKG Example"
}
diff --git a/website/src/language/locale/zh.json b/website/src/language/locale/zh.json
index d703f81..0a677b3 100644
--- a/website/src/language/locale/zh.json
+++ b/website/src/language/locale/zh.json
@@ -3,5 +3,6 @@
"zh": "中文",
"en": "英文",
"docuemnt": "文档",
- "example": "案例"
+ "example": "案例",
+ "pkg-example": "PKG 示例"
}
diff --git a/website/src/pages/example/App-zh.md b/website/src/pages/example/App-zh.md
index 3144227..de9da2b 100644
--- a/website/src/pages/example/App-zh.md
+++ b/website/src/pages/example/App-zh.md
@@ -16,58 +16,53 @@ import Alert from "@uiw/react-alert";
```jsx mdx:preview
import React from "react";
+import { useState } from 'react';
import ReactDOM from "react-dom";
import { Alert, ButtonGroup, Button } from "uiw";
-class Demo extends React.Component {
- constructor() {
- super();
- this.state = {
- visible1: false,
- visible2: false,
- };
- }
- onClick(type) {
- this.setState({ [type]: !this.state[type] });
- }
- onClosed(type) {
- this.setState({ [type]: false });
- }
- render() {
- return (
+export default function Demo() {
+ const [visible1, setVisible1] = useState(false);
+ const [visible2, setVisible2] = useState(false);
+ return (
{
+ setVisible1(false)
+ }}
content="这个对话框只有两个个按钮,单击“确定按钮”后,此对话框将关闭。用作通知用户重要信息。"
/>
console.log("您点击了确定按钮!")}
onCancel={() => console.log("您点击了取消按钮!")}
- onClosed={this.onClosed.bind(this, "visible2")}
+ onClosed={() => {
+ setVisible2(false)
+ }}
>
这个对话框有两个按钮,单击 “确定按钮” 或 “取消按钮”
后,此对话框将关闭,触发 “onConfirm” 或 “onCancel”
事件。用作通知用户重要信息。
-
- );
- }
+ )
}
-export default Demo;
```
## 延迟关闭对话框
diff --git a/website/src/pages/pkg/index.tsx b/website/src/pages/pkg/index.tsx
new file mode 100644
index 0000000..9014b81
--- /dev/null
+++ b/website/src/pages/pkg/index.tsx
@@ -0,0 +1,64 @@
+import React from 'react';
+import { FC, PropsWithChildren, useRef } from 'react';
+import MarkdownPreview from '@uiw/react-markdown-preview';
+import { getMetaId, getURLParameters, CodeBlockData } from 'markdown-react-code-preview-loader';
+
+import { Root, Element, RootContent } from 'hast';
+import MDSource from 'pkg-example/README.md';
+import CodeLayout from 'react-code-preview-layout';
+
+const Preview = CodeLayout.Preview;
+const Code = CodeLayout.Code;
+const Toolbar = CodeLayout.Toolbar;
+
+interface CodePreviewProps {
+ mdData?: CodeBlockData;
+ 'data-meta'?: string;
+}
+
+const CodePreview: FC> = (props) => {
+ const $dom = useRef(null);
+ // @ts-ignore
+ const { mdData, node, 'data-meta': meta, ...rest } = props;
+ // @ts-ignore
+ const line = node?.position?.start.line;
+ const metaId = getMetaId(meta) || String(line);
+ const Child = mdData?.components[`${metaId}`];
+ if (metaId && typeof Child === 'function') {
+ const code = mdData?.data[metaId].value || '';
+ const param = getURLParameters(meta || '');
+ return (
+
+
+
+
+ {param.title || 'Example'}
+
+
+
+
+ );
+ }
+ return
;
+};
+
+export function PkgExamplePage() {
+ return (
+ {
+ if (node.type === 'element' && parent && parent.type === 'root' && /h(1|2|3|4|5|6)/.test(node.tagName)) {
+ const child = node.children && (node.children[0] as Element);
+ if (child && child.properties && child.properties.ariaHidden === 'true') {
+ child.children = [];
+ }
+ }
+ }}
+ components={{
+ code: (props) => ,
+ }}
+ />
+ );
+}