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

ocr-p14-dropdown-npm

v2.8.0

Published

The OCR-P14-DROPDOWN-NPM component is a React Dropdown component wich is a custom dropdown list that allows users to select items from a list of choices. It is fully styled using styled-components and supports search functionality to filter displayed item

Downloads

39

Readme

OCR-P14-DROPDOWN-NPM

The OCR-P14-DROPDOWN-NPM component is a React Dropdown component wich is a custom dropdown list that allows users to select items from a list of choices. It is fully styled using styled-components and supports search functionality to filter displayed items. The component handle z-index so you can have multiple dropdowns and opening one will cover the other one.

Requirements

To use this component, you need to install it in a React project and have already installed:

  • react
  • react-dom
  • styled-components
  • prop-types

If you don't have these installed, refer yourself to the documentation of each one to install them in your project or use npm command: npm i react react-dom styled-components prop-types

Installation

To install the React Dropdown component in your project, you can use npm or yarn:

npm i ocr-p14-dropdown-npm

yarn add ocr-p14-dropdown-npm

Usage

Here's how you can use the React Dropdown component in your application:

Basic Example

import React, { useState } from "react";
import Dropdown from "ocr-p14-dropdown-npm";

export default const YourComponent = () => {
    const [selectedItem, setSelectedItem] = useState("");

    const arrOfStrOrNum = ["Option 1", "Option 2", "Option 3", "Option 4"]; // arr of data to pass

    return (
        <div>
            <h1>Example of using the Dropdown component</h1>
            <Dropdown
                dropdownData={arrOfStrOrNum}
                onChange={(selection) => setSelectedItem(selection)}
            />
        </div>
    );
};

Example with name, id and reset dropdown selection

If for example, the user submit a form and you want to reset the dropdown component to its original state, you can add a state and pass the onReset props to true.

import React, { useState, useEffect } from "react";
import Dropdown from "ocr-p14-dropdown-npm";

export default const YourComponent = () => {
    const [selectedItem, setSelectedItem] = useState("");
    const [onResetState, setOnResetState] = useState(false);

    useEffect(() => {
        if(onResetState) {
            setOnResetState(false);
        }
    }, [onResetState])

    const arrOfStrOrNum = ["Option 1", "Option 2", "Option 3", "Option 4"];

    return (
        <div>
            <h1>Example of using the Dropdown component</h1>
            <Dropdown
                dropdownData={arrOfStrOrNum}
                onChange={(selection) => setSelectedItem(selection)}
                onReset={onResetState}
                name="dropdownExample"
                id="dropdownExample"
            />
            <button onClick={() => setOnResetState(true)}>Reset dropdown selection</button>
        </div>
    );
};

Props

The Dropdown component takes the following props:

  • dropdownData (array, required): An array of options to display in the dropdown menu. Each element can be a string or a number.

  • onChange (function, required): A callback function called when the user selects an item in the dropdown. The function receives the text of the selected item as a parameter.

  • onReset (variable/state, optional): A boolean wich when is "true" will reset the user's selection to a default value (the first of the array of data passed).

  • name (variable/state, optional): a string wich will be the name of the input (for label for example)

  • id (variable/state, optional): a string wich will be the id of the input

Styling

The React Dropdown component is fully styled using styled-components. You can customize the styles by adding your on CSS.

Limitations

The component is not optimized for very large lists of options, as it will render all the elements in the list. Its dropdown menu's height is limited to 25vh. For large amounts of data, we recommend using a virtualization library to optimize performance.

Notes

Make sure to handle changes to the parent component's state using the onChange.

The component has some default styling, feel free to add your own styles to match your application's theme.

License

This project is licensed under the MIT License. You are free to use, modify, and distribute it under the terms of the MIT License.