1.0.4 • Published 4 months ago

nested-select-react v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Nested Select React

A flexible, accessible nested select component for React applications that allows users to navigate and select from hierarchical data.

Installation

npm install nested-select-react
# or
yarn add nested-select-react

Usage

import { NestedSelect } from 'nested-select-react';

// Your hierarchical data
const categories = [
  {
    id: '1',
    name: 'Electronics',
    children: [
      {
        id: '1-1',
        name: 'Computers',
        children: [
          { id: '1-1-1', name: 'Laptops' },
          { id: '1-1-2', name: 'Desktops' }
        ]
      },
      { id: '1-2', name: 'Smartphones' }
    ]
  },
  {
    id: '2',
    name: 'Clothing',
    children: [
      { id: '2-1', name: 'Men' },
      { id: '2-2', name: 'Women' }
    ]
  }
];

function App() {
  const [selectedCategory, setSelectedCategory] = useState(null);

  const handleSelect = (category) => {
    setSelectedCategory(category);
    console.log('Selected:', category);
  };

  return (
    <div>
      <h1>Product Category</h1>
      <NestedSelect
        items={categories}
        selectedItemId={selectedCategory?.id}
        onSelect={handleSelect}
        placeholder="Select a category..."
      />
    </div>
  );
}

Props

PropTypeDefaultDescription
itemsarrayrequiredArray of hierarchical items
selectedItemIdstring/numbernullID of the currently selected item
onSelectfunctionrequiredCallback when an item is selected
idKeystring'id'Key to use for item IDs
labelKeystring'name'Key to use for item labels
childrenKeystring'children'Key to use for item children
placeholderstring'Select an item...'Placeholder text when no item is selected
maxHeightstring/number'15rem'Maximum height of the dropdown menu
classNamestring''Additional CSS classes for the component
dropdownClassNamestring''Additional CSS classes for the dropdown
showSelectAllbooleantrueWhether to show the "Select All" button
showBreadcrumbbooleantrueWhether to show the breadcrumb navigation
renderItemfunction-Custom renderer for items
renderTriggerfunction-Custom renderer for the trigger button
renderBreadcrumbfunction-Custom renderer for breadcrumb navigation
renderEmptyfunction-Custom renderer for empty state
disableItemfunction-Function to determine if an item should be disabled
filterItemsfunction-Function to filter items when searching
searchPlaceholderstring'Search...'Placeholder text for the search input

License

MIT

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago