Open In App

ReactJS UI Ant Design Typography Component

Improve
Improve
Like Article
Like
Save
Share
Report

Ant Design Library has this component pre-built, and it is very easy to integrate as well. Typography component is useful for basic text writing, body text, including headings, lists, and many more. We can use the following approach in ReactJS to use the Ant Design Typography Component.

Typography.Text Props:

  • code: It is used for the code style.
  • copyable: It is used to indicate whether to be copyable or not.
  • delete: It is used for the deleted line style.
  • disabled: It is used to disable the content.
  • editable: It is used to edit state when is object if this is set to editable.
  • ellipsis: It is used to display the ellipsis when text overflows.
  • keyboard: It is used for the keyboard style.
  • mark: It is used for the marked style.
  • onClick: It is used to set the handler to handle the click event.
  • strong: It is used for the bold style.
  • italic: It is used for the italic style.
  • type: It is used to denote the content type.
  • underline: It is used for the underlined style.

Typography.Title Props:

  • code: It is used for the code style.
  • copyable: It is used to indicate whether to be copyable or not.
  • delete: It is used for the deleted line style.
  • disabled: It is used to disable the content.
  • editable: It is used to edit state when is object if this is set to editable.
  • ellipsis: It is used to display the ellipsis when text overflows.
  • level: It is used to set content importance.
  • mark: It is used for the marked style.
  • onClick: It is used to set the handler to handle the click event.
  • italic: It is used for the italic style.
  • type: It is used to denote the content type.
  • underline: It is used for the underlined style.

Typography.Paragraph Props:

  • code: It is used for the code style.
  • copyable: It is used to indicate whether to be copyable or not.
  • delete: It is used for the deleted line style.
  • disabled: It is used to disable the content.
  • editable: It is used to edit state when is object if this is set to editable.
  • ellipsis: It is used to display the ellipsis when text overflows.
  • mark: It is used for the marked style.
  • onClick: It is used to set the handler to handle the click event.
  • strong: It is used for the bold style.
  • italic: It is used for the italic style.
  • type: It is used to denote the content type.
  • underline: It is used for the underlined style.

Copyable Props:

  • icon: It is used for the custom copy icon.
  • text: It is used to denote the text to copy.
  • tooltips: It is used for the custom tooltip text.
  • onCopy: It is a function which is called when copied text.

Editable Props:

  • autoSize: It is used to denote the autoSize attribute of textarea.
  • editing: It is used to indicate whether to be editable.
  • icon: It is used for the custom editable icon.
  • maxLength: It is used to denote the maxLength attribute of textarea number.
  • tooltip: It is used for the custom tooltip text.
  • onCancel: It is a callback function that is called when type ESC to exit the editable state.
  • onChange: It is a callback function that is called when input at textarea.
  • onEnd: It is a callback function that is called when type ENTER to exit editable state.
  • onStart: It is a callback function that is called when entering the editable state.
  • onCancel: It is a callback function that is called when type ESC to exit the editable state.
  • onEnd: It is a callback function that is called when type ENTER to exit the editable state.

Ellipsis Props:

  • expandable: It is used to indicate whether to be expandable.
  • rows: It is used to denote the max rows of content.
  • suffix: It is used to denote the suffix of ellipsis content.
  • symbol: It is used for the custom description of ellipsis.
  • tooltip: It is used to show a tooltip when ellipsis.
  • onEllipsis: It is a callback function that is called when enter or leave the ellipsis state.
  • onExpand: It is a callback function that is called when expanding the content.

Creating React Application And Installing Module:

  • Step 1: Create a React application using the following command:

    npx create-react-app foldername
  • Step 2: After creating your project folder i.e. foldername, move to it using the following command:

    cd foldername
  • Step 3: After creating the ReactJS application, Install the required module using the following command:

    npm install antd

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

App.js




import React from 'react'
import "antd/dist/antd.css";
import { Typography } from 'antd';
  
const { Title } = Typography;
  
export default function App() {
  
  return (
    <div style={{
      display: 'block', width: 700, padding: 30
    }}>
      <h4>ReactJS Ant-Design Typography Component</h4>
      <>
        <Title>h1 Size Heading</Title>
        <Title level={2}>h2 Size Heading</Title>
        <Title level={3}>h3 Size Heading</Title>
      </>
    </div>
  );
}


Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Reference: https://ant.design/components/typography/



Last Updated : 01 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads