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

@yanbe/hrnet-dropdown

v1.0.11

Published

A simple dropdown menu component for React

Downloads

6

Readme

A Simple Dropdown Component For React

A simple dropdown component for React.

Prerequisites:

Description

This is a simple dropdown menu component for React. You can use it to display a number of elements on a list when clicking on the dropdown menu.

Some CSS styles are applied by default, but you can use a few props to change the style of the component (see the Example section below).

You can interact with the component with you keyboard. It is entirely focusable. Here are the keyboard options :

  • ENTER: Opens the dropdown menu. When a choice is highlighted, pressing Enter will select the choice and close the menu.

  • UP: Will move the highlight to the selected option up on the list.

  • DOWN/RIGHT: Will move the highlight to the selected option down on the list.

  • PAGE UP: Will move the highlight to the first option on the list.

  • PAGE DOWN: Will move the highlight to the last option on the list.

  • ESCAPE: Closes the dropdown menu.

Installation

  • You can install the component using the following command:
  • npm install @yanbe/hrnet-dropdown

Usage

This component is a React component, and should be usable in any React application.

You can import the Dropdown component like this :


import Dropdown from "@yanbe/hrnet-dropdown";

Example

Here is an example of the component being used in a simple way :


import React, { useState } from "react";
import Dropdown from '@yanbe/hrnet-dropdown';


function App() {

  // This is a simple array containing the data that will be used for the dropdown in this example
  const options = [
    "Option 1", 
    "Option 2", 
    "Option 3", 
    "Option 4", 
    "Option 5", 
    "Option 6", 
    "Option 7", 
    "Option 8", 
    "Option 9", 
    "Option 10"
  ];
  
  // We use a React State to handle the selection of an option
  const [selectedOption, setSelectedOption] = useState("");

  const handleSelectedOption = (option) => {
    setSelectedOption(option);
  };

  return (
    <div 
      className="App"
      style={{ 
        display: "flex", 
        flexDirection: "column", 
        alignItems: "center" 
      }}>

      <h1>Dropdown Demo</h1>

      <Dropdown
        data={options}
        label="Choices"
        placeholder="Please Select An Option"
        onSelected={handleSelectedOption}
        id="dropdown-example"
        errorMessage=""
        containerStyle={{ 
            width: '300px' 
            }}
        toggleStyle={{ 
            backgroundColor: '#eee', 
            padding: '10px' 
            }}
        menuStyle={{ 
            backgroundColor: '#fff', 
            border: '1px solid #ccc', 
            borderRadius: '4px' 
            }}
        itemStyle={{ 
            padding: '8px 12px', 
            cursor: 'pointer' 
            }}
        highlightedStyle={{ 
            backgroundColor: '#f0f0f0' 
            }}
        
      />
      <p>Your choice : {selectedOption}</p>

    </div>
  );
}

export default App;

Props

| Prop | Type | Description | | :----------------- | :-------------------- | :-------------------------------------------------------------------------------------------- | | data | arrayOf string | Required. The data passed to the dropdown menu. | | label | string | The label text above the dropdown menu. | | placeholder | string | The text showing by default on the dropdown menu. | | onSelected | func | The callback function called when a choice is selected. | | id | string | The unique ID of the dropdown menu. | | errorMessage | string | The error message showing below the dropdown that you can enable if needed. | | containerStyle | object | Empty by default. Prop to enable CSS styles that you can apply to the dropdown container. | | toggleStyle | object | Empty by default. Prop to enable CSS styles that you can apply to the dropdown toggle. | | menuStyle | object | Empty by default. Prop to enable CSS styles that you can apply to the dropdown menu. | | itemStyle | object | Empty by default. Prop to enable CSS styles that you can apply to the dropdown list. | | highlightedStyle | object | Empty by default. Prop to enable CSS styles that you can apply to a highlighted list element. |