Files
timi-tdesign-mobile/src/assets/style/page-layout.less
T
Timi ba0c7bf9a2 feat: master-detail third pane
- MasterDetail / MasterDetailPage: add `sub` prop and `#sub` slot. The three
  columns share one container and are placed by left/right, so the detail pane
  moves between columns without remounting and keeps its scroll position.
- useMasterDetailPane: add subView / openSub / closeSub, keep the sub view in
  query and browser history alongside detail and view.
- page-layout: sub pane reuses the in-pane navbar rules; the list navbar slides
  out on the third level instead of being hidden.
- docs: demos for the third pane, the layered navbars and PaneTransition;
  restore transition durations in demo previews under prefers-reduced-motion,
  where VitePress zeroes them. Fix the missing `split` ref in the master-detail
  demo and the incorrect note about the back arrow.
2026-11-11 23:55:30 +08:00

249 lines
8.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 主从分栏展开/收起时长。
*
* MasterDetail 的主栏宽度和这里列表页导航栏的宽度必须同步,
* 所以时长只在这一处定义,两边都引用它。
*/
:root {
--tui-split-duration: 320ms;
}
/**
* 页面骨架样式。
*
* 需与 PageTransition 配合使用:页面根节点加 .tui-page-layout,
* 内容区加 .tui-page-content。
* - 有顶部导航栏时,根节点追加 .tui-navbar;
* - 需要为底部导航栏留出空白时,再追加 .tui-tabbar。
*
* .tui-page-content 使用绝对定位铺满上级容器,因此上级必须是
* PageTransition 渲染出的定位容器,不要在普通 div 中直接使用。
*/
/**
* 主从分栏里详情栏的空白态容器:占满右栏并垂直居中,顶部让出导航栏。
*
* 用在 <master-detail> 的 #detail 插槽里,省去每个页面自己写 height 和内边距。
* 已经给 master-detail 传了 top-inset 的话,用 --tui-detail-empty-inset 把默认值改掉,避免叠加。
*/
.tui-detail-empty {
height: 100%;
display: flex;
box-sizing: border-box;
align-items: center;
justify-content: center;
padding-top: var(--tui-detail-empty-inset, calc(var(--safe-area-inset-top, env(safe-area-inset-top, 0px)) + 48px));
// 必须有不透明背景:切换视图时它和旧内容同时在场,
// 透明的话提示文字会浮在还在滑出的页面上,看起来像重影。
background: var(--tui-detail-empty-background, var(--td-bg-color-page));
}
.tui-page-layout {
min-height: 100vh;
box-sizing: border-box;
color: var(--td-text-color-primary);
background: var(--td-bg-color-page);
.tui-page-content {
flex: 1;
inset: 0;
width: 100%;
display: flex;
overflow: hidden;
position: absolute;
min-height: 0;
box-sizing: border-box;
padding-top: calc(var(--safe-area-inset-top, env(safe-area-inset-top, 0px)) + 48px + 1rem);
padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
flex-direction: column;
&.scroll {
overflow: auto;
-webkit-overflow-scrolling: touch;
}
&.column {
gap: 1rem;
display: flex;
flex-direction: column;
&.scroll > * {
flex-shrink: 0;
}
}
}
&.tui-navbar {
--tui-nav-height: calc(var(--safe-area-inset-top, env(safe-area-inset-top, 0px)) + 48px);
--td-navbar-padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
.t-navbar__content,
.t-navbar__placeholder {
height: var(--tui-nav-height);
box-sizing: border-box;
}
.t-navbar__content {
color: var(--td-text-color-primary);
overflow: visible;
box-shadow: 0 3px 8px rgba(0, 0, 0, .1);
background: var(--tui-navbar-background, color-mix(in srgb, var(--td-bg-color-container) 85%, transparent));
-webkit-backdrop-filter: blur(var(--tui-backdrop-blur, 10px));
backdrop-filter: blur(var(--tui-backdrop-blur, 10px));
}
&.tui-tabbar {
.tui-page-content.scroll,
.tui-page-content.column {
padding-bottom: 6rem;
}
}
}
}
/**
* 左侧导航栏出现后,TDesign 导航栏的 fixed 内容需要让出左侧宽度,
* 否则会整条横跨到导航栏上方。
*/
.tui-app-shell.is-rail {
.rail {
padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
}
.t-navbar--fixed .t-navbar__content {
left: var(--tui-fixed-left, 0px);
}
/**
* 转场期间页面带 transform 且整体已经右移,fixed 元素改为相对页面定位,
* 不能再叠加一次导航栏宽度,否则顶部导航左侧会空出一格。
*/
.page-transition-page[class*="push-"] .t-navbar--fixed .t-navbar__content {
left: 0;
}
}
/**
* 贴着内容区定位的 fixed 元素(底部操作栏、悬浮按钮等)。
*
* 加上这个类后会避开左侧导航栏,并与内容区保持 --tui-fixed-gap 的边距。
*/
.tui-fixed-inset {
left: calc(var(--tui-fixed-left, 0px) + var(--tui-fixed-gap, 1rem)) !important;
right: var(--tui-fixed-gap, 1rem) !important;
}
/**
* 双栏导航:分栏时左右各一条头部,而不是一条横跨全宽的导航栏。
*
* 思路是把列表页的导航栏收缩到主栏宽度,详情页的导航栏退化成栏内头部。
* 两者都在 y=0 起算、高度一致,看起来就是一条被分开的工具栏。
*
* 全部依赖 :has(),老浏览器里整块失效,退化为单导航栏,不影响功能。
* 注意不能用 transform 限制 fixed:那会连详情页里的弹层一起锁进栏位。
*/
// 主从分栏的曲线,和 MasterDetail 共用;时长统一走 --tui-split-duration
@split-easing: var(--tui-bezier, cubic-bezier(.19, 1, .22, 1));
/**
* 主从分栏的详情栏里,入场动画要短一些。
*
* 整页进入用 400ms 是合适的,但在右栏展开的同一时间播 400ms,
* 内容会比列表缩窄晚 300ms 才完全显现,看起来像"详情跟不上"。
*/
.tui-master-detail .detail .entrance-fade-up-enter-active,
.tui-master-detail .sub .entrance-fade-up-enter-active {
transition-duration: 200ms;
}
@supports selector(:has(*)) {
// 分栏时内容区整体上移,两栏各自从顶部开始
.tui-page-layout:has(> .tui-page-content > .tui-master-detail.split) > .tui-page-content {
padding-top: 0;
}
// 列表页导航栏收缩到主栏宽度,右侧让给详情栏的头部。
// 时长/曲线与 master-detail 里的主栏过渡保持一致,两者必须同步到位。
.tui-page-layout:has(> .tui-page-content > .tui-master-detail.split) > .t-navbar--fixed .t-navbar__content {
right: auto;
width: var(--tui-master-width, 380px);
transition:
width var(--tui-split-duration, 320ms) @split-easing,
margin-left var(--tui-split-duration, 320ms) @split-easing,
opacity .12s ease-out;
}
/**
* 第三层:列表整列滑出,列表页的导航栏跟着让位。
*
* 用 margin-left 而不是 transform——导航栏里可能有弹层,transform 会把它们锁进来。
* 宽度不变、只是移出可视区,回退时按原路滑回,不用重新测量。
*/
.tui-page-layout:has(> .tui-page-content > .tui-master-detail.split.has-sub) > .t-navbar--fixed .t-navbar__content {
margin-left: calc(-1 * var(--tui-master-width, 380px));
opacity: 0;
pointer-events: none;
}
// 详情未选中、主栏占满时,导航栏也要满宽。
// fixed 的 100% 是视口宽度,还得扣掉左侧 rail,才和内容区对齐。
.tui-page-layout:has(> .tui-page-content > .tui-master-detail.split.is-collapsed) > .t-navbar--fixed .t-navbar__content {
width: calc(100% - var(--tui-fixed-left, 0px));
}
// push 转场时 fixed 改以页面容器为定位基准,页面宽度已避开 rail,不能再次扣除 rail。
.tui-app-shell.is-rail .page-transition-page[class*="push-"] .tui-page-layout:has(> .tui-page-content > .tui-master-detail.split.is-collapsed) > .t-navbar--fixed .t-navbar__content {
left: 0;
right: 0;
width: auto;
}
// 详情栏、子页栏放的是整页组件时:栏位本身不再滚动,改由页面内容区滚动
.tui-master-detail .detail:has(> .tui-page-layout),
.tui-master-detail .sub:has(> .tui-page-layout) {
display: flex;
overflow: hidden;
padding-top: 0;
flex-direction: column;
}
.tui-master-detail .detail > .tui-page-layout,
.tui-master-detail .sub > .tui-page-layout {
height: 100%;
display: flex;
min-height: 0;
flex-direction: column;
}
// 页面导航栏浮在内容之上,而不是占位:这样滚动内容才能穿进它的毛玻璃层
.tui-master-detail .detail > .tui-page-layout > .t-navbar--fixed,
.tui-master-detail .sub > .tui-page-layout > .t-navbar--fixed {
top: 0;
left: 0;
right: 0;
z-index: 20;
position: absolute;
}
// 栏内定位是相对栏位算的,必须清掉 rail 留下的左偏移,否则整条导航右移 96px
.tui-master-detail .detail > .tui-page-layout > .t-navbar--fixed .t-navbar__content,
.tui-master-detail .sub > .tui-page-layout > .t-navbar--fixed .t-navbar__content {
left: 0;
right: 0;
position: relative;
}
// 内容区铺满栏位,顶部内边距沿用页面骨架的导航高度,滚上去就被导航盖住
.tui-master-detail .detail > .tui-page-layout > .tui-page-content,
.tui-master-detail .sub > .tui-page-layout > .tui-page-content {
flex: 1;
position: static;
}
}