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

stimulus-numeric-controls

v1.0.3

Published

Adds the increment and decrepment functionality to a numeric input using stimulus js

Downloads

10

Readme

Stimulus numeric controls component

Simple functionality to increase and decrease numeric value with custom controls

How to use

add data-controler="numeric-controls" on an element that is encompasing both, your numeric input field and the controls

add data-numeric-controls-target="value" on the numeric input field

add data-action="click->numeric-controls#increment" on the control that should be incrementing the numeric input field

add data-action="click->numeric-controls#decrement" on the control that should be decrementing the numeric input field

Optional

  • add step attribute to the input to increment by certain value (increments by 1 by default)
  • add min attribute to the input to not be able to decrement beyond certain value (no min by default)
  • add max attribute to not be able to incremenet beyond certain value

Example use

Simple HTML

.....
  <div data-controller="numeric-controls" style="position:relative; height: max-content">
    <input type="number" min="0" step="3"  data-numeric-controls-target="value" >
    <div style="display:flex; position: absolute; top: 25%; right: 2rem">
      <button type="button" data-action="click->numeric-controls#decrement" style="margin-right:0.5rem">-</button>
      <button type="button" data-action="click->numeric-controls#increment">+</button>
    </div>
  </div>
.....

Rails and simple form (with tailwind)

Input classes are already set up to be tailwindy

<%= simple_form_for @widget do |f| %>
  <%= f.input :name %>
  <%= f.input :category, as: :select, collection: ["one", "two", "three"] %>
    <%= f.input :price do %>
      <div data-controller="numeric-controls">
        <%= f.input :price, label: false,  input_html:{ min: 0, step: 4, data: {numeric_controls_target: "value"}} %>
        <%= content_tag(:div, class: "absolute inset-y-0 right-0 flex justify-end items-center gap-x-1.5 pe-3") do %>
          <%= button_tag(type: 'button',
                        data: { action: "click->numeric-controls#increment" },
                        class: "size-6 inline-flex justify-center items-center gap-x-2 text-sm font-medium rounded-full border border-gray-200 bg-white text-gray-800 shadow-sm hover:bg-gray-50 disabled:opacity-50 disabled:pointer-events-none dark:bg-neutral-900 dark:border-neutral-700 dark:text-white dark:hover:bg-neutral-800") do %>
            <%= content_tag(:svg, class: "flex-shrink-0 size-3.5", width: 24, height: 24, fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", stroke_width: "2", stroke_linecap: "round", stroke_linejoin: "round") do%>
                <%= content_tag(:path, nil, d: "M5 12h14")  +  content_tag(:path, nil, d: "M12 5v14")%>
            <% end %>
          <% end %>
          <%= button_tag(type: 'button',
                        data: { action: "click->numeric-controls#decrement" },
                        class: "size-6 inline-flex justify-center items-center gap-x-2 text-sm font-medium rounded-full border border-gray-200 bg-white text-gray-800 shadow-sm hover:bg-gray-50 disabled:opacity-50 disabled:pointer-events-none dark:bg-neutral-900 dark:border-neutral-700 dark:text-white dark:hover:bg-neutral-800") do %>
            <%= content_tag(:svg, class: "flex-shrink-0 size-3.5", width: 24, height: 24, fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", stroke_width: "2", stroke_linecap: "round", stroke_linejoin: "round") do%>
                <%= content_tag(:path, nil, d: "M5 12h14")%>
            <% end %>
          <% end %>
        <% end %>
      </div>
    <% end %>
  <%= f.input :bought %>
  <%= f.submit %>
<% end %>

Example 2, Example 2 screenshot

Rails, simple form and simple form configured with tailwind

<%= tailwind_simple_form_for @widget do |f| %>
  <%= f.input :name %>
  <%= f.input :category, as: :select, collection: ["one", "two", "three"] %>
  <%= f.input :price, wrapper: :numeric, input_html:{ min: 0, step: 4} %>
  <%= f.input :bought %>
  <%= f.submit %>
<% end %>