New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-filter-chips

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-filter-chips

React Filter Chips is a versatile React component for creating filter chips based on various data types like strings, numbers, dates, arrays, and booleans. It provides customizable chip styles, close icon options, and supports dynamic filtering and cleari

  • 1.0.6
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

ReactFilterChips

Overview

The ReactFilterChips component provides an interactive way to display and manage filter chips in your React application. It allows users to see the applied filters and remove them individually or clear all filters at once. This component is highly customizable and supports various data types including strings, numbers, arrays, objects, booleans, and dates.

Live Demo

To test React Filter Chips on CodeSandbox, click here.

Installation

To install the ReactFilterChips component, you can use npm:

npm install react-filter-chips

Or using yarn

yarn add react-filter-chips

Simple Usage

import React, { useState, useEffect } from "react";
import ReactFilterChips from "react-filter-chips";

function App() {
  const EMPTY_FILTER = {
    string: "",
    number: null,
    array: [],
    Object: null,
    boolean: false,
    date: null,
  };

  const [filterState, setFilterState] = useState(EMPTY_FILTER);
  const [filterStateTem, setFilterStateTem] = useState(EMPTY_FILTER);

  const onDeleteChip = (data) => {
    console.log("Updated state:", data);
    setFilterState(data);
    setFilterStateTem(data);
  };

  const onClear = () => {
    setFilterState(EMPTY_FILTER);
    setFilterStateTem(EMPTY_FILTER);
  };

  useEffect(() => {
    const initialData = {
      string: "example string",
      number: 12345,
      array: [
        { chip_value: "array-data-1", chip_label: "Array 1" },
        { chip_value: "array-data-2", chip_label: "Array 2" },
      ],
      Object: {
        chip_value: "object-data-1",
        chip_label: "Object 1",
      },
      boolean: true,
      date: new Date(),
    };
    setFilterState(initialData);
    setFilterStateTem(initialData);
  }, []);

  return (
    <div className="App">
      <ReactFilterChips
        filterData={filterState}
        tempState={filterStateTem}
        emptyFilter={EMPTY_FILTER}
        clearLabel="Clear All"
        filterLabel="Filter By"
        onDeleteChip={onDeleteChip}
        onClear={onClear}
      />
    </div>
  );
}

export default App;

Props

PropTypeDescriptionDefault
filterDataObjectThe main filter data that is displayed as chips. This should be an object with various key-value pairs representing the filters.
tempStateObjectA temporary state object to keep track of the current state of filters.
emptyFilterObjectAn object representing the empty state of filters. Used to reset the filters.
alterFilterObject(Optional) An object representing the altered state of filters. This can be used to change the state of filters when a chip is removed.
removeItemsArray(Optional) An array of keys that should be excluded from being displayed as chips.
onDeleteChipFunctionA callback function that is called when a chip is deleted. It receives the updated filter state as an argument.
onClearFunctionA callback function that is called when the "Clear All" button is clicked. It resets the filter state.
clearLabelString(Optional) The label for the "Clear All" button. Defaults to an empty string.""
filterLabelString(Optional) The label that appears before the filter chips. Defaults to an empty string.""
chipstyleObject(Optional) A style object to customize the appearance of the chips.
iconStyleObject(Optional) A style object to customize the appearance of the close icon on the chips.
isShowCloseStartBoolean(Optional) A boolean to determine if the close icon should be shown at the start of the chip. Defaults to false.false
isShowCloseBoolean(Optional) A boolean to determine if the close icon should be shown on the chips. Defaults to true.true
customIconReactNode(Optional) A custom icon to replace the default close icon.

Meta Dev Zone – @meta-dev-zone

Keywords

FAQs

Package last updated on 09 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc