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

@lockmondan/select-custom

v0.2.10

Published

A select custom for react and next

Downloads

2

Readme

select-custom

Customizable select component for React and Next.js.

Understanding the Elements

In this package, you will find 2 elements, Select and Option, which allow you to customize them as you wish.

These elements use classes generated by Tailwind CSS for their default styling. To replace these generated classes with your own Tailwind classes, you can use the tailwind-merge package, enabling you to style them however you like.

How to Style Them?

To style these elements, both have a className property. However, there is a difference: the Select component works a bit differently from the Option component.

Select

The className property uses an interface named ClassNameSelect, which consists of three attributes: classNameRoot, classNameView, and classNameOptions. Each of these attributes is responsible for a specific part of styling the Select component.

  1. classNameRoot: It takes a string type and is responsible for wrapping the entire Select element.

  2. classNameView: It can receive either the ClassNameSelectView interface or a string, and it is responsible for the display of the selected value. The ClassNameSelectView interface has four attributes:

    • style: Styles the entire view area of the Select.

    • whenShowOptions: Modifies styling when the options list is shown.

    • whenHiddenOptions: Modifies styling when the options list is hidden.

    • input: Styles the input component.

  3. classNameOptions: It can receive the ClassNameSelectComponent type or a string, and it is responsible for styling the options list. The ClassNameSelectComponent interface has three attributes:

    • style: Styles the entire options list.

    • whenShowOptions: Modifies styling when the options list is shown.

    • whenHiddenOptions: Modifies styling when the options list is hidden.

Option

The className property accepts only the string type, allowing you to style the entire component as you prefer.

How to Use Them?

To use these components, the process is similar to using traditional select and option elements. The Select component should be the parent element that wraps all Option elements. See the example below:

<Select name="car" value="0">
  <Option value="0" text="Ferrari" />
  <Option value="1" text="Porsche" />
</Select>

In this example, Select is the main container, and each Option represents a choice available within the Select.

Select

The Select component has some required attributes: name, value, and children.

  • name: Type string, is required as it is the key to capture the selected value, especially useful in a form with server actions.

  • value: Type string, sets the initially selected value from one of the options. If the value is not found, it will default to an empty string and display a default placeholder "Select an Option".

  • children: The Select element must contain at least one Option element.

Optional Attributes

  • showOptionsIcon and hiddenOptionsIcon: Type React.ElementType, responsible for changing the icon that appears in the component's view. It is recommended to use the react-icons package for swapping icons.

  • sizeIcons: Type number, changes the size of the icons in the view.

  • hiddenIcons: Type boolean, hides the icons in the view.

Option

The Option component has 2 required attributes: value and text.

  • value: Type string. This property is directly tied to the value attribute of the Select element. When the page renders, the Option with the same value will be pre-selected by the Select.

    Example:

    <Select name="car" value="0">
      <Option value="0" text="Ferrari" /> {/* Option pre-selected by Select */}
      <Option value="1" text="Porsche" />
    </Select>
  • text: Type string. This property defines the text that will be displayed by the Select element when one of the options is selected.

Optional Attributes:

  • placeholder: Type boolean. When true, this property specifies that the text of the Option will be used as a placeholder in the Select element. Whenever this Option is selected, the Select value will be an empty string.

    Example:

    <Select name="car" value="placeholder">
      <Option value="placeholder" text="Choose your car" placeholder />
      <Option value="0" text="Ferrari" />
      <Option value="1" text="Porsche" />
    </Select>
  • icon: Type React.ElementType. This attribute adds an icon to the Option element. It is recommended to use the react-icons package to add the icon.

Well, that's all and feel free to use it.