diff options
| author | shu <nvcsadjkojf@outlook.com> | 2026-10-22 13:03:06 +0800 |
|---|---|---|
| committer | shu <nvcsadjkojf@outlook.com> | 2026-10-22 13:03:06 +0800 |
| commit | bfe5541e56f68b74fd41974c804f8e7ac1ff9f2a (patch) | |
| tree | 5f5026082ad8d87af02500bcb13d6fbdc8bfa77a /src/components | |
基于 Vite 8、React 19、TypeScript 6、React Router 7 和 Astryx 0.7.2
搭建完整的中文应用起始模板,包含可直接运行的应用外壳与示例页面。
主要变更:
- 使用 Astryx 构建 AppShell、顶部导航、可折叠侧边栏和响应式移动端抽屉。
- 接入 Astryx neutral 主题与中文语言包,支持明暗主题切换并持久化偏好。
- 新增概览、组件、图标、关于和 404 页面,统一使用共享页面框架。
- 将页面路由、侧边栏名称、图标和active状态合并到 app-routes.tsx,
路由与导航由同一份配置生成,避免重复维护。
- 新增根目录 app.config.ts,可在 browser/history 与 hash 路由模式之间切换;
当前保留 hash 模式配置。
- 组件页提供 14 个可交互组合场景,覆盖全部 173 个 Astryx 组件,
包含按钮、表单、表格、导航、聊天、对话框、菜单、命令面板和 Toast 等。
- 新增图标页面,支持浏览 29 个 Astryx 语义图标和 1903 个 Lucide 图标,
提供搜索、分页、图标集切换和点击复制用法。
- 对组件页和图标页实施路由级懒加载,并按 React、React Router 拆分 vendor
chunk,降低首屏入口体积并改善长期缓存。
- 接入 React Router 的 LinkProvider,保证 Astryx 链接、导航和按钮在两种
路由模式下均使用客户端导航。
- 配置 pnpm 供应链策略例外与依赖构建许可,锁定可以正常安装的依赖版本。
- 补充 README,记录项目结构、脚本、组件展厅、图标页、路由模式与构建策略。
验证结果:
- pnpm build 通过
- pnpm lint 0 warnings
- browser 与 hash 两种路由模式的页面和侧边栏导航均已验证
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/AppLayout.tsx | 79 | ||||
| -rw-r--r-- | src/components/ComponentsRoute.tsx | 16 | ||||
| -rw-r--r-- | src/components/IconsRoute.tsx | 16 | ||||
| -rw-r--r-- | src/components/Page.tsx | 42 | ||||
| -rw-r--r-- | src/components/PageLoading.tsx | 13 |
5 files changed, 166 insertions, 0 deletions
diff --git a/src/components/AppLayout.tsx b/src/components/AppLayout.tsx new file mode 100644 index 0000000..9c93302 --- /dev/null +++ b/src/components/AppLayout.tsx @@ -0,0 +1,79 @@ +import { useLayoutEffect, useState } from 'react' +import { Outlet, useLocation } from 'react-router-dom' +import { AppShell } from '@astryxdesign/core/AppShell' +import { Icon } from '@astryxdesign/core/Icon' +import { IconButton } from '@astryxdesign/core/IconButton' +import { NavIcon } from '@astryxdesign/core/NavIcon' +import { SideNav, SideNavItem, SideNavSection } from '@astryxdesign/core/SideNav' +import { TopNav, TopNavHeading } from '@astryxdesign/core/TopNav' +import { Moon, Sparkles, Sun } from 'lucide-react' +import { isRouteActive, navRoutes } from '../app-routes' +import { useThemeMode } from '../theme/useThemeMode' + +export function AppLayout() { + const { pathname } = useLocation() + const { mode, toggleMode } = useThemeMode() + const [isMobileNavOpen, setIsMobileNavOpen] = useState(false) + + useLayoutEffect(() => { + const main = document.getElementById('astryx-app-shell-main') + if (main) main.scrollTop = 0 + window.scrollTo(0, 0) + }, [pathname]) + + const nextMode = mode === 'light' ? 'dark' : 'light' + + return ( + <AppShell + height="fill" + contentPadding={0} + mobileNav={{ + isOpen: isMobileNavOpen, + onOpenChange: setIsMobileNavOpen, + }} + topNav={ + <TopNav + label="主导航" + heading={ + <TopNavHeading + heading="Astryx 起始模板" + headingHref="/" + logo={ + <NavIcon + icon={<Icon icon={Sparkles} size="sm" color="inherit" />} + /> + } + /> + } + endContent={ + <IconButton + label={`切换到${nextMode === 'dark' ? '深色' : '浅色'}主题`} + tooltip={`切换到${nextMode === 'dark' ? '深色' : '浅色'}主题`} + variant="ghost" + icon={<Icon icon={mode === 'light' ? Moon : Sun} />} + onClick={toggleMode} + /> + } + /> + } + sideNav={ + <SideNav collapsible> + <SideNavSection title="探索"> + {navRoutes.map(({ label, path, icon }) => ( + <SideNavItem + key={path} + label={label} + href={path} + icon={icon} + selectedIcon={icon} + isSelected={isRouteActive(path, pathname)} + onClick={() => setIsMobileNavOpen(false)} + /> + ))} + </SideNavSection> + </SideNav> + }> + <Outlet /> + </AppShell> + ) +} diff --git a/src/components/ComponentsRoute.tsx b/src/components/ComponentsRoute.tsx new file mode 100644 index 0000000..53db94a --- /dev/null +++ b/src/components/ComponentsRoute.tsx @@ -0,0 +1,16 @@ +import { lazy, Suspense } from 'react' +import { PageLoading } from './PageLoading' + +const ComponentsPage = lazy(() => + import('../pages/ComponentsPage').then((module) => ({ + default: module.ComponentsPage, + })), +) + +export function ComponentsRoute() { + return ( + <Suspense fallback={<PageLoading />}> + <ComponentsPage /> + </Suspense> + ) +} diff --git a/src/components/IconsRoute.tsx b/src/components/IconsRoute.tsx new file mode 100644 index 0000000..83c7690 --- /dev/null +++ b/src/components/IconsRoute.tsx @@ -0,0 +1,16 @@ +import { lazy, Suspense } from 'react' +import { PageLoading } from './PageLoading' + +const IconsPage = lazy(() => + import('../pages/IconsPage').then((module) => ({ + default: module.IconsPage, + })), +) + +export function IconsRoute() { + return ( + <Suspense fallback={<PageLoading />}> + <IconsPage /> + </Suspense> + ) +} diff --git a/src/components/Page.tsx b/src/components/Page.tsx new file mode 100644 index 0000000..4dd1248 --- /dev/null +++ b/src/components/Page.tsx @@ -0,0 +1,42 @@ +import type { ReactNode } from 'react' +import { Layout, LayoutContent } from '@astryxdesign/core/Layout' +import { Heading } from '@astryxdesign/core/Heading' +import { Text } from '@astryxdesign/core/Text' +import { VStack } from '@astryxdesign/core/VStack' + +export function Page({ children }: { children: ReactNode }) { + return ( + <Layout + height="auto" + padding={6} + contentWidth={1120} + content={<LayoutContent>{children}</LayoutContent>} + /> + ) +} + +interface PageHeaderProps { + eyebrow?: string + title: string + description?: string +} + +export function PageHeader({ eyebrow, title, description }: PageHeaderProps) { + return ( + <VStack gap={2} maxWidth={820}> + {eyebrow ? ( + <Text type="label" color="accent"> + {eyebrow} + </Text> + ) : null} + <Heading level={1} type="display-3" textWrap="balance"> + {title} + </Heading> + {description ? ( + <Text type="large" color="secondary" as="p" textWrap="pretty"> + {description} + </Text> + ) : null} + </VStack> + ) +} diff --git a/src/components/PageLoading.tsx b/src/components/PageLoading.tsx new file mode 100644 index 0000000..3e98fe8 --- /dev/null +++ b/src/components/PageLoading.tsx @@ -0,0 +1,13 @@ +import { Center } from '@astryxdesign/core/Center' +import { Spinner } from '@astryxdesign/core/Spinner' +import { Page } from './Page' + +export function PageLoading() { + return ( + <Page> + <Center minHeight={480}> + <Spinner size="lg" /> + </Center> + </Page> + ) +} |
