Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support url params n&s for playground #135

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.