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

netsocs-react-tree

v1.2.1

Published

Un tree reutilizable para el proyecto de netsocs

Downloads

8

Readme

Netsocs react tree

Storybooks aqui

Este opinionado componente de árbol permite integrar facilmente un árbol de componentes React en su aplicación. El árbol de componentes es una estructura de datos jerárquica que permite a los usuarios navegar a través de una lista de elementos con una estructura de árbol, donde los items pueden tener hijos que a su vez pueden tener hijos, desplegando y ocultando los elementos de la lista.

Este componente es compatible con tooltips, menu contextual, y puede ser personalizado con iconos y estilos.

Instalación

npm i netsocs-react-tree

Uso

import React from "react";
import { Tree } from "netsocs-react-tree";

const data = [
	{
		content: <span>Node 1</span>,
		id: "1",
		childrens: [
			{
				content: <span>Node 1.1</span>,
				id: "1.1",
				childrens: [
					{
						content: <span>Node 1.1.1</span>,
						id: "1.1.1",
					},
					{
						content: <span>Node 1.1.2</span>,
						id: "1.1.2",
					},
				],
			},
			{
				content: <span>Node 1.2</span>,
				id: "1.2",
			},
		],
	},
];

const App = () => {
	return <Tree nodes={data} />;
};

export default App;

Docs

export interface NodeTree {
	/**
	 * The string identifier for the node
	 */
	id: string;
	/**
	 * content of the node is a react component
	 */
	content: React.ReactNode;
	/**
	 * Array of children nodes, when is undefined the node is a leaf node
	 */
	childrens?: NodeTree[];
	/**
	 * The node is expanded or not
	 * @type boolean
	 * @default false
	 */
	expanded?: boolean;

	/**
	 * The tooltip label
	 * @default ""
	 * @type string
	 * @example "This is a tooltip"
	 */
	tooltipLabel?: string;
	/**
	 * Context menu items
	 */
	contextMenuItems?: ContextMenuItem[];
	/**
	 * The onOpenClose event of the node
	 */
	onOpenClose?: (
		expanded: boolean,
		node: NodeTree,
		event: React.MouseEvent
	) => void;
	/**
	 * The onClick event of the node
	 */
	onClick?: (node: NodeTree, event: React.MouseEvent) => void;
}

La interfaz NodeTree define la estructura de los nodos del árbol. Cada nodo tiene un identificador único, un contenido que es un componente React, un array de nodos hijos, un booleano que indica si el nodo está expandido o no, un tooltip y un array de items para el menú contextual.

export interface ContextMenuItem {
	/**
	 * The content of the context menu item
	 * @type React.ReactNode
	 * @example <span>Item 1</span>
	 * @default null
	 * @required
	 * @description The content of the context menu item
	 */
	content: React.ReactNode;
	/**
	 * The onClick event of the context menu item
	 * @type () => void
	 * @example () => console.log("Item 1 clicked")
	 * @default null
	 * @required
	 * @description The onClick event of the context menu item
	 */
	onClick: () => void;
	/**
	 * Ignore the default style of the context menu item
	 * @type boolean
	 * @example true
	 * @default false
	 * @description Ignore the default style of the context menu item
	 */
	ignoreDefaultStyle?: boolean;
}

La interfaz ContextMenuItem define la estructura de los items del menú contextual. Cada item tiene un contenido que es un componente React, un evento onClick y un booleano que indica si se debe ignorar el estilo por defecto del item.

export interface TreeProps {
	/**
	 * Array of nodes
	 */
	nodes: NodeTree[];
}

La interfaz TreeProps define las propiedades del componente Tree. El componente Tree recibe un array de nodos.

TODO

  • [ ] Permitir submenus en el menu contextual
  • [ ] Permitir personalizar el menu contextual
  • [ ] Permitir personalizar los iconos de desplegar y ocultar
  • [ ] Agregar drang and drop
  • [ ] Agregar soporte para teclado
  • [ ] Agregar soporte para accesibilidad
  • [ ] Agregar soporte para temas
  • [ ] Agregar soporte para estilos personalizados
  • [ ] Agregar soporte para personalizar los tooltips
  • [ ] Agregar tests unitarios