Skip to content

Commit

Permalink
chore: support url params n&s for playground
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Jan 15, 2024
1 parent 5684e0f commit e960f0c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion docs/docs/playground/demos/Playground/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { LiveProvider, LiveEditor, LiveError, LivePreview } from "react-live";
import qs from "qs";
import * as prism from 'prism-react-renderer';
import * as helux from 'helux';
import ApiMenus from './ApiMenus';
Expand All @@ -15,14 +16,17 @@ const subNames: Record<string, string> = {
modular: 'defineActions',
};
const cachedSubNames: Record<string, string> = {};
const obj = qs.parse(window.location.search, { ignoreQueryPrefix: true });
const name = obj.n || 'atom';
const subName = obj.s || 'primitive';

function getCode(name: string, subName: string) {
const codeDict: any = codes;
return codeDict[name]?.[subName] || '';
}

export default () => {
const [info, setInfo] = React.useState({ name: 'atom', subName: 'primitive', code: getCode('atom', 'primitive'), });
const [info, setInfo] = React.useState({ name, subName, code: getCode('atom', 'primitive'), });
const changeCode = (name: string) => {
const subName = cachedSubNames[name] || subNames[name] || 'primitive';
setInfo({ name, subName, code: getCode(name, subName) });
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/playground/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
nav:
title: 生态
title: Playground
order: 3
---

Expand Down
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"lodash.throttle": "^4.1.1",
"prism-react-renderer": "^2.3.1",
"prism-themes": "^1.9.0",
"qs": "^6.11.2",
"rc-motion": "^2.9.0",
"rc-tree": "^5.8.2",
"react-copy-to-clipboard": "^5.1.0",
Expand Down
5 changes: 3 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e960f0c

Please sign in to comment.