JGuang

页面布局

Layout · Astryx

交互预览
npm install @astryxdesign/core@0.7.1 @astryxdesign/theme-neutral@0.7.1 @stylexjs/stylex@0.19.0

页面布局 · Layout

使用头部、内容、侧面板和页脚插槽构建页面。

安装与前置条件

npm install @astryxdesign/core@0.7.1 @astryxdesign/theme-neutral@0.7.1 @stylexjs/stylex@0.19.0

需要 React 19+,按顺序导入基础 CSS 和主题,并设置 Theme Provider。参见开始使用。

示例与使用方式

  • 页面布局 · 综合展示 1:首先体验这个示例,再查看代码理解组件的组合方式。
  • 页面布局 · 综合展示 2:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 综合展示 3:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 综合展示 4:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 综合展示 5:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 基础用法 6:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 基础用法 7:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 交互示例 8:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 交互示例 9:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 交互示例 10:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 交互示例 11:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 交互示例 12:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 交互示例 13:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 交互示例 14:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。
  • 页面布局 · 交互示例 15:可交互查看这一用法的行为,复制代码时保留它实际使用的属性与导入。

API 与上游详细参考

优先使用 0.7.1 官方中文说明;上游尚未提供中文的条目保留英文。属性名、类型及默认值保持原生 API,不把示例状态名称当成组件属性。

Layout

Layout is a general five-slot primitive for arranging header, start, content, end, and footer regions within a page or bounded container. AppShell owns the page shell and app-wide navigation behavior; use HStack or VStack for simple directional stacking.

属性类型默认值说明
contentReactNodeContent slot (center). Accepts any ReactNode; use LayoutContent when a content region is needed. Children passed to <Layout> render here too: <Layout>{main}</Layout> is shorthand for <Layout content={main} />.
headerReactNodeHeader slot. Accepts any ReactNode; use LayoutHeader when a header region is needed.
footerReactNodeFooter slot. Accepts any ReactNode; use LayoutFooter when a footer region is needed.
startReactNodeLogical-start slot (left in LTR). Accepts any ReactNode; use LayoutPanel when a panel region is needed.
endReactNodeLogical-end slot (right in LTR). Accepts any ReactNode; use LayoutPanel when a panel region is needed.
height'fill' | 'auto''fill'Height behavior: fill the container or grow with content.
contentWidthSizeValueMaximum width of the aligned content within each slot (header, content, footer, panels), centered when narrower than the available space. Without panels, LayoutContent spans the available width so its scrollbar stays at the outer edge while its children align internally to contentWidth. With exactly one panel, the panel stays aligned to the contentWidth frame while LayoutContent extends to the opposite open edge. With both panels, contentWidth includes the complete middle composition. Percentage widths—including percentage-bearing calc(), min(), max(), and clamp() values—and intrinsic widths, plus bare var(...) values, retain the constrained composition; use calc(var(...)) for a variable guaranteed to resolve to a length. Dividers stay full-bleed. Numbers are treated as pixels, strings are used as-is (e.g. 60ch). Common page widths: 640 for forms, settings, and text-focused pages; 960 for content pages and wider layouts.
padding0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10Padding at the layout's outer edges using the spacing scale. Applies to this Layout's own header, footer, panels, and content. A nested Layout does not inherit it: without padding, its regions use the enclosing Card, Section, or Dialog padding, or the default inset (spacing 4). That keeps a page Layout inside AppShell inset even though AppShell's own regions are full bleed.
defaultHasDividersbooleanDefault divider visibility for LayoutHeader and LayoutFooter children. Headers and footers that don't pass hasDivider use this value; when unset, nested layouts inherit from their parent context.

使用建议

  • Use Layout when content needs named header, start, content, end, or footer regions.
  • Use HStack and VStack for simple directional stacking within a content area.
  • 避免:Use Layout for simple stacking layouts; use HStack or VStack instead.
  • 避免:Use Layout as the page shell or for app-wide navigation; use AppShell for that responsibility.

Page with a details panel inside AppShell

function OrdersPage() {
  return (
    <AppShell
      sideNav={
        <SideNav>
          <SideNavItem label="Orders" isSelected />
          <SideNavItem label="Customers" />
          <SideNavItem label="Settings" />
        </SideNav>
      }>
      {/* No padding props needed: the page Layout's regions keep their
          default inset inside AppShell's full-bleed content area. */}
      <Layout
        header={
          <LayoutHeader hasDivider>
            <Heading level={1}>Orders</Heading>
          </LayoutHeader>
        }
        end={
          <LayoutPanel
            hasDivider
            width={320}
            role="complementary"
            label="Order details">
            <VStack gap={2}>
              <Heading level={2}>Order #1042</Heading>
              <Text type="body" color="secondary">
                Shipped · 3 items · $184.00
              </Text>
            </VStack>
          </LayoutPanel>
        }
        content={
          <LayoutContent>
            <Text type="body">
              Select an order to see its shipping and payment details.
            </Text>
          </LayoutContent>
        }
      />
    </AppShell>
  );
}

主题 API

{
  "targets": [
    {
      "className": "astryx-layout",
      "visualProps": [
        "height"
      ]
    },
    {
      "className": "astryx-layout-content"
    },
    {
      "className": "astryx-layout-footer"
    },
    {
      "className": "astryx-layout-header"
    },
    {
      "className": "astryx-layout-panel"
    }
  ]
}

LayoutHeader

LayoutContent

LayoutFooter

LayoutPanel

Card

Section

组件结构

  • Layout container: General layout primitive that places the header, start, content, end, and footer slots.
  • Header: Optional LayoutHeader region supplied by the caller, typically in the header slot.
  • Panel: Optional LayoutPanel region supplied by the caller in the start or end slot.
  • Content area: Optional LayoutContent region supplied by the caller in the content slot.
  • Footer: Optional LayoutFooter region supplied by the caller, typically in the footer slot.

Layout Content

可滚动的主内容区域。

属性类型默认值说明
childrenReactNode内容。
padding0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10使用间距比例的内边距。覆盖布局容器的默认内边距。
isScrollablebooleantrue启用可滚动溢出。设置可参与算术计算的 contentWidth 时,滚动区域会延伸到所有未被面板占用的边缘,同时根据上下文调整内边距以保持子内容对齐。
labelstring地标元素的无障碍标签。
roleAriaRoleARIA 地标角色。

用于操作栏、分页和状态栏的底部栏。

属性类型默认值说明
childrenReactNode页脚内容。
hasDividerbooleanfalse顶部边缘的边框。
heightSizeValue页脚高度。数字类型会被解释为像素值,字符串类型按原样使用。
labelstring地标元素的无障碍标签。
roleAriaRoleARIA 地标角色。

Layout Header

用于页面标题、应用栏和工具栏的顶部栏。

属性类型默认值说明
childrenReactNode页眉内容。
hasDividerbooleanfalse底部边缘的边框。
heightSizeValue页眉高度。数字类型会被解释为像素值,字符串类型按原样使用。
labelstring地标元素的无障碍标签。
paddingBlockEnd0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10块结束(底部)内边距,使用间距刻度。仅在该边上覆盖 padding;paddingBlockEnd={0} 将最后一个子元素停靠在页眉底边。
roleAriaRoleARIA 地标角色。

Layout Panel

用于导航、设置或检查器面板的侧边栏。

属性类型默认值说明
childrenReactNode面板内容。
hasDividerbooleanfalse相应边缘的边框。
padding0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10使用间距比例的内边距。覆盖布局容器的默认内边距。
isScrollablebooleantrue启用可滚动溢出。
labelstring地标元素的无障碍标签。
roleAriaRoleARIA 地标角色。
widthnumber | string面板宽度。数字按像素处理,字符串按原样使用。提供 resizable 时忽略,宽度由 hook 控制。
resizableResizableProps来自 useResizable() 的调整大小属性。提供时面板宽度由 hook 驱动,应在面板旁放置 ResizeHandle。其中携带区域的轴向('horizontal' | 'vertical'),必须与相邻 ResizeHandle 的 direction 一致。