feat: 全站导航换壳 sidebar 单形态,汉堡钮贴一级标题左侧 (#86)
Build Images / Build tutorial (buildkit) (push) Successful in 56s
Build Images / Build web-runner (buildkit) (push) Successful in 36s

## 背景

导航此前有三种形态:桌面顶栏(紧凑条加展开网格浮层)、桌面侧栏、窄屏抽屉。侧栏只在练习场用,其余 23 个页面走顶栏。这次顶部形态不再需要:全站统一成侧栏,窄屏收成抽屉;「打开侧栏导航」的汉堡钮不再固定在视口左上角,改为贴在一级标题左侧。

## 变更内容

**站点壳(packages/stack-site-ui-kit)**

- 删 `SiteNavbar`。`SitePage` 只剩侧栏一种布局:左侧 `SiteSidebar`,右侧 `main[data-scroll-root]` 独立滚动,页脚 sticky 常驻底部。`sidebar` prop 与顶部布局一并删除,`nav` 改为必填。
- 汉堡钮拆成 `SiteSidebarTrigger`,由 `SitePage` 渲染在标题行里。`pageHead` 改为两列 grid:窄屏第一列放触发器,h1 落第二列;触发器按 h1 的字号与行高算负 margin,对齐首行中线,标题折行时仍钉在首行。桌面不显示。
- 页面没传 `title` 时(章节页与博客文章页,h1 画在各自的 hero 卡里),触发器独占一行放在首块内容之上。
- 新增 `docked` prop:页面有贴靠视口边缘的停靠件时(练习场的右上角贴片与右缘贴签),窄屏主区让出顶部 4rem 与右缘 3rem。这段留白原先写死在 `sidebarMain`,现在只在 `docked` 时生效。
- 翻页 view transition 的常驻元素由 `site-header` 改为 `site-sidebar`,挂在侧栏上且只在 64rem 以上生效;窄屏抽屉随页面进出。
- 包出口去掉 `SiteNavbar` 与 `SiteSidebar`,`NavRowGroup` 等类型改从 `SiteSidebar` 导出。

**app 侧**

- 练习场改走统一壳,标题与描述从页面内 JSX 改为 `title` 与 `desc`。它随之从整页滚动变为主区独立滚动加页脚常驻,与其他页一致。
- `Page` 去掉 `viewTransitionName`。
- 两处提到 navbar 的页面文案改为侧栏。

**e2e 与视觉基线**

- 新增 `e2e/site-sidebar.spec.ts`:24 页桌面逐页断言,15 个标题页逐页量汉堡钮与 h1 的几何关系,9 个 hero 页,抽屉开合与跳转。
- `nav-brand`、`learn`、`pages`、`page-flip` 里依赖顶栏的用例改到侧栏;顶栏网格浮层的视觉用例随功能删除。
- 视觉基线以 `--update-snapshots=all` 重建:35 张更新,删 2 张顶栏相关,新增 `flip-top-idle`。

**随之而来的变化**

- 内容列变窄:1280 宽下由 1152px 变为 992px(侧栏占 240px)。

**两处取舍,请评审时确认**

- hero 页(章节页、博客文章页)的汉堡钮没有贴在 h1 左侧:h1 在卡片里,硬贴会让卡片窄 52px,章节标题在 390px 宽下折行。目前的做法是独占一行、压在卡片上方。
- 练习场窄屏保留了顶部让位带:「验收 / tips」贴片与「汉堡钮加标题」在同一行放不下(390px 下差约 15px),所以标题行整体下移一行,汉堡钮仍贴在 h1 左侧。

## 自测结果

- `yarn workspace @stack/tutorial test:e2e`:210 条全过,连跑两遍零失败(main 基线 159 条)。
- `tsc -b`(tutorial)、`stack-site-ui-kit typecheck`、`yarn format:check`、`node scripts/strip-comments.mjs`(0 条注释)、`yarn build` 均通过。
- 另派 glm-5.3-flash 做了一轮黑盒验收,共 10 项,9 项通过。「页脚常驻」一项在 design/components 判失败,原因是裸选择器 `footer` 命中了组件画廊里示例卡自带的演示页脚;站点页脚本身底边为 900,与预期一致。e2e 里的同类断言已改为只认站点页脚。
- 前后对照截图如下。两侧都起 `stack preview`(`VITE_STACK_RUNTIME_ORIGIN` 指向 web-runner)后用 playwright 截视口图,桌面 1280×900、移动 390×844,`document.fonts.ready` 后再截。

桌面 1280×900(每张左为 main,右为本 PR):

桌面 章节页 tutorial/ch1:顶栏退场,侧栏常驻左栏

![桌面 章节页 tutorial/ch1:顶栏退场,侧栏常驻左栏](https://gitea.idealjs.com/attachments/63add71c-274a-40cf-9d77-c58649bc31ff)

桌面 首页 index

![桌面 首页 index](https://gitea.idealjs.com/attachments/b5f1b09d-87b0-4845-90ab-720c7d857d6b)

桌面 练习场 practice:原本就是侧栏,主区留白与其他页拉齐

![桌面 练习场 practice:原本就是侧栏,主区留白与其他页拉齐](https://gitea.idealjs.com/attachments/fb048b8a-7c5b-4cee-af07-e012892d0d85)

移动 390×844:

移动 首页 index:汉堡钮从顶栏移到 h1 左侧

![移动 首页 index:汉堡钮从顶栏移到 h1 左侧](https://gitea.idealjs.com/attachments/56e96e3a-458f-43dc-9c57-436e25aeb03f)

移动 章节页 tutorial/ch1:汉堡钮独占一行,压在 hero 卡上方

![移动 章节页 tutorial/ch1:汉堡钮独占一行,压在 hero 卡上方](https://gitea.idealjs.com/attachments/ea4b3df5-b336-455c-a043-f78b4378adcb)

移动 练习场 practice:保留顶部让位带,汉堡钮随标题下移

![移动 练习场 practice:保留顶部让位带,汉堡钮随标题下移](https://gitea.idealjs.com/attachments/ad977f37-1610-4d82-b807-5c4312c36664)

移动 首页 index 抽屉打开

![移动 首页 index 抽屉打开](https://gitea.idealjs.com/attachments/b271d875-4b00-49b3-9c0a-78f19a37a41d)

移动 章节页 tutorial/ch1 抽屉打开

![移动 章节页 tutorial/ch1 抽屉打开](https://gitea.idealjs.com/attachments/8f1208a1-6b48-4956-af8c-90231cf26816)

**没覆盖的**

- 真机移动浏览器:地址栏伸缩下的 100dvh、抽屉手势。e2e 只跑 chromium 的视口模拟。
- 翻页 view transition 的实际观感:只核对了侧栏命名与冻结中间帧的截图,没在真机上连续翻页看。
- 练习场窄屏打开抽屉时,右缘贴签与 tips 浮在遮罩之上(z-index 同为 40,DOM 在后)。main 上练习场本来如此,本 PR 没动。

Reviewed-on: #86
Co-authored-by: arnold.cui-agent <arnold.cui-agent@idealjs.com>
This commit was merged in pull request #86.
This commit is contained in:
arnold.cui-agent authored and arnold.cui committed 2026-12-05 15:52:05 +00:00
1 parent bda4c35f6b
commit b5b140c417
59 files changed
+425 -554

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@
- **Vite MPA**:根目录每 `*.html` 一个入口 → `src/pages/<name>/main.tsx`
- **页面**:`index.html` 课程书架(入口画像 / 六章卡 / 主线与进度);`ch1–ch6.html` 章节页(章头靶子 → 步骤 → 积木 → 认知基础 → 指派)
- **View Transitions**:`@view-transition { navigation: auto }` 跨文档交叉淡入(MPA 不闪白);书架相框 ↔ 章节页章头同名 `view-transition-name: ch-<id>` 共享元素变形;站头 `site-header` 常驻;`prefers-reduced-motion` 下禁用
- **View Transitions**:`@view-transition { navigation: auto }` 跨文档交叉淡入(MPA 不闪白);书架相框 ↔ 章节页章头同名 `view-transition-name: ch-<id>` 共享元素变形;侧栏 `site-sidebar` 与页脚 `site-footer` 常驻(窄屏侧栏收成抽屉,不参与命名);`prefers-reduced-motion` 下禁用
- **设计系统**:token 与基础组件唯一定义于 `packages/stack-ui-kit`,业务组件在 `packages/stack-site-ui-kit`(孟菲斯 × 拟物卡);app 侧 `src/styles/tailwind.css` 以 `@theme reference` 桥接 token 原名变量
- **内容**:`src/lib/chapters.ts`(六章的靶子/步骤/积木/指派数据),改内容只动这一个文件
- **远程 code-server 访问**:按需传 `--base /absproxy/8910`(仅远程
+14 -15
View File
@@ -39,28 +39,28 @@ test.describe('教程首页', () => {
await expect(demo.getByRole('status')).toHaveText('5 件 · 完成 1')
})
test('站头恒为完整四行:四个行首与各条目在任何页面不缩减', async ({ page }) => {
const header = page.locator('main header')
test('侧栏恒为完整行组:五个行首与各条目在桌面常驻可读', async ({ page }) => {
const sidebar = page.locator('#site-sidebar-drawer')
await page.getByLabel('展开导航网格').click()
for (const label of ['全栈教程', '博客', '设计系统', '在线练习']) {
await expect(header.getByRole('link', { name: label, exact: true })).toHaveCount(1)
await expect(sidebar.getByRole('link', { name: label, exact: true })).toHaveCount(1)
}
await expect(sidebar.getByText('技能熟悉', { exact: true })).toBeVisible()
await expect(header.getByRole('link', { name: '快速开始', exact: true })).toBeVisible()
await expect(header.getByRole('link', { name: /20\d{2}-\d{2}/ }).first()).toBeVisible()
await expect(header.getByRole('link', { name: '颜色', exact: true })).toBeVisible()
await expect(header.getByRole('link', { name: '组件', exact: true })).toBeVisible()
await expect(header.getByRole('link', { name: '重建中', exact: true })).toBeVisible()
await expect(sidebar.getByRole('link', { name: '快速开始', exact: true })).toBeVisible()
await expect(sidebar.getByRole('link', { name: /20\d{2}-\d{2}/ }).first()).toBeVisible()
await expect(sidebar.getByRole('link', { name: '颜色', exact: true })).toBeVisible()
await expect(sidebar.getByRole('link', { name: '组件', exact: true })).toBeVisible()
await expect(sidebar.getByRole('link', { name: '重建中', exact: true })).toBeVisible()
})
test('移动端导航抽屉:对称触发器的 aria-expanded 随纯 CSS 开合翻转', async ({ page }) => {
test('移动端侧栏抽屉:对称触发器的 aria-expanded 随纯 CSS 开合翻转', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 })
await page.goto('/tutorial/')
const open = page.locator('label[aria-label="打开导航菜单"]')
const close = page.locator('label[aria-label="收起导航菜单"]')
const overlay = page.locator('label[for="site-nav-toggle"][aria-hidden="true"]')
const drawer = page.locator('#site-nav-drawer')
const open = page.locator('label[aria-label="打开侧栏导航"]')
const close = page.locator('label[aria-label="收起侧栏导航"]')
const overlay = page.locator('label[for="site-sidebar-toggle"][aria-hidden="true"]')
const drawer = page.locator('#site-sidebar-drawer')
await expect(open).toBeVisible()
await expect(open).toHaveAttribute('aria-expanded', 'false')
@@ -69,7 +69,6 @@ test.describe('教程首页', () => {
await open.click()
await expect(drawer).toBeVisible()
await expect(open).toBeHidden()
await expect(close).toBeVisible()
await expect(close).toHaveAttribute('aria-expanded', 'true')
await overlay.click({ position: { x: 350, y: 400 } })
+10 -7
View File
@@ -1,15 +1,17 @@
import { expect, test } from '@playwright/test'
const PAGES = ['/index.html', '/design/', '/tutorial/ch7.html', '/blog/']
const SIDEBAR = '#site-sidebar-drawer'
const OPENER = 'label[for="site-sidebar-toggle"][aria-label="打开侧栏导航"]'
test.describe('navbar 品牌徽章一致性', () => {
test.describe('侧栏品牌徽章一致性', () => {
test('各页面 brand 徽章:无背景填充、嵌套零投影(logo 恒定,不随页面翻转)', async ({ page }) => {
const shadows: string[] = []
const backgrounds: string[] = []
for (const pagePath of PAGES) {
await page.goto(pagePath, { timeout: 20_000 })
await page.waitForTimeout(300)
const brand = page.locator('header a').first()
const brand = page.locator(`${SIDEBAR} a`).first()
backgrounds.push(await brand.evaluate((el) => getComputedStyle(el).backgroundColor))
shadows.push(await brand.evaluate((el) => getComputedStyle(el).boxShadow))
}
@@ -19,8 +21,9 @@ test.describe('navbar 品牌徽章一致性', () => {
test('hover 反馈:嵌套钮不升影,换底色', async ({ page }) => {
await page.goto('/index.html', { timeout: 20_000 })
const brand = page.locator('header a').first()
const brand = page.locator(`${SIDEBAR} a`).first()
const rest = await brand.evaluate((el) => getComputedStyle(el).boxShadow)
expect(rest).toBe('none')
await brand.hover()
expect(rest).toBe('none')
await expect
@@ -31,10 +34,10 @@ test.describe('navbar 品牌徽章一致性', () => {
test('移动抽屉 brand 同款零投影', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 })
await page.goto('/index.html', { timeout: 20_000 })
await page.locator('label[for="site-nav-toggle"]').first().click()
const drawerBrand = page.locator('#site-nav-drawer a').first()
await expect(drawerBrand).toBeVisible()
const shadow = await drawerBrand.evaluate((el) => getComputedStyle(el).boxShadow)
await page.locator(OPENER).click()
const brand = page.locator(`${SIDEBAR} a`).first()
await expect(brand).toBeVisible()
const shadow = await brand.evaluate((el) => getComputedStyle(el).boxShadow)
expect(shadow).toBe('none')
})
})
+2 -10
View File
@@ -53,17 +53,9 @@ const scrollToBottom = async (page: Page) => {
await page.waitForTimeout(400)
}
test('翻页视觉 · 顶部紧凑条默认收起态', async ({ browser, baseURL }) => {
test('翻页视觉 · 页面顶部静置态(侧栏常驻、无浮层)', async ({ browser, baseURL }) => {
const page = await openVisualPage(browser, baseURL, false)
await expect(page).toHaveScreenshot('flip-collapsed-top.png', { maxDiffPixelRatio: 0.01 })
await page.context().close()
})
test('翻页视觉 · toggle 展开导航网格浮层', async ({ browser, baseURL }) => {
const page = await openVisualPage(browser, baseURL, false)
await page.getByLabel('展开导航网格').click()
await page.waitForTimeout(400)
await expect(page).toHaveScreenshot('flip-nav-overlay.png', { maxDiffPixelRatio: 0.01 })
await expect(page).toHaveScreenshot('flip-top-idle.png', { maxDiffPixelRatio: 0.01 })
await page.context().close()
})
Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

After

Width:  |  Height:  |  Size: 200 KiB

+13 -28
View File
@@ -195,36 +195,21 @@ test('weak top charge holds prev edge symbols on screen, reverse wheel springs t
expect(await page.evaluate(edgeProgress, 'prev')).toBe(0)
})
test('navbar stays collapsed by default; toggle expands an overlay without squeezing content', async ({
page,
}) => {
test('侧栏与抽屉都不挤压滚动区', async ({ page }) => {
await page.setViewportSize({ width: 1280, height: 900 })
await page.goto('/tutorial/ch1.html')
await expect(page.locator('[data-flip-edge="next"]')).toHaveCount(1)
const grid = page.locator('#site-nav-drawer')
await expect(grid).toBeHidden()
const root = page.locator('[data-scroll-root]')
const sidebar = page.locator('#site-sidebar-drawer')
expect((await root.boundingBox())!.height).toBe(900)
expect((await sidebar.boundingBox())!.width).toBe(240)
await page.evaluate(() => {
const el = document.querySelector('[data-scroll-root]')
if (el instanceof HTMLElement) el.scrollTop = 400
})
await page.waitForTimeout(300)
await expect(grid).toBeHidden()
const heightBefore = await page.evaluate(() => {
const el = document.querySelector('[data-scroll-root]')
return el instanceof HTMLElement ? el.clientHeight : 0
})
await page.getByLabel('展开导航网格').click()
await expect(grid).toBeVisible()
const heightAfter = await page.evaluate(() => {
const el = document.querySelector('[data-scroll-root]')
return el instanceof HTMLElement ? el.clientHeight : 0
})
expect(heightAfter).toBe(heightBefore)
await page.getByLabel('收起导航网格').click()
await expect(grid).toBeHidden()
await page.setViewportSize({ width: 390, height: 844 })
await page.locator('label[aria-label="打开侧栏导航"]').click()
await expect(sidebar).toBeVisible()
expect((await root.boundingBox())!.height).toBe(844)
await expect(page.locator('[data-scroll-root] #site-sidebar-drawer')).toHaveCount(0)
expect((await sidebar.boundingBox())!.x).toBe(0)
})
test('charging at index bottom flips into the tutorial hub with next direction', async ({
@@ -254,7 +239,7 @@ test('charging at ch7 bottom crosses into the skills section', async ({ page })
test('charging at practice bottom loops back to the index page', async ({ page }) => {
await page.goto('/practice/')
await expect(page.locator('[data-flip-edge="next"]')).toHaveCount(1)
await page.evaluate(() => window.scrollTo(0, document.documentElement.scrollHeight))
await page.evaluate(scrollToBottom)
await page.waitForTimeout(200)
await page.mouse.move(640, 450)
await chargeByWheel(page, 250)
+3 -4
View File
@@ -755,19 +755,18 @@ test.describe('技能熟悉页', () => {
] as const
for (const { key, name } of SKILLS) {
test(`${key} 渲染有内容,导航新组「技能熟悉」当前项高亮`, async ({ page }) => {
test(`${key} 渲染有内容,侧栏「技能熟悉」组当前项高亮`, async ({ page }) => {
await page.goto(`/skills/${key}.html`)
await expect(page.locator('#root')).not.toBeEmpty()
await expect(page.locator('h1')).toHaveText(name)
await expect(page.getByText('内容建设中')).toBeVisible()
await page.getByLabel('展开导航网格').click()
for (const { key: sibling } of SKILLS) {
const item = page.locator(`#site-nav-drawer a[href="../skills/${sibling}.html"]`)
const item = page.locator(`#site-sidebar-drawer a[href="../skills/${sibling}.html"]`)
await expect(item).toHaveClass(
sibling === key ? /bgPaperDeep/ : /textBody.*hoverBgPaperDeep|hoverBgPaperDeep.*textBody/,
)
}
await expect(page.locator('#site-nav-drawer').getByText('技能熟悉')).toBeVisible()
await expect(page.locator('#site-sidebar-drawer').getByText('技能熟悉')).toBeVisible()
})
}
+195
View File
@@ -0,0 +1,195 @@
import type { Page } from '@playwright/test'
import { expect, test } from '@playwright/test'
const SIDEBAR = '#site-sidebar-drawer'
const OPENER = 'label[for="site-sidebar-toggle"][aria-label="打开侧栏导航"]'
const OVERLAY = 'label[for="site-sidebar-toggle"][aria-hidden="true"]'
const CLOSE = 'label[aria-label="收起侧栏导航"]'
const LINKED_HEADS = ['全栈教程', '博客', '设计系统', '在线练习']
const HEADS = ['全栈教程', '技能熟悉', '博客', '设计系统', '在线练习']
const TITLED = [
'index.html',
'tutorial/index.html',
'design/',
'design/colors.html',
'design/typography.html',
'design/symbols.html',
'design/components.html',
'design/shadow.html',
'skills/html.html',
'skills/css.html',
'skills/javascript.html',
'blog/index.html',
'blog/2025-07.html',
'blog/2026-08.html',
'practice/index.html',
]
const HERO = [
'tutorial/ch1.html',
'tutorial/ch2.html',
'tutorial/ch3.html',
'tutorial/ch4.html',
'tutorial/ch5.html',
'tutorial/ch6.html',
'tutorial/ch7.html',
'blog/gorzil.html',
'blog/sapling-transformer.html',
]
const ALL = [...TITLED, ...HERO]
const sidebarRows = async (page: Page, path: string) => {
const sidebar = page.locator(SIDEBAR)
for (const label of LINKED_HEADS) {
await expect(sidebar.getByRole('link', { name: label, exact: true }), path).toHaveCount(1)
}
for (const label of HEADS) {
await expect(sidebar.getByText(label, { exact: true }), path).toBeVisible()
}
}
const gapToTitle = async (page: Page, minTriggerTop: number) => {
const trigger = (await page.locator(OPENER).boundingBox())!
const title = (await page.locator('h1').first().boundingBox())!
const lineHeight = await page
.locator('h1')
.first()
.evaluate((el) => parseFloat(getComputedStyle(el).lineHeight))
expect(
Math.abs(trigger.x + trigger.width + 12 - title.x),
'汉堡钮右缘距标题 12px',
).toBeLessThanOrEqual(0.5)
expect(
Math.abs(trigger.y + trigger.height / 2 - (title.y + lineHeight / 2)),
'汉堡钮居中压在标题首行',
).toBeLessThanOrEqual(1)
expect(trigger.y).toBeGreaterThanOrEqual(minTriggerTop)
return trigger
}
test.describe('全站 · sidebar 单形态导航', () => {
test.use({ viewport: { width: 1280, height: 900 } })
for (const path of ALL) {
test(`桌面 · ${path}:顶部 navbar 退场,侧栏常驻左栏 240px 全高,主区独立滚动`, async ({
page,
}) => {
await page.goto(`/${path}`)
await expect(page.locator('[data-scroll-root] > header')).toHaveCount(0)
await expect(page.locator('#site-nav-drawer, #site-nav-toggle')).toHaveCount(0)
await expect(page.locator('[data-scroll-root] #site-sidebar-drawer')).toHaveCount(0)
const sidebar = page.locator(SIDEBAR)
await expect(sidebar).toBeVisible()
const box = (await sidebar.boundingBox())!
expect(box.x, path).toBe(0)
expect(box.width, path).toBe(240)
expect(box.height, path).toBe(900)
const root = (await page.locator('[data-scroll-root]').boundingBox())!
expect(root.x, path).toBe(240)
expect(root.width, path).toBe(1040)
await expect(page.locator(OPENER)).toBeHidden()
await sidebarRows(page, path)
})
}
test('桌面:主区滚动时侧栏原地不动,站点页脚常驻底部(不被页内演示 footer 冒名)', async ({
page,
}) => {
const siteFooter = page.locator('[data-scroll-root] > [class*="footerWrapSticky"]')
for (const path of ['/tutorial/ch1.html', '/design/components.html']) {
await page.goto(path)
const sidebarTop = (await page.locator(SIDEBAR).boundingBox())!.y
await page.locator('[data-scroll-root]').evaluate((el) => el.scrollTo(0, 600))
await page.waitForTimeout(200)
expect((await page.locator(SIDEBAR).boundingBox())!.y, path).toBe(sidebarTop)
await expect(siteFooter, path).toHaveCount(1)
await expect(siteFooter.locator('footer'), path).toHaveCount(1)
const shell = (await siteFooter.boundingBox())!
expect(shell.y + shell.height, path).toBeCloseTo(900, 0)
}
})
test('翻页 VT:桌面侧栏命名 site-sidebar 常驻,移动端不命名(抽屉随页面进出)', async ({
page,
}) => {
await page.goto('/tutorial/ch1.html')
const sidebar = page.locator(SIDEBAR)
const name = () => sidebar.evaluate((el) => getComputedStyle(el).viewTransitionName)
expect(await name()).toBe('site-sidebar')
await page.setViewportSize({ width: 390, height: 844 })
expect(await name()).toBe('none')
})
for (const path of TITLED) {
const docked = path === 'practice/index.html'
test(`移动 · ${path}:汉堡钮贴一级标题左侧,居中压在标题首行`, async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 })
await page.goto(`/${path}`)
await expect(page.locator('h1')).toHaveCount(1)
await expect(page.locator(SIDEBAR)).toBeHidden()
const trigger = await gapToTitle(page, docked ? 60 : 12)
expect(trigger.x).toBe(24)
expect(trigger.width).toBe(40)
expect(trigger.y).toBeLessThan(docked ? 64 : 16)
})
}
for (const path of HERO) {
test(`移动 · ${path}:h1 住 hero 卡内,汉堡钮独占一行贴在首块之上`, async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 })
await page.goto(`/${path}`)
await expect(page.locator('h1').first()).toBeVisible()
await expect(page.locator(SIDEBAR)).toBeHidden()
const trigger = (await page.locator(OPENER).boundingBox())!
const title = (await page.locator('h1').first().boundingBox())!
expect(trigger.x).toBeLessThanOrEqual(title.x)
expect(trigger.y).toBeLessThan(16)
expect(trigger.y + trigger.height).toBeLessThan(title.y)
})
}
test('移动:抽屉开合——汉堡钮打开,遮罩点按与收起钮关闭,开合不挤压主区', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 })
await page.goto('/tutorial/ch1.html')
const sidebar = page.locator(SIDEBAR)
const opener = page.locator(OPENER)
const root = page.locator('[data-scroll-root]')
await expect(sidebar).toBeHidden()
await expect(opener).toHaveAttribute('aria-expanded', 'false')
await opener.click()
await expect(sidebar).toBeVisible()
await expect(page.locator(CLOSE)).toHaveAttribute('aria-expanded', 'true')
const box = (await sidebar.boundingBox())!
expect(box.x).toBe(0)
expect(box.y).toBe(0)
expect(box.width).toBe(288)
expect(box.height).toBe(844)
expect((await root.boundingBox())!.width).toBe(390)
await page.locator(OVERLAY).click({ position: { x: 370, y: 400 } })
await expect(sidebar).toBeHidden()
await opener.click()
await expect(sidebar).toBeVisible()
await page.locator(CLOSE).click()
await expect(sidebar).toBeHidden()
})
test('移动:抽屉内链接跳到相邻页,到达后抽屉收起、标题在场', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 })
await page.goto('/tutorial/ch1.html')
await page.locator(OPENER).click()
await page.locator(SIDEBAR).getByRole('link', { name: 'React', exact: true }).click()
await page.waitForURL('**/ch2.html')
await expect(page.locator(SIDEBAR)).toBeHidden()
await expect(page.locator('h1')).toContainText('React')
await expect(page.locator(OPENER)).toBeVisible()
})
})
+3 -4
View File
@@ -30,7 +30,7 @@ const PAGES = [
const MOBILE = ['index.html', 'tutorial/ch1.html', 'design/components.html', 'practice/index.html']
const DRAWER_TOGGLES = ['site-nav-toggle', 'site-sidebar-toggle']
const OPENER = 'label[for="site-sidebar-toggle"][aria-label="打开侧栏导航"]'
const nameOf = (path: string) =>
path
@@ -46,6 +46,7 @@ const flattenPage = (page: Page) =>
for (const el of document.querySelectorAll<HTMLElement>('[data-scroll-root]')) {
el.style.height = 'auto'
el.style.overflow = 'visible'
;(el.parentElement as HTMLElement).style.height = 'auto'
}
document.documentElement.style.height = 'auto'
document.body.style.height = 'auto'
@@ -80,9 +81,7 @@ for (const path of MOBILE) {
await settle(page)
await baseline(page, `m-${nameOf(path)}`)
const toggle = page.locator(DRAWER_TOGGLES.map((id) => `label[for="${id}"]`).join(', ')).first()
if ((await toggle.count()) === 0) return
await toggle.click()
await page.locator(OPENER).click()
await baseline(page, `m-${nameOf(path)}-drawer`)
})
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 727 KiB

After

Width:  |  Height:  |  Size: 761 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 349 KiB

After

Width:  |  Height:  |  Size: 384 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 227 KiB

After

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 903 KiB

After

Width:  |  Height:  |  Size: 953 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 316 KiB

After

Width:  |  Height:  |  Size: 350 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 KiB

After

Width:  |  Height:  |  Size: 278 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 KiB

After

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 193 KiB

After

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

After

Width:  |  Height:  |  Size: 443 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 KiB

After

Width:  |  Height:  |  Size: 331 KiB

-1
View File
@@ -142,7 +142,6 @@ export function Page({
<SitePage
nav={siteNavFor(pageKey)}
active={activeKey}
viewTransitionName="site-header"
footerGroups={FOOTER_GROUPS}
title={title}
subtitle={subtitle}
@@ -260,7 +260,7 @@ export function App() {
</Section>
<Section
label="Dropdown · 下拉基件"
note="placement=bottom 向下展开/top 向上弹出;点入口开合、Esc 与点面板外收起;tips 贴签、验收夹、陪练 agent 是它的真件应用,站头 navbar 为同型的纯 CSS 实现"
note="placement=bottom 向下展开/top 向上弹出;点入口开合、Esc 与点面板外收起;tips 贴签、验收夹、陪练 agent 是它的真件应用,侧栏导航抽屉为同型的纯 CSS 实现"
>
<DropdownPreview />
</Section>
+1 -1
View File
@@ -23,7 +23,7 @@ const BOOKS: { key: PageKey; label: string; desc: string }[] = [
{
key: 'design-components',
label: '组件',
desc: 'CourseCard、票券、Button、SiteNavbar 等组件的实际组合。',
desc: 'CourseCard、票券、Button、SiteSidebar 等组件的实际组合。',
},
{
key: 'design-shadow',
+9 -14
View File
@@ -1,32 +1,27 @@
import { PageFlipZone } from '@idealjs/stack-site-ui-kit/components/PageFlipZone'
import { SitePage } from '@idealjs/stack-site-ui-kit/components/SitePage'
import { SiteSidebar } from '@idealjs/stack-site-ui-kit/components/SiteSidebar'
import { textContent, textInk, textMute, textT1 } from '@idealjs/stack-ui-kit/components'
import { PageTurnBar } from '../../components/PageTurnBar'
import { flipTargetsOf } from '../../lib/pages'
import { FOOTER_GROUPS, siteNavFor } from '../../lib/ui'
import { PracticeWorkspace } from './components/PracticeWorkspace'
const DESC =
'沙箱写真跑:web runner 沙箱预览与 playground 编辑器同住右缘侧栏——点紫色的「沙箱预览」签直接看沙箱,点「编辑器」签写码;点「运行 ▶」构建产物送进隔离 iframe 执行,并自动切到沙箱页签;侧栏展开时页面罩上灰色蒙版,点蒙版或按 Esc 收回。标题栏右上角「💡 tips」拉出操作流水线,点任意一步,提示词自动填进陪练 agent 输入框,回车即发;验收夹具和 tips 并排在标题栏,点夹具拉出来逐条打勾。'
export function App() {
const nav = siteNavFor('practice')
const flips = flipTargetsOf('practice')
return (
<PageFlipZone prev={flips.prev} next={flips.next}>
<SitePage
sidebar={<SiteSidebar brand={nav.brand} rows={nav.rows} active="practice" />}
nav={nav}
active="practice"
docked
footerGroups={FOOTER_GROUPS}
title="在线练习"
desc={DESC}
>
<div className="mb-4">
<h1 className={`m-0 ${textT1} font-extrabold ${textInk}`}>在线练习</h1>
<p className={`m-0 mt-1.5 ${textContent} ${textMute}`}>
沙箱写真跑:web runner 沙箱预览与 playground
编辑器同住右缘侧栏——点紫色的「沙箱预览」签直接看沙箱,点「编辑器」签写码;点「运行
▶」构建产物送进隔离 iframe
执行,并自动切到沙箱页签;侧栏展开时页面罩上灰色蒙版,点蒙版或按 Esc
收回。标题栏右上角「💡 tips」拉出操作流水线,点任意一步,提示词自动填进陪练 agent
输入框,回车即发;验收夹具和 tips 并排在标题栏,点夹具拉出来逐条打勾。
</p>
</div>
<PracticeWorkspace />
<PageTurnBar from="practice" />
</SitePage>
+2 -2
View File
@@ -6,7 +6,7 @@
- `src/types.ts`:课程域类型(`ChapterId`/`Target`/`Chapter`/`Edge`/`Profile`)
- 章节与图谱:`ChapterTicket`、`EntryGuide`、`MemphisCard`(含 `BrickDots`/`EntryBadge`)、`RoutableCard`/`RoutableScene`、`RouteLine`
- 站点壳:`SiteNavbar`、`SitePage`(含 `SiteFooter`)、`SiteSidebar`——本版仍以 tailwind 工具类书写,靠 app 桥接层消费 token,后续逐步 ve 化
- 站点壳:`SitePage`(含 `SiteFooter`)单一侧栏布局,内部渲染 `SiteSidebar`(桌面左栏常驻、窄屏 checkbox 抽屉);汉堡触发器 `SiteSidebarTrigger` 贴一级标题左侧,页面自带 hero 无 `title` 时独占一行;`docked` 供带视口贴签的页面(如练习场)在窄屏让出顶部一带与右缘通道
- 翻页:`PageFlipZone`(滚轮/键盘蓄力翻页,约定 `html[data-vt]`/sessionStorage `vt`/`data-scroll-root`)
- 拟物学习套件 `learning/`:ClipboardChecklist、FolderTabs、StickyNote、Bookmark、FlashCard、ExperimentFrame、OutputReceipt、TaskEnvelope、Stamp、BrickToolbox、DeliveryManifest、ComparisonBoard、DataFlowBoard;交互骨架(Tabs/FlipCard/ToggleButton)来自 ui-kit,本包做皮与业务文案薄封装,DOM 与类名不变
- `examples/LearningKitGallery.tsx`:12 件标本画廊
@@ -21,5 +21,5 @@ app html 以包说明符引入:`<link rel="stylesheet" href="@idealjs/stack-si
## 已知后续
- `SiteNavbar`/`SiteSidebar`/`MemphisCard` 等剩余 tailwind 类逐步迁 vanilla-extract
- `MemphisCard` 等剩余 tailwind 类逐步迁 vanilla-extract
- `StickyNote`/`ComparisonBoard`(零业务词)整件下沉 ui-kit,样式段随迁
@@ -1,276 +0,0 @@
import { ShadowButton, shadowButtonClasses } from '@idealjs/stack-ui-kit/react'
import {
bgInk,
bgPaper,
bgPaperDeep,
borderInk,
borderInk20,
borderTransparent,
hoverBgPaperDeep,
hoverBorderInk,
lgBgPaper,
lgBorderInk,
lgShadowInkLift,
maxLgBorderInk,
shadowInk,
textBody,
textContent,
textInk,
textT2,
textT3,
} from '@idealjs/stack-ui-kit/components'
import type { CSSProperties, ReactNode } from 'react'
import { Fragment } from 'react'
export interface NavSectionLink {
key: string
label: string
href: string
}
export interface NavItemLink {
key: string
label: string
href: string
color?: string
mono?: boolean
}
export interface NavRowGroup {
sectionKey: string
label: string
href?: string
items: NavItemLink[]
}
const SELECTED = `${bgPaperDeep} ${textInk}`
const IDLE = `${textBody} ${hoverBgPaperDeep}`
const LIGHT_PRESS =
'transition-[transform,background-color,border-color] duration-150 active:translate-y-[1px]'
function RowLabel({
on,
href,
children,
className,
style,
}: {
on: boolean
href?: string
children: ReactNode
className?: string
style?: CSSProperties
}) {
const cls = `w-full rounded-lg border-2 px-2 py-0.5 text-left ${textT3} font-extrabold leading-tight ${LIGHT_PRESS} ${
on ? `${borderInk}` : `${borderTransparent} ${textInk} ${hoverBorderInk}`
} ${className ?? ''}`
if (!href)
return (
<span className={cls} style={style}>
{children}
</span>
)
return (
<a href={href} className={`no-underline ${cls}`} style={style}>
{children}
</a>
)
}
export function SiteNavbar({
brand,
rows,
active,
}: {
brand: NavSectionLink
rows: NavRowGroup[]
active?: string
}) {
const rowOn = (row: NavRowGroup) =>
active === row.sectionKey || row.items.some((i) => i.key === active)
const activeLabel = (() => {
for (const row of rows) {
if (row.sectionKey === active && !row.href) return row.label
const hit = row.items.find((i) => i.key === active)
if (hit) return hit.label
}
return undefined
})()
let bandCursor = 1
const bands = rows.map((row) => {
const divider = bandCursor
const span = Math.max(1, Math.ceil(row.items.length / 6))
const band = { row, divider, start: divider + 1, span }
bandCursor = divider + 1 + span
return band
})
return (
<header
className={`relative max-lg:z-50 lg:z-30 mb-8 rounded-2xl border-2 ${borderInk} ${bgPaper} p-2.5 ${shadowInk}`}
>
<input
id="site-nav-expand"
type="checkbox"
aria-label="展开或收起桌面导航网格"
className="peer/nav-expand sr-only"
/>
<input
id="site-nav-toggle"
type="checkbox"
aria-label="打开或收起导航菜单"
className="peer/nav-drawer sr-only"
/>
<div className="relative z-40 flex flex-wrap items-center gap-1.5 max-lg:peer-checked/nav-drawer:[&_.nav-drawer-open]:invisible max-lg:peer-checked/nav-drawer:[&_.nav-drawer-close]:visible lg:peer-checked/nav-expand:[&_.nav-expand-open]:invisible lg:peer-checked/nav-expand:[&_.nav-expand-close]:visible">
<span className="mr-auto inline-flex">
<ShadowButton
tone="ghost"
href={brand.href}
size="none"
nested
className={`px-2.5 py-0.5 font-mono ${textT2} font-extrabold ${hoverBgPaperDeep}`}
>
{brand.label}
</ShadowButton>
</span>
{activeLabel && (
<span
className={`hidden rounded-lg ${bgPaperDeep} px-2.5 py-0.5 ${textT3} font-extrabold ${textInk} lg:inline-block`}
>
{activeLabel}
</span>
)}
<span className="hidden lg:inline-grid">
{/* biome-ignore lint/a11y/useAriaPropsSupportedByRole: 纯 CSS checkbox 开合的触发 label,aria 状态为增强语义保留 */}
<label
htmlFor="site-nav-expand"
aria-label="展开导航网格"
aria-expanded="false"
aria-controls="site-nav-drawer"
className={`nav-expand-open hidden lg:col-start-1 lg:row-start-1 lg:grid lg:size-10 lg:place-items-center ${shadowButtonClasses({ size: 'none', nested: true, className: `${hoverBgPaperDeep}` })}`}
>
<span aria-hidden="true" className="text-lg font-extrabold leading-none">
▼
</span>
</label>
{/* biome-ignore lint/a11y/useAriaPropsSupportedByRole: 纯 CSS checkbox 开合的触发 label,aria 状态为增强语义保留 */}
<label
htmlFor="site-nav-expand"
aria-label="收起导航网格"
aria-expanded="true"
aria-controls="site-nav-drawer"
className={`nav-expand-close hidden lg:col-start-1 lg:row-start-1 lg:invisible lg:grid lg:size-10 lg:place-items-center ${shadowButtonClasses({ size: 'none', nested: true, className: `${hoverBgPaperDeep}` })}`}
>
<span aria-hidden="true" className="text-lg font-extrabold leading-none">
▲
</span>
</label>
</span>
<span className="hidden max-lg:inline-grid">
{/* biome-ignore lint/a11y/useAriaPropsSupportedByRole: 纯 CSS checkbox 开合的触发 label,aria 状态为增强语义保留 */}
<label
htmlFor="site-nav-toggle"
aria-label="打开导航菜单"
aria-expanded="false"
aria-controls="site-nav-drawer"
className={`nav-drawer-open hidden max-lg:col-start-1 max-lg:row-start-1 max-lg:grid max-lg:size-10 max-lg:place-items-center ${shadowButtonClasses({ size: 'none', nested: true, className: `${hoverBgPaperDeep}` })}`}
>
<span aria-hidden="true" className="flex flex-col gap-[5px]">
<i className={`block h-[3px] w-5 rounded-sm ${bgInk}`} />
<i className={`block h-[3px] w-5 rounded-sm ${bgInk}`} />
<i className={`block h-[3px] w-5 rounded-sm ${bgInk}`} />
</span>
</label>
{/* biome-ignore lint/a11y/useAriaPropsSupportedByRole: 纯 CSS checkbox 开合的触发 label,aria 状态为增强语义保留 */}
<label
htmlFor="site-nav-toggle"
aria-label="收起导航菜单"
aria-expanded="true"
aria-controls="site-nav-drawer"
className={`nav-drawer-close hidden max-lg:col-start-1 max-lg:row-start-1 max-lg:invisible max-lg:grid max-lg:size-10 max-lg:place-items-center ${shadowButtonClasses({ size: 'none', nested: true, className: `${hoverBgPaperDeep}` })}`}
>
<span aria-hidden="true" className="text-lg font-extrabold leading-none">
×
</span>
</label>
</span>
</div>
<div
id="site-nav-drawer"
className={`max-lg:fixed max-lg:inset-y-0 max-lg:left-0 max-lg:z-50 max-lg:w-72 max-lg:overflow-y-auto max-lg:rounded-none max-lg:border-r-2 ${maxLgBorderInk} max-lg:bg-paper max-lg:px-4 max-lg:py-5 max-lg:shadow-[8px_0_0_0_var(--color-ink)] max-lg:invisible max-lg:opacity-0 max-lg:-translate-x-full max-lg:transition-[transform,visibility,opacity] max-lg:duration-300 max-lg:ease-[cubic-bezier(0.32,0.72,0,1)] max-lg:motion-reduce:transition-none max-lg:peer-checked/nav-drawer:visible max-lg:peer-checked/nav-drawer:translate-x-0 max-lg:peer-checked/nav-drawer:opacity-100 lg:pointer-events-none lg:absolute lg:inset-x-0 lg:top-full lg:z-40 lg:mt-2 lg:rounded-2xl lg:border-2 ${lgBorderInk} ${lgBgPaper} lg:p-3 ${lgShadowInkLift} lg:invisible lg:opacity-0 lg:-translate-y-1 lg:transition-[transform,visibility,opacity] lg:duration-300 lg:ease-[cubic-bezier(0.32,0.72,0,1)] lg:motion-reduce:transition-none lg:peer-checked/nav-expand:pointer-events-auto lg:peer-checked/nav-expand:visible lg:peer-checked/nav-expand:opacity-100 lg:peer-checked/nav-expand:translate-y-0`}
>
<div className="lg:hidden max-lg:mb-5">
<ShadowButton
tone="ghost"
href={brand.href}
size="sm"
nested
className={`font-mono ${hoverBgPaperDeep}`}
>
{brand.label}
</ShadowButton>
</div>
<div className="grid gap-x-1.5 gap-y-2 max-lg:grid-cols-2 lg:grid-cols-[96px_repeat(6,minmax(0,1fr))]">
{bands.map(({ row, divider, start, span }) => (
<Fragment key={row.sectionKey}>
<div
aria-hidden="true"
className={`col-span-full border-t border-dashed ${borderInk20} lg:[grid-column:1/-1] lg:[grid-row:var(--divider)]`}
style={{ '--divider': divider } as CSSProperties}
/>
<RowLabel
on={rowOn(row)}
href={row.href}
className="self-start max-lg:col-span-2 lg:[grid-column:1] lg:[grid-row:var(--band)]"
style={{ '--band': `${start} / span ${span}` } as CSSProperties}
>
{row.label}
</RowLabel>
<div
className="grid min-w-0 gap-1.5 max-lg:col-span-2 max-lg:grid-cols-2 lg:col-span-6 lg:col-start-2 lg:grid-cols-subgrid lg:[grid-row:var(--band)]"
style={{ '--band': `${start} / span ${span}` } as CSSProperties}
>
{row.items.map((item) => {
const on = item.key === active
return (
<a
key={item.key}
href={item.href}
className={`rounded-lg px-2.5 py-0.5 text-left ${textContent} font-bold leading-snug no-underline ${LIGHT_PRESS} ${
on ? (item.color ? `${textInk}` : SELECTED) : IDLE
} ${item.mono ? 'font-mono' : ''}`}
style={on && item.color ? { background: item.color } : undefined}
>
{item.label}
</a>
)
})}
</div>
</Fragment>
))}
</div>
</div>
{/* biome-ignore lint/a11y/noLabelWithoutControl: 遮罩 label 关联的 checkbox 由纯 CSS 开合机制持有 */}
<label
htmlFor="site-nav-toggle"
aria-hidden="true"
className={`hidden max-lg:fixed max-lg:inset-0 max-lg:z-40 max-lg:block max-lg:cursor-pointer max-lg:bg-ink/40 max-lg:invisible max-lg:opacity-0 max-lg:transition-[visibility,opacity] max-lg:duration-300 max-lg:ease-[cubic-bezier(0.32,0.72,0,1)] max-lg:motion-reduce:transition-none max-lg:peer-checked/nav-drawer:visible max-lg:peer-checked/nav-drawer:opacity-100`}
/>
{/* biome-ignore lint/a11y/noLabelWithoutControl: 桌面透明遮罩,点导航网格外任意处收起 overlay */}
<label
htmlFor="site-nav-expand"
aria-hidden="true"
className="hidden lg:fixed lg:inset-0 lg:z-20 lg:block lg:cursor-pointer lg:invisible lg:peer-checked/nav-expand:visible"
/>
</header>
)
}
@@ -1,8 +1,9 @@
import type { ReactNode } from 'react'
import type { NavRowGroup, NavSectionLink } from './SiteNavbar'
import { SiteNavbar } from './SiteNavbar'
import type { NavRowGroup, NavSectionLink } from './SiteSidebar'
import { SiteSidebar, SiteSidebarTrigger } from './SiteSidebar'
import {
contentColumn,
contentColumnDocked,
footer,
footerCopyright,
footerDot,
@@ -10,20 +11,15 @@ import {
footerLabel,
footerLink,
footerRow,
footerWrap,
footerWrapSticky,
navShellPad,
navSticky,
pageDesc,
pageHead,
pageScroller,
pageSubtitle,
pageTitle,
sidebarColumn,
pageTrigger,
sidebarLayout,
sidebarMain,
siteShell,
siteShellSlim,
} from './sitePage.css'
export interface SiteNav {
@@ -31,6 +27,64 @@ export interface SiteNav {
rows: NavRowGroup[]
}
export function SitePage({
nav,
active,
docked = false,
footerGroups,
title,
subtitle,
desc,
children,
}: SitePageProps) {
const head = title || subtitle || desc
return (
<div className={sidebarLayout}>
<SiteSidebar brand={nav.brand} rows={nav.rows} active={active} />
<main data-scroll-root className={sidebarMain}>
<div className={docked ? contentColumnDocked : contentColumn}>
{head ? (
<div className={pageHead}>
<SiteSidebarTrigger />
{title && <h1 className={pageTitle}>{title}</h1>}
{subtitle && <p className={pageSubtitle}>{subtitle}</p>}
{desc && <p className={pageDesc}>{desc}</p>}
</div>
) : (
<div className={pageTrigger}>
<SiteSidebarTrigger />
</div>
)}
{children}
</div>
<div className={footerWrapSticky} style={{ viewTransitionName: 'site-footer' }}>
<div className={`${siteShell} pb-6`}>
<SiteFooter groups={footerGroups} />
</div>
</div>
</main>
</div>
)
}
export interface SitePageProps {
nav: SiteNav
active?: string
docked?: boolean
footerGroups: SiteFooterGroup[]
title?: string
subtitle?: string
desc?: string
children: ReactNode
}
export interface SiteFooterGroup {
label: string
links: { href: string; label: string }[]
@@ -58,77 +112,3 @@ export function SiteFooter({ groups }: { groups: SiteFooterGroup[] }) {
</footer>
)
}
export function SitePage({
nav,
active,
viewTransitionName,
sidebar,
footerGroups,
title,
subtitle,
desc,
children,
}: SitePageProps) {
if (sidebar) {
return (
<div className={sidebarLayout}>
{sidebar}
<div className={sidebarColumn}>
<main className={sidebarMain}>{children}</main>
<div className={footerWrap} style={{ viewTransitionName: 'site-footer' }}>
<div className={`${siteShellSlim} pb-6`}>
<SiteFooter groups={footerGroups} />
</div>
</div>
</div>
</div>
)
}
return (
<main data-scroll-root className={pageScroller}>
{nav && (
<div className={navSticky} style={viewTransitionName ? { viewTransitionName } : undefined}>
<div className={`${siteShell} ${navShellPad}`}>
<SiteNavbar brand={nav.brand} rows={nav.rows} active={active} />
</div>
</div>
)}
<div className={contentColumn}>
{(title || subtitle || desc) && (
<div className={pageHead}>
{title && <h1 className={pageTitle}>{title}</h1>}
{subtitle && <p className={pageSubtitle}>{subtitle}</p>}
{desc && <p className={pageDesc}>{desc}</p>}
</div>
)}
{children}
</div>
<div className={footerWrapSticky} style={{ viewTransitionName: 'site-footer' }}>
<div className={`${siteShell} pb-6`}>
<SiteFooter groups={footerGroups} />
</div>
</div>
</main>
)
}
export interface SitePageProps {
nav?: SiteNav
active?: string
viewTransitionName?: string
sidebar?: ReactNode
footerGroups: SiteFooterGroup[]
title?: string
subtitle?: string
desc?: string
children: ReactNode
}
@@ -6,7 +6,6 @@ import {
textBody,
textInk,
} from '@idealjs/stack-ui-kit/components'
import type { NavRowGroup, NavSectionLink } from './SiteNavbar'
import {
brandRow,
burgerBar,
@@ -24,9 +23,33 @@ import {
rowSelectedInset,
toggleInput,
triggerButton,
triggerWrap,
triggerDock,
} from './siteSidebar.css'
export interface NavSectionLink {
key: string
label: string
href: string
}
export interface NavItemLink {
key: string
label: string
href: string
color?: string
mono?: boolean
}
export interface NavRowGroup {
sectionKey: string
label: string
href?: string
items: NavItemLink[]
}
const SELECTED = `${bgPaperDeep} ${textInk} ${rowSelectedInset}`
const IDLE = `${textBody} ${hoverBgPaperDeep}`
@@ -50,23 +73,6 @@ export function SiteSidebar({
className={toggleInput}
/>
<span className={`${hoverHost} ${triggerWrap}`}>
{/* biome-ignore lint/a11y/useAriaPropsSupportedByRole: 纯 CSS checkbox 开合的触发 label,aria 状态为增强语义保留 */}
<label
htmlFor="site-sidebar-toggle"
aria-label="打开侧栏导航"
aria-expanded="false"
aria-controls="site-sidebar-drawer"
className={`${triggerButton} ${shadowButtonClasses({ size: 'none' })}`}
>
<span aria-hidden="true" className={burgerStack}>
<i className={burgerBar} />
<i className={burgerBar} />
<i className={burgerBar} />
</span>
</label>
</span>
<aside id="site-sidebar-drawer" className={drawer}>
<div className={brandRow}>
<ShadowButton
@@ -133,3 +139,24 @@ export function SiteSidebar({
</>
)
}
export function SiteSidebarTrigger() {
return (
<span className={`${hoverHost} ${triggerDock}`}>
{/* biome-ignore lint/a11y/useAriaPropsSupportedByRole: 纯 CSS checkbox 开合的触发 label,aria 状态为增强语义保留 */}
<label
htmlFor="site-sidebar-toggle"
aria-label="打开侧栏导航"
aria-expanded="false"
aria-controls="site-sidebar-drawer"
className={`${triggerButton} ${shadowButtonClasses({ size: 'none' })}`}
>
<span aria-hidden="true" className={burgerStack}>
<i className={burgerBar} />
<i className={burgerBar} />
<i className={burgerBar} />
</span>
</label>
</span>
)
}
@@ -1,6 +1,9 @@
import { theme } from '@idealjs/stack-ui-kit/tokens'
import { style } from '@vanilla-extract/css'
const narrow = 'screen and (max-width: 63.999rem)'
const desktop = 'screen and (min-width: 96rem)'
const shellBase = {
marginLeft: 'auto',
marginRight: 'auto',
@@ -8,27 +11,24 @@ const shellBase = {
maxWidth: '1200px',
}
const shellDesktop = { '@media': { [desktop]: { maxWidth: '1600px' } } }
export const siteShell = style({
...shellBase,
paddingLeft: '1.5rem',
paddingRight: '1.5rem',
'@media': {
'screen and (min-width: 96rem)': { maxWidth: '1600px' },
},
...shellDesktop,
})
export const siteShellSlim = style({
...shellBase,
paddingLeft: '0.75rem',
paddingRight: '0.75rem',
'@media': {
'screen and (min-width: 96rem)': { maxWidth: '1600px' },
},
})
export const pageScroller = style({
export const sidebarLayout = style({
display: 'flex',
height: '100dvh',
})
export const sidebarMain = style({
display: 'flex',
minWidth: 0,
flexGrow: 1,
flexDirection: 'column',
overflowY: 'auto',
fontSize: theme.text.content,
@@ -36,77 +36,45 @@ export const pageScroller = style({
color: theme.color.body,
})
export const sidebarLayout = style({
display: 'flex',
minHeight: '100dvh',
fontSize: theme.text.content,
lineHeight: `var(--tw-leading, ${theme.text['content--line-height']})`,
color: theme.color.body,
})
export const sidebarColumn = style({
display: 'flex',
minWidth: 0,
flexGrow: 1,
flexDirection: 'column',
})
export const sidebarMain = style({
...shellBase,
minWidth: 0,
flexGrow: 1,
paddingTop: '1rem',
paddingBottom: '1rem',
paddingLeft: '0.75rem',
paddingRight: '0.75rem',
'@media': {
'screen and (max-width: 63.999rem)': {
paddingTop: '4rem',
paddingRight: '3rem',
},
'screen and (min-width: 96rem)': { maxWidth: '1600px' },
},
})
export const footerWrap = style({
display: 'flex',
flex: 'none',
backgroundColor: theme.color.paper,
})
export const footerWrapSticky = style({
position: 'sticky',
bottom: 0,
marginTop: 'auto',
flex: 'none',
backgroundColor: theme.color.paper,
})
export const navSticky = style({
position: 'sticky',
top: 0,
zIndex: 50,
flex: 'none',
backgroundColor: theme.color.paper,
})
export const navShellPad = style({ paddingTop: '2rem' })
export const contentColumn = style({
...shellBase,
flexGrow: 1,
paddingTop: '1rem',
paddingBottom: '2rem',
paddingLeft: '1.5rem',
paddingRight: '1.5rem',
...shellDesktop,
})
export const contentColumnDocked = style([
contentColumn,
{
'@media': {
[narrow]: { paddingTop: '4rem', paddingRight: '3rem' },
},
},
])
export const pageHead = style({
display: 'grid',
alignItems: 'start',
columnGap: '0.75rem',
gridTemplateColumns: 'minmax(0, 1fr)',
marginBottom: '1.75rem',
'@media': {
'screen and (min-width: 96rem)': { maxWidth: '1600px' },
[narrow]: { gridTemplateColumns: 'auto minmax(0, 1fr)' },
},
})
export const pageHead = style({ marginBottom: '1.75rem' })
export const pageTrigger = style({
'@media': {
[narrow]: { display: 'flex', marginBottom: '1.75rem' },
},
})
export const pageTitle = style({
margin: 0,
minWidth: 0,
fontSize: theme.text.t1,
lineHeight: `var(--tw-leading, ${theme.text['t1--line-height']})`,
fontWeight: 800,
@@ -114,6 +82,7 @@ export const pageTitle = style({
})
export const pageSubtitle = style({
gridColumn: '1 / -1',
margin: 0,
marginTop: '0.5rem',
fontSize: theme.text.t2,
@@ -123,6 +92,7 @@ export const pageSubtitle = style({
})
export const pageDesc = style({
gridColumn: '1 / -1',
margin: 0,
marginTop: '0.5rem',
fontSize: theme.text.content,
@@ -130,6 +100,14 @@ export const pageDesc = style({
color: theme.color.mute,
})
export const footerWrapSticky = style({
position: 'sticky',
bottom: 0,
marginTop: 'auto',
flex: 'none',
backgroundColor: theme.color.paper,
})
export const footer = style({
borderTopWidth: 2,
borderTopStyle: 'dashed',
@@ -4,6 +4,7 @@ import { style } from '@vanilla-extract/css'
const narrow = 'screen and (max-width: 63.999rem)'
const wide = 'screen and (min-width: 64rem)'
const EASE_DRAWER = 'cubic-bezier(0.32, 0.72, 0, 1)'
const TRIGGER_SIZE = '2.5rem'
export const toggleInput = style({
position: 'absolute',
@@ -17,21 +18,20 @@ export const toggleInput = style({
borderWidth: 0,
})
export const triggerWrap = style({
position: 'fixed',
top: '0.75rem',
left: '0.75rem',
zIndex: 40,
export const triggerDock = style({
'@media': {
[narrow]: { display: 'inline-grid' },
[narrow]: {
display: 'inline-flex',
marginTop: `calc((${theme.text.t1} * ${theme.text['t1--line-height']} - ${TRIGGER_SIZE}) / 2)`,
},
[wide]: { display: 'none' },
},
})
export const triggerButton = style({
display: 'grid',
height: '2.5rem',
width: '2.5rem',
height: TRIGGER_SIZE,
width: TRIGGER_SIZE,
cursor: 'pointer',
placeItems: 'center',
})
@@ -81,11 +81,9 @@ export const drawer = style({
},
},
[wide]: {
position: 'sticky',
top: 0,
height: '100dvh',
width: '15rem',
flexShrink: 0,
viewTransitionName: 'site-sidebar',
},
'(prefers-reduced-motion: reduce)': {
transitionProperty: 'none',
+1 -3
View File
@@ -38,10 +38,8 @@ export type { PinActions } from './components/RoutableCard'
export { RoutableCard, RoutableScene } from './components/RoutableCard'
export type { LaneNode } from './components/RouteLine'
export { RouteLine } from './components/RouteLine'
export type { NavItemLink, NavRowGroup, NavSectionLink } from './components/SiteNavbar'
export { SiteNavbar } from './components/SiteNavbar'
export type { SiteFooterGroup, SiteNav, SitePageProps } from './components/SitePage'
export { SiteFooter, SitePage } from './components/SitePage'
export { SiteSidebar } from './components/SiteSidebar'
export type { NavItemLink, NavRowGroup, NavSectionLink } from './components/SiteSidebar'
export { LearningKitGallery } from './examples/LearningKitGallery'
export * from './types'
@@ -41,12 +41,12 @@
html[data-vt]::view-transition-group(root) {
background: var(--color-paper);
}
html[data-vt]::view-transition-group(site-header),
html[data-vt]::view-transition-group(site-sidebar),
html[data-vt]::view-transition-group(site-footer) {
z-index: 10;
}
html[data-vt]::view-transition-old(site-header),
html[data-vt]::view-transition-new(site-header),
html[data-vt]::view-transition-old(site-sidebar),
html[data-vt]::view-transition-new(site-sidebar),
html[data-vt]::view-transition-old(site-footer),
html[data-vt]::view-transition-new(site-footer) {
animation: none;
+1 -1
View File
@@ -20,7 +20,7 @@ for (const target of PAGES) {
await page.goto(`${BASE_URL}${target.path}`)
await page.addStyleTag({
content:
'[data-scroll-root]{max-height:none!important;overflow:visible!important;height:auto!important}',
'[data-scroll-root]{max-height:none!important;overflow:visible!important;height:auto!important}div:has(>[data-scroll-root]){height:auto!important}',
})
await page.evaluate(() => document.fonts.ready)
await page.waitForTimeout(500)