# Leaderboard Component

## **Component Visuals**

<figure><img src="https://1173113760-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYEKIeE9xnHLXuuwEs8zo%2Fuploads%2F56wCDHiSqAE5yEC7fLRp%2FGamification%20-%20Leaderboard%20Screen%20temp1.png?alt=media&#x26;token=e6dd4ce3-3517-4fd7-9cf4-5d7dbfa86caa" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="info" %}
To unlock early access to the component                                                           [**Get Access**](https://bijfwfnqtsj.typeform.com/to/eUXDpbuh)
{% endhint %}

## Installation

To install the `Quest react-sdk` into your project, follow these steps:

* Open your terminal/command prompt.
* Navigate to your project's root directory using the `cd` command if you're not already there.
* Run the following command to install the `quest-sdk` package using npm:

```jsx
npm install @questlabs/react-sdk
```

> This command will download and install the package and its dependencies into your project.

{% hint style="info" %}
Make sure your project has npm and Node.js installed, and that you have the necessary permissions to install packages in your project directory.
{% endhint %}

***

The `LeaderBoard`component accepts the following props

## Usage

To integrate the `LeaderBoard` component into your React application, follow these steps

* **Import the CSS**: In your JavaScript or TypeScript file where you're using the `LeaderBoard`, import the CSS styles for the component. This ensures that the component's styling is applied correctly.

```jsx
import '@questlabs/react-sdk/dist/style.css'
```

* **Import the TutorialComponent**: Import the `LeaderBoard`component from the `@questlabs/react-sdk` package.
* **Import the QuestProvider Component**: Import the `QuestProvider` component from the `@questlabs/react-sdk` package.

```jsx
import { QuestProvider, LeaderBoard } from '@questlabs/react-sdk';
```

* **Pass the Required Props**:  Pass the required props to the `QuestProvider`. The required props are `apiKey`,  and `entityId`. and required props for the `LeaderBoard` component are `userId, questId, token`

{% hint style="info" %}
Replace `"your-api-key"` and `"your-entity-id"` with your actual Quest API credentials&#x20;
{% endhint %}

{% hint style="info" %}
Replace `"your-token"`, `"your-user-id", "your-questId"` with your actual configuration details.
{% endhint %}

## Code & Steps

{% tabs %}
{% tab title="QuestProvider" %}

```jsx
import { QuestProvider, LeaderBoard } from '@questlabs/react-sdk';
import '@questlabs/react-sdk/dist/style.css'

function App() {
  return (
      <QuestProvider
        apiKey="your-apikey"
        entityId="your-entity-Id" 
        apiType= "PRODUCTION" // STAGING 
      >
        <LeaderBoard> </LeaderBoard>
      </QuestProvider>
  );
}

export default App;


```

{% endtab %}

{% tab title="LeaderBoard " %}

```jsx
<LeaderBoard 
    userId=""
    questId=""
    token=""
    uniqueUserId="your-unique-user-id"
>
    // children
</LeaderBoard >
```

{% endtab %}

{% tab title="Header" %}

```jsx
<LeaderBoard.Header
    heading='your-heading' 
    style= {{ backgroundcolor : 'white' }} 
/>
```

{% endtab %}

{% tab title="Footer" %}

```jsx
<LeaderBoard.Footer
    text='your-company-name' 
    link='redirect-link'
    style={{ background : 'white' }}
/>
```

{% endtab %}

{% tab title="Preview" %}

```jsx
<QuestProvider
    apiKey="your-apikey"
    entityId="your-entity-Id"
    apiType="PRODUCTION" // STAGING 
>
    <LeaderBoard
        userId=""
        questId=""
        token=""
        uniqueUserId="your-unique-user-id"
    >
        <LeaderBoard.Header />
        <LeaderBoard.Content />
        <LeaderBoard.Footer />
    </LeaderBoard >
</QuestProvider>
```

{% endtab %}
{% endtabs %}

***

## **Example Usage**

Here's an example of how to use the `LeaderBoard`component within your React application

{% tabs %}
{% tab title="LeaderBoard " %}

```jsx
import { QuestProvider, LeaderBoard } from '@questlabs/react-sdk';
import '@questlabs/react-sdk/dist/style.css'

function App() {
  return (
    <div>
      <QuestProvider
        apiKey="your-apikey"
        entityId="your-entity-Id" 
        apiType= "PRODUCTION" // STAGING 
      >
       <LeaderBoard 
          userId=""
          questId=""
          token=""
          uniqueUserId="your-unique-user-id"
        >
          <LeaderBoard.Header />
          <LeaderBoard.Content />
          <LeaderBoard.Footer />
        </LeaderBoard>
      </QuestProvider>
    </div>
  );
}

export default App;
```

{% endtab %}

{% tab title="LeaderBoard Wrapper" %}

```jsx
import { QuestProvider, TutorialWrapper } from '@questlabs/react-sdk';
import '@questlabs/react-sdk/dist/style.css'

function App() {
    return (
        <div>
            <QuestProvider
                apiKey="your-apikey"
                entityId="your-entity-Id"
                apiType="PRODUCTION" // STAGING 
            >
                <LeaderboardWrapper
                    userLimit={50}
                    isXpImage={true}
                    userId={userId}
                    token={token}
                    setPresentUserData={setPresentData}
                    presentUserRank={presentRank}
                    setPresentUserRank={setPresentRank}
                    DefaultImage=""
                    DefaultName=""
                    FirstRankIconImage=""
                    IsTopRank={true}
                    SecondRankIconImage=""
                    ThirdRankIconImage=""
                    rewardHead=""
                    uniqueEmailId=""
                    uniqueUserId=""
                    userImageUrl=""
                    userName=""
                    styleConfig={{
                        PresentUser: {},
                        Description: {},
                        Footer: {
                            FooterIcon: {},
                            FooterLink: "",
                            FooterStyle: {},
                            FooterText: "",
                            FooterTextStyle: {}
                        },
                        Form: {},
                        Heading: {},
                        IconStyle: {
                            color: ""
                        },
                        IndexBackground: {},
                        IndexColor: {},
                        InnerBackground: {},
                        MainHeading: {},
                        PointsBackground: {},
                        PointsColor: {},
                        ProgressBarColor: {}
                    }}
                    isLoader={true}

                />
            </QuestProvider>
        </div>
    );
}

export default App;
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The above example uses all the props.
{% endhint %}

## Props of Leaderboard Component

The **`Leaderboard`**  component accepts the following props:

<table><thead><tr><th width="232">Prop Name</th><th width="108">Type</th><th width="111">Required</th><th>Details</th></tr></thead><tbody><tr><td>token</td><td>string</td><td>required</td><td>An authentication token or API key necessary for accessing Leaderboard or quest data.</td></tr><tr><td>userId</td><td>string</td><td>required</td><td>The unique identifier of the user.</td></tr><tr><td>styleConfig</td><td>object</td><td>optional</td><td>An object containing CSS properties for styling various components within the Leaderboard process, including  main heading, heading, descriptions, points color,,points background,inner background, index color, index background ,  progressbar color, and icon style .</td></tr><tr><td>userLimit</td><td>number</td><td>optional</td><td>Limits the user</td></tr><tr><td>isXpImage</td><td>boolean</td><td>optional</td><td>Hide or show Xp image</td></tr><tr><td>DefaultImage</td><td>string</td><td>optional</td><td>To set default image</td></tr><tr><td>DefaultName</td><td>string</td><td>optional</td><td>To set default Nmae</td></tr><tr><td>FirstRankIconImage</td><td>string</td><td>optional</td><td>To set the image of first ranker</td></tr><tr><td>SecondRankIconImage</td><td>string</td><td>optional</td><td>To set the image of second ranker</td></tr><tr><td>ThirdRankIconImage</td><td>string</td><td>optional</td><td>To set the image of third ranker</td></tr><tr><td>IsTopRank</td><td>boolean</td><td>optional</td><td>To tell top rank or not</td></tr></tbody></table>

```css
styleConfig = {{
    PresentUser: { },
    Description: { },
    Footer: {
        FooterIcon: { },
        FooterLink: "",
            FooterStyle: { },
        FooterText: "",
            FooterTextStyle: { }
    },
    Form: { },
    Heading: { },
    IconStyle: {
        color: ""
    },
    IndexBackground: { },
    IndexColor: { },
    InnerBackground: { },
    MainHeading: { },
    PointsBackground: { },
    PointsColor: { },
    ProgressBarColor: { }
}}
```

## Features

* **Customizable Styling:** Users can customize the appearance of the leaderboard to align with their platform's branding or design preferences. This includes options to adjust colors, fonts, and layout, providing a seamless integration into the overall user interface.
* Versatile Leaderboard Component: Integrate a comprehensive leaderboard feature into your app, enabling dynamic tracking and visualization of user standings based on accumulated points or experience. Tailor the leaderboard to suit diverse engagement scenarios and foster competition and community interaction within your platform.

You can customize the UI with type of styleConfig would be
