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

@achadha235/react-tree-select

v1.0.3

Published

A React component that renders a tree of selectable tags

Downloads

7

Readme

react-tree-select

A very simple component to select options organized in a tree structure

👉 Try it out

DEMO

Install

pnpm add @achadha235/react-tree-select

Usage

import React, { useState } from "react";

// Default styles for the component
import "@achadha235/react-tree-select/style"
import { TreeSelect } from "@achadha235/react-tree-select"

const tags = [
  "Tag 1",
  "Tag 2",
  {
    value: "Tag 3",
    subtags: [
      "Tag 3.1",
      "Tag 3.2",
      {
        value: "Tag 3.3",
        subtags: ["Tag 3.3.1", "Tag 3.3.2"],
      },
    ],
  },
];

export function MyComponent() {
  const [selected, setSelected] = useState({});
  return (
    <div style={styles.container}>
      <TreeSelect
        tags={tags}
        onSelect={(newSelected) => setSelected(newSelected)}
        selected={selected}
      />
    </div>
  );
}

const styles = {
  container: {
    display: "flex",
    flexWrap: "wrap",
    gap: 2,
  },
};

Customizing Styles

The default styles can be imported into your project using the import below

import "@achadha235/react-tree-select/style"

However, if you'd like to customize the styles, you can include your own CSS. Just override the following classes to change the styles.

.tree-select {
  font-family: Arial, Helvetica, sans-serif;
}

.tree-select.tag {
  border: 2px solid black;
  border-radius: 8px;
  transition: all;
  padding: 4px 10px;
  background-color: white;
  cursor: pointer;
}

.tree-select.tag.active {
  background-color: orange;
}

.tree-select.tag:hover {
  background-color: lightgray;
}

.tree-select.tag.active:hover {
  background-color: rgb(243, 200, 118);
}

.tree-select.tag:active {
  background-color: rgb(243, 200, 118);
}

Avaliable Props

| prop | description | type | |------------ |-------------------------------------------------------------------------------- |-------------------------------------------- | | selected | An object where the options are keys and values are true if they are selected | Record<string, boolean> | | onSelected | Callback that is triggered when the selected options are changed | (updated: Record<string, boolean>) => void | | tags | An nested array containing all the available options | Array