npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-leetcode

v1.0.3

Published

React utiliy components for leetcode. Users can use the components in their app/portfolio to showcase their leetcode profile.

Downloads

22

Readme

React-Leetcode

Collection of components for showcasing your leetcode profile in your portfolio ✨. Built with React, TailwindCss and Vite

Demo

Example Website

Features

  • 📈 Clean and simple LeetCode stats, as reusable components
  • 🎨 Customizable themes and styles
  • 🎉 Fully customizable using CSS
  • 🍀 Open source - MIT License
  • ⚙️ Extended-Components: activity, contest, heatmap and recent-submission

Installation

With npm:

npm install react-leetcode

With Yarn:

yarn add react-leetcode

Usage

Each Component has their own default properties. You can overwrite the defaults by passing props into the loaders.

Example

import { UserProfileDetails } from "react-leetcode";

function App() {
  return (
    <div className="w-full flex justify-center items-center">
      <UserProfileDetails userName="sudhanva_nadiger__" />
    </div>
  );
}

export default App;

Component Props

UserProfilDetails Props

| Name | Type | Default Value | Description | |------------------|---------------------------------|--------------------------------------------|-----------------------------------------------------------------------------------------| | userName | string | - | The username for which the profile details will be fetched and displayed. | | theme | { primaryColor?: string; secondaryColor?: string; bgColor?: string; } | { primaryColor: "rgba(34,211,238,1)", secondaryColor: "rgba(209,213,219,1)", bgColor: "rgba(68,64,60,1)" } | An object defining the colors for the profile details component. | | loadingComponent | ReactNode | - | A custom loading component to be displayed while fetching data. | | showRank | boolean | true | Indicates whether to display the user's rank. | | hideLocation | boolean | false | Indicates whether to hide the user's location information. | | hideSchool | boolean | false | Indicates whether to hide the user's school information. | | hideWebsite | boolean | false | Indicates whether to hide the user's website information. | | hideSkills | boolean | false | Indicates whether to hide the user's skills information. | | hideCompany | boolean | false | Indicates whether to hide the user's company information. | ref | React.Ref<HTMLDivElement> | - | The ref to attach to the component's root element. |

UserSolvedProblemsStats & UserHeatMap Props

| Name | Type | Default Value | Description | |-------------------|------------------------------------|----------------------------------|-----------------------------------------------------------------------------------------------------------------------| | userName | string | - | The username of the user. | | loadingComponent| React.ReactNode | - | Custom loading component to be displayed. | | theme | { primaryColor?: string; secondaryColor?: string; bgColor?: string; } | { primaryColor: "rgba(34,211,238,1)", secondaryColor: "rgba(209,213,219,1)", bgColor: "rgba(68,64,60,1)" } | An object containing custom theme colors.
| showUserName | boolean | true | Flag indicating whether to show the user's name. | | ref | React.Ref<HTMLDivElement> | - | The ref to attach to the component's root element. |

UserRecentSubmission & UserContestInfo Props

| Name | Type | Default Value | Description | |-----------------------|------------------------------------|----------------------------------|-----------------------------------------------------------------------------------------------------------------------| | userName | string | - | The username of the user. | | loadingComponent | JSX.Element | - | The loading component to display. | | theme | { primaryColor?: string; secondaryColor?: string; bgColor?: string; } | { primaryColor: "rgba(34,211,238,1)", secondaryColor: "rgba(209,213,219,1)", bgColor: "rgba(68,64,60,1)" } | The theme configuration object containing primaryColor, secondaryColor, and bgColor fields. | | ref | React.Ref<HTMLDivElement> | - | The ref to attach to the component's root element. |

  • If you dont provide loading component the default loader will appear
<div id="loading_container" className="flex flex-col">
    <div id="loading_dots_container" className="flex items-center justify-center gap-2 animate-pulse">
        <div className="w-1 h-1 bg-gray-600 rounded-full" />
        <div className="w-1 h-1 bg-gray-600 rounded-full" />
        <div className="w-1 h-1 bg-gray-600 rounded-full" />
    </div>
    <p id="loading_text" className="text-[10px] text-white font-bold text-center ml-[12px]">Loading...</p>
</div>

Note

If you simply use this component it will throw CORS error.

  • While developing setup the proxy.

  • Ex: Incase you are using vite for your react project add this to vite.config.ts:

import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
export default defineConfig({
  plugins: [react()],

  // Add this part to your config file
  server: {
    open: true,
    cors:  true,
    proxy: {
      '/leetcode': {
        target: 'https://leetcode.com/graphql',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/leetcode/, '')
      },
    }
  },
})
  • While deploying the website you should configure reverse proxy from the deployment platform.
  • Ex: If you are deploying your site in vercel add vercel.json file to the roor of your project folder with this content.
// vercel.json
{
    "rewrites": [
      {
        "source": "/leetcode",
        "destination": "https://leetcode.com/graphql"
      }
    ]
}

Development

  • clone the repo
git clone https://github.com/Sudhanva-Nadiger/react-leetcode.git
  • Install the packages
npm install
#or
yarn install
  • To run example website
cd example

npm run dev
#or
yarn dev

Testing

This package uses Vitest and React-Testing Library

  • Run the test
npm run test
#or
yarn test

Contributing

If you would like to contribute to this project, please follow these steps:

  • Fork the repo
  • Clone the repo git clone https://github.com/Sudhanva-Nadiger/react-leetcode.git
  • Create your feature branch (git checkout -b feature/YourFeature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin feature/YourFeature)
  • Create a new Pull Request

License

react-leetcode is released under the MIT license.

References

  1. React
  2. Vite
  3. Tailwindcss
  4. Vitest
  5. Leetcode-Stats-Card
  6. Leetcode-Query
  7. Create-library-fast-blog
  8. Testing-blog

Thank You