|
1 |
| -import { useState } from 'react'; |
2 | 1 | import ReactDom from 'react-dom/client';
|
3 |
| -import { Outlet, BrowserRouter as Router, useRoutes } from 'react-router-dom'; |
4 |
| -import { Button, Icon, Input, Skeleton, Card } from 'pivot-design'; |
| 2 | +import React, { ReactNode } from 'react'; |
| 3 | +import { BrowserRouter as Router, useLocation, useRoutes } from 'react-router-dom'; |
5 | 4 | import router from '@/routers';
|
6 |
| -import ButtonMdx from './src/components/Button/index.mdx'; |
7 |
| -import IconMdx from './src/components/Icon/index.mdx'; |
8 |
| -import InputMdx from './src/components/Input/index.mdx'; |
9 |
| -import CardMdx from './src/components/Card/index.mdx'; |
10 |
| -import SkeletonMdx from './src/components/Skeleton/index.mdx'; |
11 |
| -import Draggable from '@/examples/Draggable/Draggable'; |
12 |
| -import CodeBlock from '@/components/codeBlock'; |
13 | 5 | import './index.scss';
|
14 |
| -const App = () => { |
15 |
| - const [select, setSelect] = useState('Input'); |
16 |
| - const demoSelect = () => { |
17 |
| - return ( |
18 |
| - <div className="demo-container"> |
19 |
| - <div className={`demo-item ${select === 'Button' ? 'active' : ''}`} onClick={() => setSelect('Button')}> |
20 |
| - 按钮 |
21 |
| - </div> |
22 |
| - <div className={`demo-item ${select === 'Card' ? 'active' : ''}`} onClick={() => setSelect('Card')}> |
23 |
| - 卡片 |
24 |
| - </div> |
25 |
| - |
26 |
| - <div className={`demo-item ${select === 'Draggable' ? 'active' : ''}`} onClick={() => setSelect('Draggable')}> |
27 |
| - 拖拽列表 |
28 |
| - </div> |
29 |
| - <div className={`demo-item ${select === 'Skeleton' ? 'active' : ''}`} onClick={() => setSelect('Skeleton')}> |
30 |
| - 骨架屏 |
31 |
| - </div> |
32 |
| - <div className={`demo-item ${select === 'Icon' ? 'active' : ''}`} onClick={() => setSelect('Icon')}> |
33 |
| - 图标 |
34 |
| - </div> |
35 |
| - <div className={`demo-item ${select === 'Input' ? 'active' : ''}`} onClick={() => setSelect('Input')}> |
36 |
| - 输入框 |
37 |
| - </div> |
38 |
| - </div> |
39 |
| - ); |
40 |
| - }; |
| 6 | +import { useLayoutEffect } from 'react'; |
41 | 7 |
|
| 8 | +const App = () => { |
42 | 9 | return useRoutes(router);
|
| 10 | +}; |
43 | 11 |
|
44 |
| - /* <div className="pivot-design-docs-content"> |
45 |
| - {demoSelect()} |
46 |
| - <div className="demo-component"> |
47 |
| - {select === 'Button' ? <ButtonMdx components={{ Button, CodeBlock }} /> : null} |
48 |
| - {select === 'Icon' ? <IconMdx components={{ Icon, CodeBlock }} /> : null} |
49 |
| - {select === 'Input' ? <InputMdx components={{ Input, CodeBlock }} /> : null} |
50 |
| - {select === 'Card' ? <CardMdx components={{ Card, CodeBlock }} /> : null} |
51 |
| - {select === 'Draggable' ? <Draggable /> : null} |
52 |
| - {select === 'Skeleton' ? <SkeletonMdx components={{ Skeleton, CodeBlock }} /> : null} |
53 |
| - </div> |
54 |
| - </div> */ |
| 12 | +const AutoScrollToTop: React.FC<{ children: React.ReactElement }> = ({ children }) => { |
| 13 | + const location = useLocation(); |
| 14 | + useLayoutEffect(() => { |
| 15 | + document.documentElement.scrollTo(0, 0); |
| 16 | + }, [location.pathname]); |
| 17 | + return children; |
55 | 18 | };
|
56 | 19 |
|
57 | 20 | ReactDom.createRoot(document.getElementById('root') as HTMLElement).render(
|
58 | 21 | <Router>
|
59 |
| - <App /> |
| 22 | + <AutoScrollToTop> |
| 23 | + <App /> |
| 24 | + </AutoScrollToTop> |
60 | 25 | </Router>
|
61 | 26 | );
|
0 commit comments