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

rd-flexselect

v1.1.0

Published

A simple and flexible unstyled select component library for React applications, designed to make form-building easier and more intuitive.

Downloads

7

Readme

FlexSelect - A Flexible and Unstyled Select Component for React

FlexSelect is a highly flexible and unstyled select component for React that allows you to create custom select components with ease. With its simple design, FlexSelect can adapt to various use cases and design needs, making it a perfect choice for any project that requires customizable selects.

Installation

To install FlexSelect, run the following command:

npm install rd-flexselect

Usage

To use FlexSelect, simply import it and use it in your React components:

⚠️ Warning: Best Practices for Select Components ⚠️ : Attributes such as data-select-novalue or data-select-placeholder can be used to determine whether the select element is currently displaying an empty value or a placeholder value. These attributes are helpful in designing select components to meet your specific needs. To ensure that these attributes work correctly, make sure to include the value and id attributes in selectProps. Additionally, you must provide an id for the label element to work properly.

//MyComponent.tsx

import FlexSelect from "rd-flexselect"
import React, { useState } from "react";
import "../styles/index.css"
const App = () =>{
    const [value,setValue] = useState<string>();
    function changeHandler(e : React.SyntheticEvent<HTMLSelectElement, Event>){
        setValue((e.target as HTMLSelectElement).value);
    }
    return(
            <form>
                <FlexSelect
                    containerClassName="container"
                    labelContent={"myLabel"}
                    wrapperClassName="wrapper"
                    labelClassName="label"
                    hasValueContainerClassName="onValue"
                    focusContainerClassName="container-focus"
                    selectProps={{ 
                            id : "my-select-1",
                            onChange : changeHandler,
                            value,
                            className : "select",
                            placeholder : "Select A Option",
                            // defaultValue : "NO_VALUE" // if defaultValue is NO_VALUE then nothing will be displayed if value is undefined
                            // defaultValue : "PLACEHOLDER" // if default value is set to PLACEHOLDER then placeholder value will be displayed if value is undefined
                        }}
                    >
                    <option value="option 1">option 1</option>
                    <optgroup label="Group 1">
                        <option value="option 2">option 2</option>
                        <option value="option 3">option 3</option>
                    </optgroup>
                </FlexSelect>
            </form>
    )
}
/* styles.css */
.container{
    display: flex;
    flex-direction: row;
    border: .2rem solid black;
    width: 100%;
    transition: 0.3s ease;
}
.wrapper{
    display: flex;
    flex-direction:  column;
    position: relative;
    width: 100%;
}
.select{
    border: 0;
    outline: none;
    height: 100%;
    width: 100%;
    padding: 1rem;
}
.label{
    position: absolute;
    top: 0;
    background: white;
    transform: translateY(-50%);
    padding: 0 .5rem;
    left: .5rem;
}

.after,.before{
    white-space: nowrap;
    background-color: black;
    padding: 1rem;
    text-align: center;
    color: white;
}
.container-focus{
    border-color: green;
}

.container-focus .after{
    color: green;
}

select[data-select-placeholder]{
    color: red;
}
option{
    color: gray;
}
optgroup{
    color: gray;
}

Props

FlexSelect accepts the following props:

  • selectProps : The props to be passed to the select element.

  • labelContent : The content of the label. Can be a string or a ReactNode.

  • containerClassName : The CSS class to be applied to the container element.

  • focusContainerClassName : The CSS class to be applied to the container element when it is in focus.

  • blurContainerClassName : The CSS class to be applied to the container element when it loses focus.

  • hasValueContainerClassName : The CSS class to be applied to the container element when select has a value.

  • wrapperClassName : The CSS class to be applied to the wrapper element of label and select.

  • labelClassName : The CSS class to be applied to the label element.

  • disabledOverlayElememt : A JSX element to be displayed over the select when it is disabled. If this prop is provided, the select is automatically considered as disabled.

  • beforeElement : A JSX element to be displayed before the select.

  • afterElement : A JSX element to be displayed after the select.

Contribution

Contributions are welcome and appreciated! If you find any issues or have suggestions for improvement, please submit a pull request or create an issue on the GitHub repository.

License

FlexSelect is MIT licensed.

Thanks

Thanks for using FlexSelect! If you have any questions or suggestions, feel free to open an issue or pull request.