Skip to content

Commit

Permalink
chore: fix single demo edit path (#2969)
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn authored Jul 1, 2024
1 parent 4952235 commit d411579
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions site/src/components/Demo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React from 'react';
import Button from 'tdesign-react/button';
import { Link, useLocation } from 'react-router-dom';

export const demoFiles = import.meta.globEager('../../../src/**/_example/*.jsx');
export const demoFiles = import.meta.globEager('../../../src/**/_example/*.tsx');

const demoObject = {};
Object.keys(demoFiles).forEach((key) => {
const match = key.match(/([\w-]+)._example.([\w-]+).jsx/);
const match = key.match(/([\w-]+)._example.([\w-]+).tsx/);
const [, componentName, demoName] = match;

demoObject[`${componentName}/${demoName}`] = demoFiles[key].default;
if (demoObject[componentName]) {
demoObject[componentName].push(demoName)
demoObject[componentName].push(demoName);
} else {
demoObject[componentName] = [demoName];
}
Expand All @@ -21,20 +21,23 @@ export default function Demo() {
const location = useLocation();
const match = location.pathname.match(/\/react\/demos\/([\w-]+)\/?([\w-]+)?/);
const [, componentName, demoName] = match;

const demoList = demoObject[componentName];
const demoFunc = demoObject[`${componentName}/${demoName}`];

return demoFunc ? demoFunc() : (
return demoFunc ? (
demoFunc()
) : (
<ul style={{ margin: '48px 200px' }}>
{
demoList.map(demoName => (
<li key={demoName}>
<Link to={`/react/demos/${componentName}/${demoName}`}>
<Button style={{ fontSize: 18 }} variant="text">{demoName}</Button>
</Link>
</li>
))
}
{demoList.map((demoName) => (
<li key={demoName}>
<Link to={`/react/demos/${componentName}/${demoName}`}>
<Button style={{ fontSize: 18 }} variant="text">
{demoName}
</Button>
</Link>
</li>
))}
</ul>
);
}

0 comments on commit d411579

Please sign in to comment.