-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathApp.tsx
More file actions
70 lines (62 loc) · 1.65 KB
/
Copy pathApp.tsx
File metadata and controls
70 lines (62 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type { Component } from "solid-js";
import { JSX, createSignal, createEffect } from "solid-js";
import { Box, Tabs, TabList, Tab, TabPanel, Flex } from "@hope-ui/solid";
import { Route, Routes, useNavigate, useLocation } from "solid-app-router";
import Main from "./Main";
import Info from "./Info";
const Panel: Component<{ children: JSX.Element }> = (props) => {
return (
<Box m="$2" mt="$6">
{props.children}
</Box>
);
};
const AppRoutes: Component = () => {
return (
<Routes>
<Route path="/" element={<Main />} />
<Route path="/info" element={<Info />} />
</Routes>
);
};
const App: Component = () => {
const [tabIndex, setTabIndex] = createSignal(0);
// set correct tab index from pathname
createEffect(() => {
const location = useLocation();
if (location.pathname === "/") {
setTabIndex(0);
} else if (location.pathname === "/info") {
setTabIndex(1);
}
});
// use tab index to navigate to pathname
const navigate = useNavigate();
const handleTabsChange = (index: number) => {
if (index === 0) {
navigate("/");
} else if (index === 1) {
navigate("/info");
}
setTabIndex(index);
};
return (
<Tabs h="$screenH" index={tabIndex()} onChange={handleTabsChange}>
<Flex direction={"column"} h="$full" maxH="100vh">
<TabList>
<Tab>Main</Tab>
<Tab>Info</Tab>
</TabList>
<TabPanel maxHeight="calc(100vh - 40px)">
<AppRoutes />
</TabPanel>
<TabPanel>
<Panel>
<AppRoutes />
</Panel>
</TabPanel>
</Flex>
</Tabs>
);
};
export default App;