PageHeader页头

页头位于页容器中,页容器顶部,起到了内容概览和引导页级操作的作用。包括由面包屑、标题、页面内容简介、页面级操作等、页面级导航组成。

何时使用

当需要使用户快速理解当前页是什么以及方便用户使用页面功能时使用,通常也可被用作页面间导航。

代码演示

PageHeader页头 - 图1

标准样式

标准页头,适合使用在需要简单描述的场景。

  1. import { PageHeader } from 'antd';
  2. ReactDOM.render(
  3. <PageHeader onBack={() => null} title="Title" subTitle="This is a subtitle" />,
  4. mountNode,
  5. );

PageHeader页头 - 图2

带面包屑页头

带面包屑页头,适合层级比较深的页面,让用户可以快速导航。

  1. import { PageHeader } from 'antd';
  2. const routes = [
  3. {
  4. path: 'index',
  5. breadcrumbName: 'First-level Menu',
  6. },
  7. {
  8. path: 'first',
  9. breadcrumbName: 'Second-level Menu',
  10. },
  11. {
  12. path: 'second',
  13. breadcrumbName: 'Third-level Menu',
  14. },
  15. ];
  16. ReactDOM.render(
  17. <PageHeader title="Title" breadcrumb={{ routes }} subTitle="This is a subtitle" />,
  18. mountNode,
  19. );

PageHeader页头 - 图3

组合示例

使用了 pageHeader 提供的所有能力。

  1. import { PageHeader, Menu, Dropdown, Icon, Button, Tag, Typography, Row } from 'antd';
  2. const { Paragraph } = Typography;
  3. const menu = (
  4. <Menu>
  5. <Menu.Item>
  6. <a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
  7. 1st menu item
  8. </a>
  9. </Menu.Item>
  10. <Menu.Item>
  11. <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
  12. 2nd menu item
  13. </a>
  14. </Menu.Item>
  15. <Menu.Item>
  16. <a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">
  17. 3rd menu item
  18. </a>
  19. </Menu.Item>
  20. </Menu>
  21. );
  22. const DropdownMenu = () => {
  23. return (
  24. <Dropdown key="more" overlay={menu}>
  25. <Button
  26. style={{
  27. border: 'none',
  28. padding: 0,
  29. }}
  30. >
  31. <Icon
  32. type="ellipsis"
  33. style={{
  34. fontSize: 20,
  35. verticalAlign: 'top',
  36. }}
  37. />
  38. </Button>
  39. </Dropdown>
  40. );
  41. };
  42. const routes = [
  43. {
  44. path: 'index',
  45. breadcrumbName: 'First-level Menu',
  46. },
  47. {
  48. path: 'first',
  49. breadcrumbName: 'Second-level Menu',
  50. },
  51. {
  52. path: 'second',
  53. breadcrumbName: 'Third-level Menu',
  54. },
  55. ];
  56. const IconLink = ({ src, text }) => (
  57. <a
  58. style={{
  59. marginRight: 16,
  60. display: 'flex',
  61. alignItems: 'center',
  62. }}
  63. >
  64. <img
  65. style={{
  66. marginRight: 8,
  67. }}
  68. src={src}
  69. alt="start"
  70. />
  71. {text}
  72. </a>
  73. );
  74. const content = (
  75. <div className="content">
  76. <Paragraph>
  77. Ant Design interprets the color system into two levels: a system-level color system and a
  78. product-level color system.
  79. </Paragraph>
  80. <Paragraph>
  81. Ant Design&#x27;s design team preferred to design with the HSB color model, which makes it
  82. easier for designers to have a clear psychological expectation of color when adjusting colors,
  83. as well as facilitate communication in teams.
  84. </Paragraph>
  85. <Row className="contentLink" type="flex">
  86. <IconLink
  87. src="https://gw.alipayobjects.com/zos/rmsportal/MjEImQtenlyueSmVEfUD.svg"
  88. text="Quick Start"
  89. />
  90. <IconLink
  91. src="https://gw.alipayobjects.com/zos/rmsportal/NbuDUAuBlIApFuDvWiND.svg"
  92. text=" Product Info"
  93. />
  94. <IconLink
  95. src="https://gw.alipayobjects.com/zos/rmsportal/ohOEPSYdDTNnyMbGuyLb.svg"
  96. text="Product Doc"
  97. />
  98. </Row>
  99. </div>
  100. );
  101. const Content = ({ children, extraContent }) => {
  102. return (
  103. <Row className="content" type="flex">
  104. <div className="main" style={{ flex: 1 }}>
  105. {children}
  106. </div>
  107. <div
  108. className="extra"
  109. style={{
  110. marginLeft: 80,
  111. }}
  112. >
  113. {extraContent}
  114. </div>
  115. </Row>
  116. );
  117. };
  118. ReactDOM.render(
  119. <PageHeader
  120. title="Title"
  121. subTitle="This is a subtitle"
  122. tags={<Tag color="blue">Running</Tag>}
  123. extra={[
  124. <Button key="3">Operation</Button>,
  125. <Button key="2">Operation</Button>,
  126. <Button key="1" type="primary">
  127. Primary
  128. </Button>,
  129. <DropdownMenu key="more" />,
  130. ]}
  131. avatar={{ src: 'https://avatars1.githubusercontent.com/u/8186664?s=460&v=4' }}
  132. breadcrumb={{ routes }}
  133. >
  134. <Content
  135. extraContent={
  136. <img
  137. src="https://gw.alipayobjects.com/mdn/mpaas_user/afts/img/A*KsfVQbuLRlYAAAAAAAAAAABjAQAAAQ/original"
  138. alt="content"
  139. />
  140. }
  141. >
  142. {content}
  143. </Content>
  144. </PageHeader>,
  145. mountNode,
  146. );

PageHeader页头 - 图4

多种形态的 PageHeader

使用操作区,并自定义子节点,适合使用在需要展示一些复杂的信息,帮助用户快速了解这个页面的信息和操作。

  1. import { PageHeader, Tag, Button, Statistic, Descriptions, Row } from 'antd';
  2. ReactDOM.render(
  3. <div>
  4. <PageHeader
  5. onBack={() => window.history.back()}
  6. title="Title"
  7. subTitle="This is a subtitle"
  8. extra={[
  9. <Button key="3">Operation</Button>,
  10. <Button key="2">Operation</Button>,
  11. <Button key="1" type="primary">
  12. Primary
  13. </Button>,
  14. ]}
  15. >
  16. <Descriptions size="small" column={3}>
  17. <Descriptions.Item label="Created">Lili Qu</Descriptions.Item>
  18. <Descriptions.Item label="Association">
  19. <a>421421</a>
  20. </Descriptions.Item>
  21. <Descriptions.Item label="Creation Time">2017-01-10</Descriptions.Item>
  22. <Descriptions.Item label="Effective Time">2017-10-10</Descriptions.Item>
  23. <Descriptions.Item label="Remarks">
  24. Gonghu Road, Xihu District, Hangzhou, Zhejiang, China
  25. </Descriptions.Item>
  26. </Descriptions>
  27. </PageHeader>
  28. <br />
  29. <PageHeader
  30. onBack={() => window.history.back()}
  31. title="Title"
  32. tags={<Tag color="blue">Running</Tag>}
  33. subTitle="This is a subtitle"
  34. extra={[
  35. <Button key="3">Operation</Button>,
  36. <Button key="2">Operation</Button>,
  37. <Button key="1" type="primary">
  38. Primary
  39. </Button>,
  40. ]}
  41. >
  42. <Row type="flex">
  43. <Statistic title="Status" value="Pending" />
  44. <Statistic
  45. title="Price"
  46. prefix="$"
  47. value={568.08}
  48. style={{
  49. margin: '0 32px',
  50. }}
  51. />
  52. <Statistic title="Balance" prefix="$" value={3345.08} />
  53. </Row>
  54. </PageHeader>
  55. </div>,
  56. mountNode,
  57. );

PageHeader页头 - 图5

响应式

在不同大小的屏幕下,应该有不同的表现

  1. import { PageHeader, Tabs, Button, Statistic, Descriptions } from 'antd';
  2. const { TabPane } = Tabs;
  3. const renderContent = (column = 2) => (
  4. <Descriptions size="small" column={column}>
  5. <Descriptions.Item label="Created">Lili Qu</Descriptions.Item>
  6. <Descriptions.Item label="Association">
  7. <a>421421</a>
  8. </Descriptions.Item>
  9. <Descriptions.Item label="Creation Time">2017-01-10</Descriptions.Item>
  10. <Descriptions.Item label="Effective Time">2017-10-10</Descriptions.Item>
  11. <Descriptions.Item label="Remarks">
  12. Gonghu Road, Xihu District, Hangzhou, Zhejiang, China
  13. </Descriptions.Item>
  14. </Descriptions>
  15. );
  16. const extraContent = (
  17. <div
  18. style={{
  19. display: 'flex',
  20. width: 'max-content',
  21. justifyContent: 'flex-end',
  22. }}
  23. >
  24. <Statistic
  25. title="Status"
  26. value="Pending"
  27. style={{
  28. marginRight: 32,
  29. }}
  30. />
  31. <Statistic title="Price" prefix="$" value={568.08} />
  32. </div>
  33. );
  34. const Content = ({ children, extra }) => {
  35. return (
  36. <div className="content">
  37. <div className="main">{children}</div>
  38. <div className="extra">{extra}</div>
  39. </div>
  40. );
  41. };
  42. ReactDOM.render(
  43. <div>
  44. <PageHeader
  45. onBack={() => window.history.back()}
  46. title="Title"
  47. subTitle="This is a subtitle"
  48. extra={[
  49. <Button key="3">Operation</Button>,
  50. <Button key="2">Operation</Button>,
  51. <Button key="1" type="primary">
  52. Primary
  53. </Button>,
  54. ]}
  55. footer={
  56. <Tabs defaultActiveKey="1">
  57. <TabPane tab="Details" key="1" />
  58. <TabPane tab="Rule" key="2" />
  59. </Tabs>
  60. }
  61. >
  62. <Content extra={extraContent}>{renderContent()}</Content>
  63. </PageHeader>
  64. </div>,
  65. mountNode,
  66. );

API

参数说明类型默认值版本
title自定义标题文字ReactNode-3.14.0
subTitle自定义的二级标题文字ReactNode-3.14.0
avatar标题栏旁的头像avatar props-3.22.0
backIcon自定义 back icon ,如果为 false 不渲染 back iconReactNode<Icon type="arrow-left" />3.14.0
tagstitle 旁的 tag 列表Tag[] | Tag-3.14.0
extra操作区,位于 title 行的行尾ReactNode-3.14.0
breadcrumb面包屑的配置breadcrumb-3.14.0
footerPageHeader 的页脚,一般用于渲染 TabBarReactNode-3.14.0
onBack返回按钮的点击事件()=>void()=>history.back()3.14.0