JGuang

Layout

Layout · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Layout

Handling the overall layout of a page.

Specification

Size

The first level navigation is left aligned near a logo, and the secondary menu is right aligned.

  • Top Navigation: the height of the first level navigation is 64px, and the second level navigation is 48px.
  • Top Navigation (for landing pages): the height of the first level navigation is 80px, and the second level navigation is 56px.
  • Calculation formula of a top navigation: 48+8n.
  • Calculation formula of an aside navigation: 200+8n.

Interaction rules

  • The first level navigation and the last level navigation should be distinguishable by visualization;
  • The current item should have the highest priority of visualization;
  • When the current navigation item is collapsed, the style of the current navigation item is applied to its parent level;
  • The left side navigation bar has support for both the accordion and expanding styles; you can choose the one that fits your case the best.

Visualization rules

Style of a navigation should conform to its level.

  • Emphasis by colorblock

    When the background color is a deep color, you can use this pattern for the parent level navigation item of the current page.

  • The highlight match stick

    When the background color is a light color, you can use this pattern for the current page navigation item; we recommend using it for the last item of the navigation path.

  • Highlighted font

    From the visualization aspect, a highlighted font is stronger than colorblock; this pattern is often used for the parent level of the current item.

  • Enlarge the size of the font

    12px, 14px is a standard font size of navigation's, 14px is used for the first and the second level of the navigation. You can choose an appropriate font size regarding the level of your navigation.

Component Overview

  • Layout: The layout wrapper, in which Header Sider Content Footer or Layout itself can be nested, and can be placed in any parent container.
  • Header: The top layout with the default style, in which any element can be nested, and must be placed in Layout.
  • Sider: The sidebar with default style and basic functions, in which any element can be nested, and must be placed in Layout.
  • Content: The content layout with the default style, in which any element can be nested, and must be placed in Layout.
  • Footer: The bottom layout with the default style, in which any element can be nested, and must be placed in Layout.

Based on flex layout, please pay attention to the compatibility.

Examples

  • Basic Structure · basic
  • Header-Content-Footer · top
  • Header-Sider · top-side
  • Header Sider 2 · top-side-2
  • Sider · side
  • Custom trigger · custom-trigger
  • Collapsible overlay · collapsible-overlay
  • Responsive · responsive
  • Fixed Header · fixed
  • Fixed Sider · fixed-sider

API

<Layout>
  <Header>header</Header>
  <Layout>
    <Sider>left sidebar</Sider>
    <Content>main content</Content>
    <Sider>right sidebar</Sider>
  </Layout>
  <Footer>footer</Footer>
</Layout>

Layout

Common props ref:Common props

The wrapper.

PropertyDescriptionTypeDefaultVersionGlobal Config
hasSiderWhether contain Sider in children, don't have to assign it normally. Useful in ssr avoid style flickeringboolean-×

Layout.Sider

The sidebar.

PropertyDescriptionTypeDefaultVersion
breakpointBreakpoints of the responsive layoutxs | sm | md | lg | xl | xxl | xxxl-xxxl: 6.3.0
classNamesCustomize class for each semantic structure inside the Sider component, supports object or functionRecord<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
collapsedTo set the current statusboolean-
collapsedWidthWidth of the collapsed sidebar, by setting to 0 a special trigger will appearnumber80
collapsibleWhether can be collapsedbooleanfalse
defaultCollapsedTo set the initial statusbooleanfalse
reverseArrowReverse direction of arrow, for a sider that expands from the rightbooleanfalse
stylesCustomize inline style for each semantic structure inside the Sider component, supports object or functionRecord<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-
themeColor theme of the sidebarlight | darkdark
triggerSpecify the customized trigger, set to null to hide the triggerReactNode-
widthWidth of the sidebarnumber | string200
zeroWidthTriggerStyleTo customize the styles of the special trigger that appears when collapsedWidth is 0object-
onBreakpointThe callback function, executed when breakpoints changed(broken) => {}-
onCollapseThe callback function, executed by clicking the trigger or activating the responsive layout(collapsed, type) => {}-

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element with Sider layout, theme, width and collapsed state styles—
bodyBody element that wraps Sider children layout and display styles—

Semantic description source: vendor/components/layout/demo/_semantic.tsx

breakpoint width

{
  xs: '480px',
  sm: '576px',
  md: '768px',
  lg: '992px',
  xl: '1200px',
  xxl: '1600px',
  xxxl: '1920px',
}

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
colorBgHeaderstringSee native declaration and inherited types
colorBgBodystringSee native declaration and inherited types
colorBgTriggerstringSee native declaration and inherited types
bodyBgstringBackground Color of body
headerBgstringBackground Color of header
headerHeightnumber | stringHeight of header
headerPaddingCSSProperties['padding']Padding of header
headerColorstringText color of header
footerPaddingCSSProperties['padding']Padding of footer
footerBgstringBackground Color of footer
siderBgstringBackground Color of sider
triggerHeightnumber | stringHeight of sider trigger
triggerBgstringBackground Color of sider trigger
triggerColorstringColor of sider trigger
zeroTriggerWidthnumberWidth of sider trigger when collapse is 0
zeroTriggerHeightnumberHeight of sider trigger when collapse is 0
lightSiderBgstringBackground Color of light theme sider
lightTriggerBgstringBackground Color of light theme sider trigger
lightTriggerColorstringColor of light theme sider trigger

Declaration source: vendor/components/layout/style/index.ts

import type { CSSProperties } from 'react';

import { unit } from '@ant-design/cssinjs';

import type { CSSObject } from '@ant-design/cssinjs';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks } from '../../theme/internal';

export interface ComponentToken {
  /** @deprecated Use headerBg instead */
  colorBgHeader: string;
  /** @deprecated Use bodyBg instead */
  colorBgBody: string;
  /** @deprecated Use triggerBg instead */
  colorBgTrigger: string;

  /**
   * @desc 主体部分背景色
   * @descEN Background Color of body
   */
  bodyBg: string;
  /**
   * @desc 顶部背景色
   * @descEN Background Color of header
   */
  headerBg: string;
  /**
   * @desc 顶部高度
   * @descEN Height of header
   */
  headerHeight: number | string;
  /**
   * @desc 顶部内边距
   * @descEN Padding of header
   */
  headerPadding: CSSProperties['padding'];
  /**
   * @desc 顶部文字颜色
   * @descEN Text color of header
   */
  headerColor: string;
  /**
   * @desc 页脚内边距
   * @descEN Padding of footer
   */
  footerPadding: CSSProperties['padding'];
  /**
   * @desc 页脚背景色
   * @descEN Background Color of footer
   */
  footerBg: string;
  /**
   * @desc 侧边栏背景色
   * @descEN Background Color of sider
   */
  siderBg: string;
  /**
   * @desc 侧边栏开关高度
   * @descEN Height of sider trigger
   */
  triggerHeight: number | string;
  /**
   * @desc 侧边栏开关背景色
   * @descEN Background Color of sider trigger
   */
  triggerBg: string;
  /**
   * @desc 侧边栏开关颜色
   * @descEN Color of sider trigger
   */
  triggerColor: string;
  /**
   * @desc collapse 为 0 时侧边栏开关宽度
   * @descEN Width of sider trigger when collapse is 0
   */
  zeroTriggerWidth: number;
  /**
   * @desc collapse 为 0 时侧边栏开关高度
   * @descEN Height of sider trigger when collapse is 0
   */
  zeroTriggerHeight: number;
  /**
   * @desc 亮色主题侧边栏背景色
   * @descEN Background Color of light theme sider
   */
  lightSiderBg: string;
  /**
   * @desc 亮色主题侧边栏开关背景色
   * @descEN Background Color of light theme sider trigger
   */
  lightTriggerBg: string;
  /**
   * @desc 亮色主题侧边栏开关颜色
   * @descEN Color of light theme sider trigger
   */
  lightTriggerColor: string;
}

export interface LayoutToken extends FullToken<'Layout'> {}

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/layout/Sider.tsx
  • vendor/components/layout/context.ts
  • vendor/components/layout/index.tsx
  • vendor/components/layout/layout.tsx
  • vendor/components/layout/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.