aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/App.tsx
diff options
context:
space:
mode:
authorshu <nvcsadjkojf@outlook.com>2026-09-07 15:48:36 +0800
committershu <nvcsadjkojf@outlook.com>2026-09-07 15:48:36 +0800
commit481402e09fe760634b826b09e302e2e1bfec88b1 (patch)
tree9b55025bfcd6acd2c5d795f057de27028b422603 /src/App.tsx
feat: initialize React Spectrum template with layouts and showcases
Diffstat (limited to 'src/App.tsx')
-rw-r--r--src/App.tsx38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/App.tsx b/src/App.tsx
new file mode 100644
index 0000000..716d5ad
--- /dev/null
+++ b/src/App.tsx
@@ -0,0 +1,38 @@
+import { useLayoutEffect, useState } from 'react'
+import { Outlet, useHref, useNavigate, type NavigateOptions } from 'react-router'
+import { Provider } from '@react-spectrum/s2/Provider'
+import BasicLayout from './components/layout-basic'
+import { getInitialColorScheme, ThemeContext, themeStorageKey } from './theme'
+
+// Configure the type of the `routerOptions` prop on all React Spectrum components.
+declare module '@react-spectrum/s2/Provider' {
+ interface RouterConfig {
+ routerOptions: NavigateOptions
+ }
+}
+
+function App() {
+ const navigate = useNavigate()
+ const [colorScheme, setColorScheme] = useState(getInitialColorScheme)
+
+ useLayoutEffect(() => {
+ document.documentElement.dataset.theme = colorScheme
+ try {
+ localStorage.setItem(themeStorageKey, colorScheme)
+ } catch {
+ // Keep applying the theme even when browser storage is unavailable.
+ }
+ }, [colorScheme])
+
+ return (
+ <ThemeContext value={{ colorScheme, setColorScheme }}>
+ <Provider background="base" colorScheme={colorScheme} router={{ navigate, useHref }}>
+ <BasicLayout>
+ <Outlet />
+ </BasicLayout>
+ </Provider>
+ </ThemeContext>
+ )
+}
+
+export default App