Skip to content
Related Articles

Related Articles

Improve Article

ReactJS Evergreen Avatar Component

  • Last Updated : 05 Jun, 2021

React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. Avatar components are used to represent users only. We can use the following approach in ReactJS to use the Evergreen Avatar Component.

Avatar Props:

  • className: It is used to pass the class name for this component.
  • src: It is used to pass the address of the image for an image element or avatar.
  • size: It is used to indicate the size of the avatar.
  • name: It is used to denote the name used for the initials and title attribute.
  • hashValue: It is used to denote the value used for the hash function.
  • color: It is used to denote the color used for the avatar.
  • getInitials: It is a function that is used to get the initials based on the name.
  • forceShowInitials: It is used to force show the initials when this is set to true.
  • sizeLimitOneCharacter: It is used to use a single initial for the avatar when the size is smaller than this number.
  • shape: It is used to denote the shape of the avatar component. It can be round or square.

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 evergreen-ui

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 { Avatar } from 'evergreen-ui'
  
export default function App() {
  return (
    <div style={{
      display: 'block', width: 700, paddingLeft: 30
    }}>
      <h4>ReactJS Evergreen Avatar Component</h4>
      <Avatar name="Ajay" size={50} />
      <Avatar name="Bunty" size={50} />
      <Avatar name="Chirag" size={50} />
      <Avatar name="Dinesh" size={50} />
    </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://evergreen.segment.com/components/avatar

My Personal Notes arrow_drop_up
Recommended Articles
Page :