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

nested-collapse

v1.0.3

Published

A React component for nested collapse.

Downloads

58

Readme

nested-collapse

nested-collapse is a versatile and visually appealing UI package designed for creating collapsible nested content structures in your React applications. This package offers an easy-to-use and flexible interface, allowing you to create complex and nested UI components with minimal effort.

Features

  • Nested Collapsible Content: Easily create nested sections that can be expanded or collapsed.
  • Flexible and Customizable: Modify the appearance and behavior to suit your application’s needs.
  • Simple Integration: Lightweight and easy to integrate with any React project.

Install

  npm install nested-collapse
  yarn add nested-collapse

Live Demo

Check out the live demo here.

Example Usage

Here's an example of how nested-collapse looks in action:

Nested Collapse Screenshot

Usage

import React from 'react';
import NestedCollapse, { ICollapseData, TreeData } from "nested-collapse";

const App: React.FC = () => {
  const data: ICollapseData[] = TreeData([
    {
      id: 1,
      title: "Collapse 1",
      // Other optional props may remain
    },
    {
      id: 2,
      title: "Collapse 2",
    },
    {
      id: 3,
      title: "Collapse 1.1",
      parentId: 1,
    },
    {
      id: 4,
      title: "Collapse 1.2",
      parentId: 1,
    },
    {
      id: 5,
      title: "Collapse 1.1.1",
      parentId: 3,
    },
    {
      id: 6,
      title: "Collapse 1.1.2",
      parentId: 3,
    },
    {
      id: 7,
      title: "Collapse 1.1.1.1",
      parentId: 5,
    },
  ]);

  return (
    <>
      <NestedCollapse
        showHeaderBorder={true} // optional
        showBodyBorder={true} // optional
        colors={[
          // A string array containing colors, corresponding to the levels of the tree branches.
        ]} // optional

        data={data}
        isLoading={false} // optional

        AddItemButtonTitle={() => (<>Add Item</>)}
        AddItemComponent={({ parentId }) => (
          // The form component required to add a new object is coded here.
        )}
        HeaderOpenIcon={() => <>{/** Icon Component */}</>}
        HeaderCloseIcon={() =>  <>{/** Icon Component */}</>}
        HoverComponent={({ parentId, addChild }) => (
          <>
            // The area where operations such as adding a new item and deleting the selected item can be performed.
            // When the addChild function is executed, it creates a new child object field.
          </>
        )}
        EmptyComponent={() => (
          <>
            // If the children object is empty, the component required to provide the empty appearance.
          </>
        )}
      />
    </>
  );
}

Props

NestedCollapse component accepts the following props:

  • showHeaderBorder (boolean, optional): Controls whether the borders around the collapse headers are visible. When set to true, borders are shown.
  • showBodyBorder (boolean, optional): Determines whether the border on the left side of the collapsible area is visible. When set to true, a left border is displayed.
  • colors (string[], optional): An array of strings representing colors, sorted according to the tree's branch structure, used to visually distinguish different levels.
  • data (array, required): Contains the data structure for the collapsible content, including titles, content, and child elements for each collapse.
  • isLoading (boolean, optional): Indicates the loading state of the data. When set to true, a loading indicator is shown instead of the collapse content.
  • AddItemButtonTitle (React.ReactNode, optional): Defines the content of the button used to add a new main collapse. This could be a text or icon component.
  • AddItemComponent (React.FC, required): The form component required to add a new object within the collapse, providing necessary fields to the user.
  • HeaderOpenIcon (React.ReactNode, optional): The icon displayed when the collapse header is open, such as a downward-facing arrow.
  • HeaderCloseIcon (React.ReactNode, optional): The icon displayed when the collapse header is closed, such as a right-facing arrow.
  • HoverComponent (React.FC, required): A menu that appears when hovering over the collapse, allowing actions like adding a new item or deleting an existing one. The addChild function creates a new child element.
  • EmptyComponent (React.ReactNode, optional): The component displayed when a collapse has no child elements, such as a message saying 'No items added yet.'

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! If you have any suggestions or find any issues, feel free to open an issue or submit a pull request on GitHub.

Author

Created by Abdullah Dalgıç.

Acknowledgements

Special thanks to all the contributors and open-source projects that made this package possible.