• PageHeader页头
    • 何时使用
    • 代码演示
    • API

    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(<PageHeader title="Title" breadcrumb={{ routes }} />, mountNode);

    PageHeader 页头 - 图3

    带内容的例子

    带内容的例子,可以优先展示页面的主要信息。

    1. import { PageHeader, Typography } from 'antd';
    2. const { Paragraph } = Typography;
    3. const routes = [
    4. {
    5. path: 'index',
    6. breadcrumbName: 'First-level Menu',
    7. },
    8. {
    9. path: 'first',
    10. breadcrumbName: 'Second-level Menu',
    11. },
    12. {
    13. path: 'second',
    14. breadcrumbName: 'Third-level Menu',
    15. },
    16. ];
    17. const content = (
    18. <div className="content">
    19. <Paragraph>
    20. Ant Design interprets the color system into two levels: a system-level color system and a
    21. product-level color system.
    22. </Paragraph>
    23. <Paragraph>
    24. Ant Design&#x27;s design team preferred to design with the HSB color model, which makes it
    25. easier for designers to have a clear psychological expectation of color when adjusting colors,
    26. as well as facilitate communication in teams.
    27. </Paragraph>
    28. <p className="contentLink">
    29. <a>
    30. <img
    31. src="https://gw.alipayobjects.com/zos/rmsportal/MjEImQtenlyueSmVEfUD.svg"
    32. alt="start"
    33. />
    34. Quick Start
    35. </a>
    36. <a>
    37. <img src="https://gw.alipayobjects.com/zos/rmsportal/NbuDUAuBlIApFuDvWiND.svg" alt="info" />
    38. Product Info
    39. </a>
    40. <a>
    41. <img src="https://gw.alipayobjects.com/zos/rmsportal/ohOEPSYdDTNnyMbGuyLb.svg" alt="doc" />
    42. Product Doc
    43. </a>
    44. </p>
    45. </div>
    46. );
    47. const extraContent = (
    48. <img
    49. src="https://gw.alipayobjects.com/mdn/mpaas_user/afts/img/A*KsfVQbuLRlYAAAAAAAAAAABjAQAAAQ/original"
    50. alt="content"
    51. />
    52. );
    53. ReactDOM.render(
    54. <PageHeader title="Title" breadcrumb={{ routes }}>
    55. <div className="wrap">
    56. <div className="content">{content}</div>
    57. <div className="extraContent">{extraContent}</div>
    58. </div>
    59. </PageHeader>,
    60. mountNode,
    61. );

    PageHeader 页头 - 图4

    复杂的例子

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

    1. import { PageHeader, Tag, Tabs, Button, Statistic, Row, Col } from 'antd';
    2. const TabPane = Tabs.TabPane;
    3. const Description = ({ term, children, span = 12 }) => (
    4. <Col span={span}>
    5. <div className="description">
    6. <div className="term">{term}</div>
    7. <div className="detail">{children}</div>
    8. </div>
    9. </Col>
    10. );
    11. const content = (
    12. <Row>
    13. <Description term="Created">Lili Qu</Description>
    14. <Description term="Association">
    15. <a>421421</a>
    16. </Description>
    17. <Description term="Creation Time">2017-01-10</Description>
    18. <Description term="Effective Time">2017-10-10</Description>
    19. <Description term="Remarks" span={24}>
    20. Gonghu Road, Xihu District, Hangzhou, Zhejiang, China
    21. </Description>
    22. </Row>
    23. );
    24. const extraContent = (
    25. <Row>
    26. <Col span={12}>
    27. <Statistic title="Status" value="Pending" />
    28. </Col>
    29. <Col span={12}>
    30. <Statistic title="Price" prefix="$" value={568.08} />
    31. </Col>
    32. </Row>
    33. );
    34. ReactDOM.render(
    35. <PageHeader
    36. onBack={() => window.history.back()}
    37. title="Title"
    38. subTitle="This is a subtitle"
    39. tags={<Tag color="red">Warning</Tag>}
    40. extra={[
    41. <Button key="3">Operation</Button>,
    42. <Button key="2">Operation</Button>,
    43. <Button key="1" type="primary">
    44. Primary
    45. </Button>,
    46. ]}
    47. footer={
    48. <Tabs defaultActiveKey="1">
    49. <TabPane tab="Details" key="1" />
    50. <TabPane tab="Rule" key="2" />
    51. </Tabs>
    52. }
    53. >
    54. <div className="wrap">
    55. <div className="content padding">{content}</div>
    56. <div className="extraContent">{extraContent}</div>
    57. </div>
    58. </PageHeader>,
    59. mountNode,
    60. );

    API

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