PageHeader页头

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

何时使用

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

代码演示

PageHeader页头 - 图1

标准样式

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

  1. import { PageHeader } from 'antd';
  2. ReactDOM.render(
  3. <PageHeader
  4. className="site-page-header"
  5. onBack={() => null}
  6. title="Title"
  7. subTitle="This is a subtitle"
  8. />,
  9. mountNode,
  10. );
  1. .site-page-header {
  2. border: 1px solid rgb(235, 237, 240);
  3. }

PageHeader页头 - 图2

白底模式

默认 PageHeader 是透明底色的。在某些情况下,PageHeader 需要自己的背景颜色。

  1. import { PageHeader, Button, Descriptions } from 'antd';
  2. ReactDOM.render(
  3. <div className="site-page-header-ghost-wrapper">
  4. <PageHeader
  5. ghost={false}
  6. onBack={() => window.history.back()}
  7. title="Title"
  8. subTitle="This is a subtitle"
  9. extra={[
  10. <Button key="3">Operation</Button>,
  11. <Button key="2">Operation</Button>,
  12. <Button key="1" type="primary">
  13. Primary
  14. </Button>,
  15. ]}
  16. >
  17. <Descriptions size="small" column={3}>
  18. <Descriptions.Item label="Created">Lili Qu</Descriptions.Item>
  19. <Descriptions.Item label="Association">
  20. <a>421421</a>
  21. </Descriptions.Item>
  22. <Descriptions.Item label="Creation Time">2017-01-10</Descriptions.Item>
  23. <Descriptions.Item label="Effective Time">2017-10-10</Descriptions.Item>
  24. <Descriptions.Item label="Remarks">
  25. Gonghu Road, Xihu District, Hangzhou, Zhejiang, China
  26. </Descriptions.Item>
  27. </Descriptions>
  28. </PageHeader>
  29. </div>,
  30. mountNode,
  31. );
  1. .site-page-header-ghost-wrapper {
  2. background-color: #f5f5f5;
  3. padding: 24px;
  4. }

PageHeader页头 - 图3

带面包屑页头

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

  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
  18. className="site-page-header"
  19. title="Title"
  20. breadcrumb={{ routes }}
  21. subTitle="This is a subtitle"
  22. />,
  23. mountNode,
  24. );

PageHeader页头 - 图4

组合示例

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

  1. import { PageHeader, Menu, Dropdown, Button, Tag, Typography, Row } from 'antd';
  2. import { EllipsisOutlined } from '@ant-design/icons';
  3. const { Paragraph } = Typography;
  4. const menu = (
  5. <Menu>
  6. <Menu.Item>
  7. <a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
  8. 1st menu item
  9. </a>
  10. </Menu.Item>
  11. <Menu.Item>
  12. <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
  13. 2nd menu item
  14. </a>
  15. </Menu.Item>
  16. <Menu.Item>
  17. <a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">
  18. 3rd menu item
  19. </a>
  20. </Menu.Item>
  21. </Menu>
  22. );
  23. const DropdownMenu = () => {
  24. return (
  25. <Dropdown key="more" overlay={menu}>
  26. <Button
  27. style={{
  28. border: 'none',
  29. padding: 0,
  30. }}
  31. >
  32. <EllipsisOutlined
  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 className="example-link">
  58. <img className="example-link-icon" src={src} alt={text} />
  59. {text}
  60. </a>
  61. );
  62. const content = (
  63. <>
  64. <Paragraph>
  65. Ant Design interprets the color system into two levels: a system-level color system and a
  66. product-level color system.
  67. </Paragraph>
  68. <Paragraph>
  69. Ant Design&#x27;s design team preferred to design with the HSB color model, which makes it
  70. easier for designers to have a clear psychological expectation of color when adjusting colors,
  71. as well as facilitate communication in teams.
  72. </Paragraph>
  73. <div>
  74. <IconLink
  75. src="https://gw.alipayobjects.com/zos/rmsportal/MjEImQtenlyueSmVEfUD.svg"
  76. text="Quick Start"
  77. />
  78. <IconLink
  79. src="https://gw.alipayobjects.com/zos/rmsportal/NbuDUAuBlIApFuDvWiND.svg"
  80. text=" Product Info"
  81. />
  82. <IconLink
  83. src="https://gw.alipayobjects.com/zos/rmsportal/ohOEPSYdDTNnyMbGuyLb.svg"
  84. text="Product Doc"
  85. />
  86. </div>
  87. </>
  88. );
  89. const Content = ({ children, extraContent }) => {
  90. return (
  91. <Row>
  92. <div style={{ flex: 1 }}>{children}</div>
  93. <div className="image">{extraContent}</div>
  94. </Row>
  95. );
  96. };
  97. ReactDOM.render(
  98. <PageHeader
  99. title="Title"
  100. className="site-page-header"
  101. subTitle="This is a subtitle"
  102. tags={<Tag color="blue">Running</Tag>}
  103. extra={[
  104. <Button key="3">Operation</Button>,
  105. <Button key="2">Operation</Button>,
  106. <Button key="1" type="primary">
  107. Primary
  108. </Button>,
  109. <DropdownMenu key="more" />,
  110. ]}
  111. avatar={{ src: 'https://avatars1.githubusercontent.com/u/8186664?s=460&v=4' }}
  112. breadcrumb={{ routes }}
  113. >
  114. <Content
  115. extraContent={
  116. <img
  117. src="https://gw.alipayobjects.com/zos/antfincdn/K%24NnlsB%26hz/pageHeader.svg"
  118. alt="content"
  119. width="100%"
  120. />
  121. }
  122. >
  123. {content}
  124. </Content>
  125. </PageHeader>,
  126. mountNode,
  127. );
  1. #components-page-header-demo-content .image {
  2. margin: 0 0 0 60px;
  3. display: flex;
  4. align-items: center;
  5. }
  6. #components-page-header-demo-content .example-link {
  7. margin-right: 16px;
  8. }
  9. #components-page-header-demo-content .example-link-icon {
  10. margin-right: 8px;
  11. }
  12. #components-page-header-demo-content .ant-page-header-rtl .example-link {
  13. float: right;
  14. margin-right: 0;
  15. margin-left: 16px;
  16. }
  17. #components-page-header-demo-content .ant-page-header-rtl .example-link-icon {
  18. margin-right: 0;
  19. margin-left: 8px;
  20. }
  21. @media (max-width: 768px) {
  22. #components-page-header-demo-content .image {
  23. flex: 100%;
  24. margin: 24px 0 0;
  25. }
  26. }

PageHeader页头 - 图5

多种形态的 PageHeader

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

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

PageHeader页头 - 图6

响应式

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

  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. className="site-page-header-responsive"
  46. onBack={() => window.history.back()}
  47. title="Title"
  48. subTitle="This is a subtitle"
  49. extra={[
  50. <Button key="3">Operation</Button>,
  51. <Button key="2">Operation</Button>,
  52. <Button key="1" type="primary">
  53. Primary
  54. </Button>,
  55. ]}
  56. footer={
  57. <Tabs defaultActiveKey="1">
  58. <TabPane tab="Details" key="1" />
  59. <TabPane tab="Rule" key="2" />
  60. </Tabs>
  61. }
  62. >
  63. <Content extra={extraContent}>{renderContent()}</Content>
  64. </PageHeader>
  65. </div>,
  66. mountNode,
  67. );
  1. .site-page-header-responsive {
  2. border: 1px solid rgb(235, 237, 240);
  3. }

API

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