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-pill

v2.3.1

Published

**React Pill** is a customizable pill-style component that you can use to create tab-like elements in your React application. It is simple, lightweight, and easy to integrate, providing a clean and modern look for navigation or item selection.

Downloads

418

Readme

React Pill

React Pill is a customizable pill-style component that you can use to create tab-like elements in your React application. It is simple, lightweight, and easy to integrate, providing a clean and modern look for navigation or item selection.

✨ Features

  • Customizable pills with support for labels, icons, and close buttons.
  • Rounded or default rectangular styles.
  • Easy-to-use API for on-click and close actions.
  • Type safe

Demo

Demo

🚀 Getting Started

Installation

You can install react-pill via NPM:

npm install react-pill

Or with Yarn:

yarn add react-pill

🛠️ Usage

Here's how you can use the Pill component in your React project:

import React from "react";
import Pill from "react-pill";

const App = () => {
  const data = [
    { label: "Tab 1", bgcolor: "#ffcccb" },
    { label: "Tab 2", bgcolor: "#b0e57c" },
    { label: "Tab 3", bgcolor: "#87ceeb", icon: "📌" },
  ];

  const handleSelect = (event, index) => {
    console.log(`Selected Pill: ${index}`);
  };

  const handleClose = (index) => {
    console.log(`Closed Pill: ${index}`);
  };

  return (
    <div>
      <Pill
        data={data}
        onSelect={handleSelect}
        onClose={handleClose}
        rounded={true}
        containerClassName="pill-container"
        pillClassName="custom-pill"
      />
    </div>
  );
};

export default App;

Props

| Prop | Type | Description | | --------------------- | ----------- | --------------------------------------------------------------- | | data | array | Array of pill data objects, each with properties label, bgcolor, and icon. | | onClose | function | Function called when the close button is clicked. Receives the index of the pill. | | onSelect | function | Function called when a pill is selected. Receives the event and the index of the pill. | | rounded | boolean | If true, pills will have rounded corners. | | pillClassName | string | Custom class for individual pills. | | containerClassName | string | Custom class for the pill container. |

Example

In the example above:

  • The data prop provides the labels, colors, and optional icons for each pill.
  • onSelect and onClose props handle user interactions.
  • You can customize the style by providing custom CSS classes.

🖌️ Styling

You can style the pills using your own CSS. Here are the default classes you can override:

  • .defaultPill: The base pill styling.
  • .rounded: Adds rounded corners.
  • .closeButton: Styles the close button.
  • .iconContainer: Wraps the icon inside the pill.

You can create your own Pill.css to modify the appearance as desired:

.defaultPill {
  padding: 10px;
  border: none;
  cursor: pointer;
}

.rounded {
  border-radius: 20px;
}

.closeButton {
  background: none;
  border: none;
  cursor: pointer;
  margin-left: 10px;
}

🔧 Build & Development

To build the package, run:

npm run build

To run the tests:

npm test

🤝 Contributing

Contributions are welcome! If you have ideas or suggestions, feel free to open an issue or create a pull request.

📄 License

MIT License. Feel free to use, modify, and share it!