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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-ui-chip-filter

v1.0.1

Published

A flexible React component for filtering content using interactive chips

Readme

React Filter Chips

A flexible and customizable React component for filtering content using interactive chips. Perfect for creating filter interfaces in e-commerce, dashboards, and data visualization applications.

Demo

Basic Usage

React Filter Chips Demo

Image Gallery Filtering

Image Filter Demo

Features

  • Flexible Filtering: Filter data by single or multiple criteria
  • Customizable Styling: Full control over appearance with CSS classes and inline styles
  • Search Functionality: Built-in search to find specific chips
  • Responsive Design: Works seamlessly on desktop and mobile devices
  • Accessibility: ARIA labels and keyboard navigation support
  • Dark Mode: Automatic dark mode support
  • Multi-select Support: Choose between single or multi-select filtering
  • TypeScript: Full TypeScript support with comprehensive type definitions
  • Well Tested: Comprehensive test coverage

Installation

npm install react-ui-chip-filter
yarn add react-ui-chip-filter

Framework Support

This package supports multiple React setups:

  • TypeScript (TSX) - Full TypeScript support with comprehensive type definitions
  • JavaScript (JSX) - Works with plain JavaScript and JSX
  • Create React App - Compatible with CRA projects
  • Next.js - Works with Next.js applications
  • Vite - Compatible with Vite-based projects
  • Webpack - Works with custom Webpack configurations
  • ES Modules - Supports both CommonJS and ES module imports

Import Methods

TypeScript/TSX

import { FilterChips, FilterChip } from 'react-ui-chip-filter';
import 'react-ui-chip-filter/styles';

JavaScript/JSX

import { FilterChips } from 'react-ui-chip-filter';
import 'react-ui-chip-filter/styles';

CommonJS (Node.js)

const { FilterChips } = require('react-ui-chip-filter');
require('react-ui-chip-filter/dist/index.css');

ES Modules (Browser)

import { FilterChips } from 'react-ui-chip-filter/dist/index.esm.js';
import 'react-ui-chip-filter/dist/index.css';

Basic Usage

import React, { useState } from 'react';
import { FilterChips, FilterChip } from 'react-ui-chip-filter';

const data = [
  { id: 1, name: 'John Doe', category: 'Developer', skills: ['React', 'TypeScript'] },
  { id: 2, name: 'Jane Smith', category: 'Designer', skills: ['Figma', 'Sketch'] },
  { id: 3, name: 'Bob Johnson', category: 'Developer', skills: ['Vue', 'JavaScript'] },
];

const chips: FilterChip[] = [
  { id: 'dev', label: 'Developers', value: 'Developer' },
  { id: 'design', label: 'Designers', value: 'Designer' },
  { id: 'react', label: 'React', value: 'React' },
];

function App() {
  const [filteredData, setFilteredData] = useState(data);

  const handleChipClick = (chip: FilterChip, filtered: any[]) => {
    setFilteredData(filtered);
  };

  return (
    <div>
      <FilterChips
        chips={chips}
        onChipClick={handleChipClick}
        data={data}
        filterKey="category"
        multiSelect={true}
      />
      
      <div>
        {filteredData.map(item => (
          <div key={item.id}>{item.name}</div>
        ))}
      </div>
    </div>
  );
}

Props

FilterChipsProps

| Prop | Type | Default | Description | |------|------|---------|-------------| | chips | FilterChip[] | Required | Array of chip objects to display | | onChipClick | (chip: FilterChip, filteredData: any[]) => void | Required | Callback fired when a chip is clicked | | data | any[] | Required | Array of data to filter | | filterKey | string \| string[] | Required | Key(s) to filter by in the data objects | | multiSelect | boolean | false | Allow multiple chips to be selected | | className | string | '' | CSS class for the container | | chipClassName | string | '' | CSS class for individual chips | | activeChipClassName | string | '' | CSS class for active chips | | disabledChipClassName | string | '' | CSS class for disabled chips | | style | React.CSSProperties | undefined | Inline styles for the container | | chipStyle | React.CSSProperties | undefined | Inline styles for individual chips | | showClearAll | boolean | true | Show clear all button | | clearAllText | string | 'Clear All' | Text for clear all button | | clearAllClassName | string | '' | CSS class for clear all button | | maxChips | number | undefined | Maximum number of chips to show initially | | showMoreText | string | 'Show More' | Text for show more button | | showLessText | string | 'Show Less' | Text for show less button | | searchable | boolean | false | Enable search functionality | | searchPlaceholder | string | 'Search chips...' | Placeholder for search input | | searchClassName | string | '' | CSS class for search input | | noResultsText | string | 'No chips found' | Text when no chips match search | | loading | boolean | false | Show loading state | | loadingText | string | 'Loading...' | Text for loading state |

FilterChip

| Property | Type | Default | Description | |----------|------|---------|-------------| | id | string | Required | Unique identifier for the chip | | label | string | Required | Display text for the chip | | value | any | Required | Value to filter by | | active | boolean | false | Whether the chip is initially active | | disabled | boolean | false | Whether the chip is disabled | | color | string | undefined | Text color for the chip | | backgroundColor | string | undefined | Background color for the chip | | borderColor | string | undefined | Border color for the chip |

Advanced Examples

E-commerce Product Filtering

const products = [
  { 
    id: 1, 
    name: 'Wireless Headphones', 
    category: 'Electronics', 
    brand: 'TechSound',
    price: 99.99,
    tags: ['wireless', 'bluetooth']
  },
  // ... more products
];

const categoryChips: FilterChip[] = [
  { id: 'electronics', label: 'Electronics', value: 'Electronics' },
  { id: 'accessories', label: 'Accessories', value: 'Accessories' },
];

const brandChips: FilterChip[] = [
  { id: 'techsound', label: 'TechSound', value: 'TechSound' },
  { id: 'gamepro', label: 'GamePro', value: 'GamePro' },
];

function ProductFilters() {
  const [filteredProducts, setFilteredProducts] = useState(products);

  return (
    <div>
      <h3>Filter by Category</h3>
      <FilterChips
        chips={categoryChips}
        onChipClick={(chip, filtered) => setFilteredProducts(filtered)}
        data={products}
        filterKey="category"
        multiSelect={true}
      />
      
      <h3>Filter by Brand</h3>
      <FilterChips
        chips={brandChips}
        onChipClick={(chip, filtered) => setFilteredProducts(filtered)}
        data={products}
        filterKey="brand"
        multiSelect={true}
        maxChips={3}
        searchable={true}
      />
    </div>
  );
}

Custom Styling

const customChips: FilterChip[] = [
  { 
    id: 'high', 
    label: 'High Priority', 
    value: 'high',
    backgroundColor: '#ff6b6b',
    color: '#ffffff'
  },
  { 
    id: 'medium', 
    label: 'Medium Priority', 
    value: 'medium',
    backgroundColor: '#ffa726',
    color: '#ffffff'
  },
];

<FilterChips
  chips={customChips}
  onChipClick={handleChipClick}
  data={data}
  filterKey="priority"
  className="custom-priority-chips"
  chipClassName="custom-chip"
  activeChipClassName="custom-active"
/>

Array Field Filtering

const data = [
  { id: 1, name: 'John', skills: ['React', 'TypeScript', 'Node.js'] },
  { id: 2, name: 'Jane', skills: ['Vue', 'JavaScript'] },
  { id: 3, name: 'Bob', skills: ['React', 'Python'] },
];

const skillChips: FilterChip[] = [
  { id: 'react', label: 'React', value: 'React' },
  { id: 'vue', label: 'Vue', value: 'Vue' },
  { id: 'typescript', label: 'TypeScript', value: 'TypeScript' },
];

<FilterChips
  chips={skillChips}
  onChipClick={handleChipClick}
  data={data}
  filterKey="skills" // This will filter arrays
  multiSelect={true}
/>

Multiple Filter Keys

<FilterChips
  chips={chips}
  onChipClick={handleChipClick}
  data={data}
  filterKey={['category', 'department']} // Filter by multiple keys
  multiSelect={true}
/>

CSS Customization

The component comes with default styles, but you can easily customize them:

/* Custom container styles */
.custom-filter-container {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 8px;
}

/* Custom chip styles */
.custom-chip {
  border-radius: 25px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Custom active chip styles */
.custom-active-chip {
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

/* Custom search input styles */
.custom-search-input {
  border: 2px solid #007bff;
  border-radius: 8px;
}

Accessibility

The component includes built-in accessibility features:

  • ARIA labels for screen readers
  • Keyboard navigation support
  • Focus management
  • High contrast mode support
  • Reduced motion support

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see the LICENSE file for details.

Repository

Changelog

Framework-Specific Examples

Create React App (JSX)

// App.js
import React, { useState } from 'react';
import { FilterChips } from 'react-ui-chip-filter';
import 'react-ui-chip-filter/styles';

function App() {
  const [data, setData] = useState([
    { id: 1, name: 'Product 1', category: 'Electronics' },
    { id: 2, name: 'Product 2', category: 'Clothing' },
  ]);

  const chips = [
    { id: 'electronics', label: 'Electronics', value: 'Electronics' },
    { id: 'clothing', label: 'Clothing', value: 'Clothing' },
  ];

  return (
    <FilterChips
      chips={chips}
      onChipClick={(chip, filtered) => setData(filtered)}
      data={data}
      filterKey="category"
    />
  );
}

Next.js (TSX)

// pages/index.tsx
import { useState } from 'react';
import { FilterChips, FilterChip } from 'react-ui-chip-filter';
import 'react-ui-chip-filter/styles';

export default function HomePage() {
  const [data, setData] = useState([
    { id: 1, name: 'Product 1', category: 'Electronics' },
  ]);

  const chips: FilterChip[] = [
    { id: 'electronics', label: 'Electronics', value: 'Electronics' },
  ];

  return (
    <FilterChips
      chips={chips}
      onChipClick={(chip, filtered) => setData(filtered)}
      data={data}
      filterKey="category"
    />
  );
}

Vite (TSX)

// src/App.tsx
import { useState } from 'react';
import { FilterChips, FilterChip } from 'react-ui-chip-filter';
import 'react-ui-chip-filter/styles';

function App() {
  const [data, setData] = useState([
    { id: 1, name: 'Product 1', category: 'Electronics' },
  ]);

  const chips: FilterChip[] = [
    { id: 'electronics', label: 'Electronics', value: 'Electronics' },
  ];

  return (
    <FilterChips
      chips={chips}
      onChipClick={(chip, filtered) => setData(filtered)}
      data={data}
      filterKey="category"
    />
  );
}

Changelog

1.0.0

  • Initial release
  • Basic filtering functionality
  • Custom styling support
  • Search functionality
  • Multi-select support
  • TypeScript definitions
  • Comprehensive test coverage
  • Support for both JSX and TSX applications
  • Multiple import methods (ES modules, CommonJS)
  • Framework compatibility (CRA, Next.js, Vite, Webpack)