Typography排版

文本的基本格式。

何时使用

  • 当需要展示标题、段落、列表内容时使用,如文章/博客/日志的文本样式。

  • 当需要一列基于文本的基础操作时,如拷贝/省略/可编辑。

代码演示

Typography排版 - 图1

基本

展示文档样例。

  1. import { Typography, Divider } from 'antd';
  2. const { Title, Paragraph, Text } = Typography;
  3. ReactDOM.render(
  4. <Typography>
  5. <Title>Introduction</Title>
  6. <Paragraph>
  7. In the process of internal desktop applications development, many different design specs and
  8. implementations would be involved, which might cause designers and developers difficulties and
  9. duplication and reduce the efficiency of development.
  10. </Paragraph>
  11. <Paragraph>
  12. After massive project practice and summaries, Ant Design, a design language for background
  13. applications, is refined by Ant UED Team, which aims to{' '}
  14. <Text strong>
  15. uniform the user interface specs for internal background projects, lower the unnecessary
  16. cost of design differences and implementation and liberate the resources of design and
  17. front-end development
  18. </Text>
  19. .
  20. </Paragraph>
  21. <Title level={2}>Guidelines and Resources</Title>
  22. <Paragraph>
  23. We supply a series of design principles, practical patterns and high quality design resources
  24. (<Text code>Sketch</Text> and <Text code>Axure</Text>), to help people create their product
  25. prototypes beautifully and efficiently.
  26. </Paragraph>
  27. <Paragraph>
  28. <ul>
  29. <li>
  30. <a href="/docs/spec/proximity">Principles</a>
  31. </li>
  32. <li>
  33. <a href="/docs/pattern/navigation">Patterns</a>
  34. </li>
  35. <li>
  36. <a href="/docs/resource/download">Resource Download</a>
  37. </li>
  38. </ul>
  39. </Paragraph>
  40. <Divider />
  41. <Title>介绍</Title>
  42. <Paragraph>
  43. 蚂蚁的企业级产品是一个庞大且复杂的体系。这类产品不仅量级巨大且功能复杂,而且变动和并发频繁,常常需要设计与开发能够快速的做出响应。同时这类产品中有存在很多类似的页面以及组件,可以通过抽象得到一些稳定且高复用性的内容。
  44. </Paragraph>
  45. <Paragraph>
  46. 随着商业化的趋势,越来越多的企业级产品对更好的用户体验有了进一步的要求。带着这样的一个终极目标,我们(蚂蚁金服体验技术部)经过大量的项目实践和总结,逐步打磨出一个服务于企业级产品的设计体系
  47. Ant Design。基于<Text mark>『确定』和『自然』</Text>
  48. 的设计价值观,通过模块化的解决方案,降低冗余的生产成本,让设计者专注于
  49. <Text strong>更好的用户体验</Text>。
  50. </Paragraph>
  51. <Title level={2}>设计资源</Title>
  52. <Paragraph>
  53. 我们提供完善的设计原则、最佳实践和设计资源文件(<Text code>Sketch</Text> 和{' '}
  54. <Text code>Axure</Text>),来帮助业务快速设计出高质量的产品原型。
  55. </Paragraph>
  56. <Paragraph>
  57. <ul>
  58. <li>
  59. <a href="/docs/spec/proximity">设计原则</a>
  60. </li>
  61. <li>
  62. <a href="/docs/pattern/navigation">设计模式</a>
  63. </li>
  64. <li>
  65. <a href="/docs/resource/download">设计资源</a>
  66. </li>
  67. </ul>
  68. </Paragraph>
  69. </Typography>,
  70. mountNode,
  71. );

Typography排版 - 图2

标题组件

展示不同级别的标题。

  1. import { Typography } from 'antd';
  2. const { Title } = Typography;
  3. ReactDOM.render(
  4. <div>
  5. <Title>h1. Ant Design</Title>
  6. <Title level={2}>h2. Ant Design</Title>
  7. <Title level={3}>h3. Ant Design</Title>
  8. <Title level={4}>h4. Ant Design</Title>
  9. </div>,
  10. mountNode,
  11. );

Typography排版 - 图3

文本组件

内置不同样式的文本。

  1. import { Typography } from 'antd';
  2. const { Text } = Typography;
  3. ReactDOM.render(
  4. <div>
  5. <Text>Ant Design</Text>
  6. <br />
  7. <Text type="secondary">Ant Design</Text>
  8. <br />
  9. <Text type="warning">Ant Design</Text>
  10. <br />
  11. <Text type="danger">Ant Design</Text>
  12. <br />
  13. <Text disabled>Ant Design</Text>
  14. <br />
  15. <Text mark>Ant Design</Text>
  16. <br />
  17. <Text code>Ant Design</Text>
  18. <br />
  19. <Text underline>Ant Design</Text>
  20. <br />
  21. <Text delete>Ant Design</Text>
  22. <br />
  23. <Text strong>Ant Design</Text>
  24. </div>,
  25. mountNode,
  26. );

Typography排版 - 图4

可交互

提供额外的交互能力。

  1. import { Typography } from 'antd';
  2. const { Paragraph } = Typography;
  3. class Demo extends React.Component {
  4. state = {
  5. str: 'This is an editable text.',
  6. };
  7. onChange = str => {
  8. console.log('Content change:', str);
  9. this.setState({ str });
  10. };
  11. render() {
  12. return (
  13. <div>
  14. <Paragraph editable={{ onChange: this.onChange }}>{this.state.str}</Paragraph>
  15. <Paragraph copyable>This is a copyable text.</Paragraph>
  16. <Paragraph copyable={{ text: 'Hello, Ant Design!' }}>Replace copy text.</Paragraph>
  17. </div>
  18. );
  19. }
  20. }
  21. ReactDOM.render(<Demo />, mountNode);

Typography排版 - 图5

省略号

多行文本省略。

  1. import { Typography } from 'antd';
  2. const { Paragraph } = Typography;
  3. ReactDOM.render(
  4. <div>
  5. <Paragraph ellipsis>
  6. Ant Design, a design language for background applications, is refined by Ant UED Team. Ant
  7. Design, a design language for background applications, is refined by Ant UED Team. Ant Design,
  8. a design language for background applications, is refined by Ant UED Team. Ant Design, a
  9. design language for background applications, is refined by Ant UED Team. Ant Design, a design
  10. language for background applications, is refined by Ant UED Team. Ant Design, a design
  11. language for background applications, is refined by Ant UED Team.
  12. </Paragraph>
  13. <Paragraph ellipsis={{ rows: 3, expandable: true }}>
  14. Ant Design, a design language for background applications, is refined by Ant UED Team. Ant
  15. Design, a design language for background applications, is refined by Ant UED Team. Ant Design,
  16. a design language for background applications, is refined by Ant UED Team. Ant Design, a
  17. design language for background applications, is refined by Ant UED Team. Ant Design, a design
  18. language for background applications, is refined by Ant UED Team. Ant Design, a design
  19. language for background applications, is refined by Ant UED Team.
  20. </Paragraph>
  21. </div>,
  22. mountNode,
  23. );

API

Typography.Text

参数说明类型默认值
copyable是否可拷贝,为对象时可设置复制文本以回调函数boolean | { text: string, onCopy: Function }false
delete添加删除线样式booleanfalse
disabled禁用文本booleanfalse
editable是否可编辑,为对象时可对编辑进行控制boolean | { editing: boolean, onStart: Function, onChange: Function(string) }false
ellipsis设置自动溢出省略booleanfalse
mark添加标记样式booleanfalse
underline添加下划线样式booleanfalse
strong是否加粗booleanfalse
type文本类型secondary, warning, danger-

Typography.Title

参数说明类型默认值
copyable是否可拷贝,为对象时可设置复制文本以回调函数boolean | { text: string, onCopy: Function }false
delete添加删除线样式booleanfalse
disabled禁用文本booleanfalse
editable是否可编辑,为对象时可对编辑进行控制boolean | { editing: boolean, onStart: Function, onChange: Function(string) }false
ellipsis自动溢出省略,为对象时可设置省略行数与是否可展开等boolean | { rows: number, expandable: boolean, onExpand: Function }false
level重要程度,相当于 h1h2h3h4number: 1, 2, 3, 41
mark添加标记样式booleanfalse
underline添加下划线样式booleanfalse
onChange当用户提交编辑内容时触发Function(string)-
type文本类型secondary, warning, danger-

Typography.Paragraph

参数说明类型默认值
copyable是否可拷贝,为对象时可设置复制文本以回调函数boolean | { text: string, onCopy: Function }false
delete添加删除线样式booleanfalse
disabled禁用文本booleanfalse
editable是否可编辑,为对象时可对编辑进行控制boolean | { editing: boolean, onStart: Function, onChange: Function(string) }false
ellipsis自动溢出省略,为对象时可设置省略行数与是否可展开等boolean | { rows: number, expandable: boolean, onExpand: Function }false
mark添加标记样式booleanfalse
underline添加下划线样式booleanfalse
onChange当用户提交编辑内容时触发Function(string)-
strong是否加粗booleanfalse
type文本类型secondary, warning, danger-