Open In App

ReactJS Blueprint Text Component

Improve
Improve
Like Article
Like
Save
Share
Report

BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex data-dense for desktop applications. Text Component provides a way for users to adds accessible overflow behavior to a line of text. We can use the following approach in ReactJS to use the ReactJS Blueprint Text Component.

Text Props:

  • className: It is used to denote a space-delimited list of class names to pass along to a child element.
  • ellipsize: It is used to indicate that this component should be truncated with an ellipsis if it overflows its container.
  • tagName: It is used to denote the HTML tag name to use for the rendered element.
  • title: It is used to denote the HTML title for the element.

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 @blueprintjs/core

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.

Javascript




import React from 'react'
import '@blueprintjs/core/lib/css/blueprint.css';
import { Text } from "@blueprintjs/core";
 
function App() {
 
    return (
        <div style={{
            display: 'block', width: 500, padding: 30
        }}>
            <h4>ReactJS Blueprint Text Component</h4>
            <div style={{width:200, height:100, backgroundColor: 'gray'}}>
                <Text ellipsize={true}>
                    Greetings from GeeksforGeeks!
                    Greetings from GeeksforGeeks!
                    Greetings from GeeksforGeeks!
                    Greetings from GeeksforGeeks!
                    Greetings from GeeksforGeeks!
                    Greetings from GeeksforGeeks!
                    Greetings from GeeksforGeeks!
                </Text>
            </div>
        </div>
    );
}
 
export default App;


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:

 

Example 2: In this example, we will use a TextArea and show how dynamically text will be truncated with an ellipsis if it overflows its container. Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

Javascript




import React,{useState} from 'react'
import '@blueprintjs/core/lib/css/blueprint.css';
import { Text, TextArea } from "@blueprintjs/core";
function App() {
const[textContent,setTextInput]=useState('');
const onInputChange = (event)=>setTextInput(event.target.value);
 
    return (
        <div >
    <h1 style={{color:'green'}}>GeeksforGeeks</h1>
            <h3>ReactJS Blueprint Text Component</h3>
      <div style={{width:200, height:100}}>
      <Text ellipsize={true}>
                    {textContent}
                      
                </Text>
      <TextArea fill={true} onChange={onInputChange} value={textContent} />
 
            </div>
        </div>
    );
}
 
export default App;


 

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

 

Reference: https://blueprintjs.com/docs/#core/components/text



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