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

react-simple-styleable-select

v1.4.0

Published

[![Build Status](https://travis-ci.com/shaefer/react-simple-select.svg?branch=master)](https://travis-ci.com/shaefer/react-simple-select) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https

Downloads

8

Readme

React-Simple-Select

Build Status semantic-release npm NPM

A simple select react component designed for 3 things

  1. simplicity
  2. ease of custom styling
  3. Mobile - (Works for both mobile and web out of the box)

Purpose:

I wanted a simple React component that wasn't bogged down in all the extras. Something I could easily style and extend. Something that even if I did build in some additional features I could do it in a way that didn't compromise my original simple, styleable component. It also needed to do enough easily so as to be worth creating a better starting point for future me and possibly even others.

1. Simplicity

const options = [
    {value: 1, label: 'Option 1'},
    {value: 'text value 2', label: 'Option 2'},
    {value: {complex: 'object', moreProps: 'hello'}, label: 'Option 3'}
]
const onChange = (event, val, fullOption) => {
    //triggered on select of new item and on cancellation of an item.
}
<SimpleSelect options={options} onChange={onChange}/>

2. Easy Custom Styling

A few basic props for those that fear or despise CSS. (I love CSS, so I'm happy to share.)

<SimpleSelect options={options} width='200px'/> //Fixed Width (Fluid by default)
<SimpleSelect options={options} fixedHeight/> //Fixed Height - assumes single line of text with ellipsis (Fluid by default)
<SimpleSelect options={options} hasSharpCorners> //Standard Corners (Rounded by default)

CSS is divided into a separate file for each part of the component and added extra comments to guide novices on what to change and where. We want to provide the simplest way to style or change any portion of the component easily. Regardless of your approach to styling components in React. You can inject your custom css and use the same definitions while adding a single tagname to increase CSS specificity by 1. The examples below can be added to styles.css and just work (they are 1 point more specific than the default styles). The component also behaves like a normal div...no odd behavior if placed inside another container regardless of positioning or style.

/* Default in SimpleSelect.css */
div.mySelectDefault .fieldset {
  padding: 0.5em;
  font-size: 1.2em; /*All the padding is em-based meaning if you change the font-size first you may find you are happy with the relative padding.*/
}
/* Default in SimpleSelect-legend.css */
div.mySelectDefault .fieldset .legend {
  background-color: lime;
  padding: 0em 0.5em;
  border: 1px solid green;
  font-size: 0.8em;
  font-style: italic;
  font-variant: small-caps;
}

The component pieces: The outer wrapper (.mySelectDefault), The div made to look like a fieldset(.fieldset), the legend(.legend), the currently displayed option (.selectedDisplay), the option list(.mySelectDefaultOptions), the dropdown arrow, the cancel button.

<div class="mySelectDefault">
    <div class="fieldset">
        <div class="legend"></div>
        <div class="mainSectionWrapper">
          <div class="selectedDisplay"></div>
          <div class="cancelContainer"></div>
          <div class="downArrowContainer"></div>
        </div>
        <div class="mySelectDefaultOptions"></div>
    </div>
</div>

3. Mobile

It works out of the box...


Getting Started

Since this is a create-react-scripts project you can clone the project, npm install, and npm start.


Other Documentation:

onChange

onChange fire appropriately when a new value is selected and when a value is canceled. Passing in your own onChange event will receive the core event, theCurrentVal of the option, and the fullOption (in case the label or other option properties are important to you.)

const myOnChange = (e, val, option) => {
  //do something useful like setting the state of some other component that houses the Select. 
  //the full option is passed because we allow the option value to be a complex object not just a simple text value. 
}

Why:

Why did I build this: I'll be honest I built this component after rage quitting use of all 3 of the most popular react select components online. They all do a lot of things and have a ton of features, but they are all painful to work with and painful to style (surprise...that is often the cost of complexity.) That is not to say these other options aren't great...if you need a lot of bells and whistles that might be the way to go. (Or if you just like the idea of spending more time trying to reduce the padding on a component than you did plugging it into your app). This component is meant to be a simple starting point. I did not set out to "beat" all those other components I do not underestimate the amount of work that goes into supporting a complex widget with dozens of internal features. I have great empathy around how we found ourselves in this current state, but not so much as to prevent a rage-driven coding frenzy that produced this first iteration of a new react-simple-select component. (just what we all need...)

Other Simple Selects Worth Looking at

React-Simple-Select