Card卡片

    最基础的卡片容器,可承载文字、列表、图片、段落,常用于后台概览页面。

    典型卡片

    包含标题、内容、操作区域。

    Card 卡片 - 图2

    在灰色背景上使用无边框的卡片。

    1. ReactDOM.render(
    2. <div style={{ background: '#ECECEC', padding: '30px' }}>
    3. <Card title="Card title" bordered={false} style={{ width: 300 }}>
    4. <p>Card content</p>
    5. <p>Card content</p>
    6. <p>Card content</p>
    7. </Card>
    8. </div>,
    9. mountNode,
    10. );

    简洁卡片

    1. import { Card } from 'antd';
    2. ReactDOM.render(
    3. <Card style={{ width: 300 }}>
    4. <p>Card content</p>
    5. <p>Card content</p>
    6. <p>Card content</p>
    7. </Card>,
    8. mountNode,
    9. );

    Card 卡片 - 图4

    可以利用 Card.Meta 支持更灵活的内容。

    栅格卡片

    在系统概览页面常常和栅格进行配合。

    1. import { Card, Col, Row } from 'antd';
    2. ReactDOM.render(
    3. <div style={{ background: '#ECECEC', padding: '30px' }}>
    4. <Row gutter={16}>
    5. <Col span={8}>
    6. <Card title="Card title" bordered={false}>
    7. Card content
    8. </Card>
    9. </Col>
    10. <Col span={8}>
    11. <Card title="Card title" bordered={false}>
    12. Card content
    13. </Card>
    14. </Col>
    15. <Col span={8}>
    16. <Card title="Card title" bordered={false}>
    17. Card content
    18. </Card>
    19. </Col>
    20. </Row>
    21. </div>,
    22. mountNode,
    23. );

    Card 卡片 - 图6

    数据读入前会有文本块样式。

    1. import { Skeleton, Switch, Card, Icon, Avatar } from 'antd';
    2. const { Meta } = Card;
    3. class App extends React.Component {
    4. state = {
    5. loading: true,
    6. };
    7. onChange = checked => {
    8. this.setState({ loading: !checked });
    9. };
    10. render() {
    11. const { loading } = this.state;
    12. return (
    13. <div>
    14. <Card style={{ width: 300, marginTop: 16 }} loading={loading}>
    15. <Meta
    16. avatar={
    17. <Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />
    18. title="Card title"
    19. description="This is the description"
    20. />
    21. </Card>
    22. <Card
    23. style={{ width: 300, marginTop: 16 }}
    24. actions={[<Icon type="setting" />, <Icon type="edit" />, <Icon type="ellipsis" />]}
    25. >
    26. <Skeleton loading={loading} avatar active>
    27. <Meta
    28. avatar={
    29. <Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />
    30. }
    31. title="Card title"
    32. description="This is the description"
    33. />
    34. </Skeleton>
    35. </Card>
    36. </div>
    37. );
    38. }
    39. }
    40. ReactDOM.render(<App />, mountNode);

    网格型内嵌卡片

    一种常见的卡片内容区隔模式。

    可以放在普通卡片内部,展示多层级结构的信息。

    1. import { Card } from 'antd';
    2. ReactDOM.render(
    3. <Card title="Card title">
    4. <p
    5. style={{
    6. fontSize: 14,
    7. color: 'rgba(0, 0, 0, 0.85)',
    8. marginBottom: 16,
    9. fontWeight: 500,
    10. }}
    11. >
    12. Group title
    13. </p>
    14. <Card type="inner" title="Inner Card title" extra={<a href="#">More</a>}>
    15. Inner Card content
    16. </Card>
    17. <Card
    18. style={{ marginTop: 16 }}
    19. type="inner"
    20. title="Inner Card title"
    21. extra={<a href="#">More</a>}
    22. >
    23. Inner Card content
    24. </Card>
    25. </Card>,
    26. mountNode,
    27. );

    Card 卡片 - 图9

    带页签的卡片

    可承载更多内容。

    1. import { Card } from 'antd';
    2. const tabList = [
    3. {
    4. key: 'tab1',
    5. tab: 'tab1',
    6. },
    7. {
    8. key: 'tab2',
    9. tab: 'tab2',
    10. },
    11. const contentList = {
    12. tab1: <p>content1</p>,
    13. tab2: <p>content2</p>,
    14. };
    15. const tabListNoTitle = [
    16. {
    17. key: 'article',
    18. tab: 'article',
    19. },
    20. {
    21. key: 'app',
    22. tab: 'app',
    23. },
    24. {
    25. key: 'project',
    26. tab: 'project',
    27. },
    28. ];
    29. const contentListNoTitle = {
    30. article: <p>article content</p>,
    31. app: <p>app content</p>,
    32. project: <p>project content</p>,
    33. };
    34. class TabsCard extends React.Component {
    35. state = {
    36. key: 'tab1',
    37. noTitleKey: 'app',
    38. };
    39. onTabChange = (key, type) => {
    40. console.log(key, type);
    41. this.setState({ [type]: key });
    42. };
    43. render() {
    44. return (
    45. <div>
    46. <Card
    47. style={{ width: '100%' }}
    48. title="Card title"
    49. extra={<a href="#">More</a>}
    50. tabList={tabList}
    51. activeTabKey={this.state.key}
    52. onTabChange={key => {
    53. this.onTabChange(key, 'key');
    54. }}
    55. >
    56. {contentList[this.state.key]}
    57. </Card>
    58. <br />
    59. <br />
    60. <Card
    61. style={{ width: '100%' }}
    62. tabList={tabListNoTitle}
    63. activeTabKey={this.state.noTitleKey}
    64. onTabChange={key => {
    65. this.onTabChange(key, 'noTitleKey');
    66. }}
    67. >
    68. {contentListNoTitle[this.state.noTitleKey]}
    69. </Card>
    70. </div>
    71. );
    72. }
    73. }

    一种支持封面、头像、标题和描述信息的卡片。

    1. <Card title="卡片标题">卡片内容</Card>