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

jb-number-input

v1.0.5

Published

number input web component

Downloads

209

Readme

jb-number-input

this is a superset component on jb-input , just for number input with extra filter and ready to use validator

Demo: codepen

instructions

install

using npm

1- install npm package

npm i jb-number-input

2- import module in one of your js in page

import 'jb-number-input';

3- use component in your html or jsx file like any other html tag

<jb-number-input label="number:" message="subtitle of input box"></jb-number-input>

using cdn

1- add script tag to your html file.

<script src="https://unpkg.com/jb-input/dist/jb-number-input.umd.js"></script>
<script src="https://unpkg.com/jb-number-input/dist/jb-number-input.umd.js"></script>

2- use web component like any other html tag whenever you need

<div class="some-app-div">
  <jb-number-input label="number:" message="subtitle of input box"></jb-number-input>
</div>

get/set value

//get value
const inputValue = document.getElementByTagName('jb-number-input').value;
//set value
document.getElementByTagName('jb-number-input').value = "new string";

Config Number parameters

if you want to control which number user may input, ex: you may want to let user input negative number or add min & max boundary or limit decimal precision. for doing so you can set number field parameter to jb-number-input.

  const numberInput = document.getElementByTagName('jb-number-input')

        //how many number you want to + or  - on user press buttons or use arrow keys default is 1
        numberInput.step=100,
        // how many decimal input accept default is infinity
        numberInput.decimalPrecision=2,
        // what char replaced to input if user paste some illegal value default is '' (empty string)
        numberInput.invalidNumberReplacement='0',
        // separate every 3 number with comma like 1000000 => 1,000,000
        numberInput.showThousandSeparator = false,
        // which char we use to separate thousand number
        numberInput.thousandSeparator =',',
        //can input accept negative number or not
        numberInput.acceptNegative=true,
        // max number value user can input. if user input bigger number it will be set to max
        numberInput.maxValue= 1000,
        //min number value user can input. if user input smaller number it will be set to this value.
        numberInput.minValue = 1,
        // will show persian number instead of english number in output but original input value remain in english char
        //if true and user type 123 and see ۱۲۳ but inputtedDom.value will be 123
        numberInput.showPersianNumber =false,

you can also set this values by html attributes:

<jb-number-input 
  min="10"
  max="100"
  step="3"
  decimal-precision="2"
  show-persian-number
  accept-negative
  thousand-separator=","
  <!-- or -->
  thousand-separator
  <!-- or -->
  thousand-separator="true"
  <!-- or -->
  thousand-separator="false"

/>

set custom style

in some cases in your project you need to change default style of web-component for example you need zero margin or different border-radius and etc.
if you want to set a custom style to this web-component all you need is to set css variable in parent scope of web-component. since jb-payment-input use jb-input underneath, read jb-input custom style list.

| variable | description | |------------------------------------------------|-------------| | --jb-number-input-input-direction | number input is ltr by default even in rtl page.so you should override it by this variable if you want it rtl or inherit | | --jb-number-input-button-width | | | --jb-number-input-increase-button-bg | | | --jb-number-input-decrease-button-bg | | | --jb-number-input-increase-button-border | | | --jb-number-input-decrease-button-border | | | --jb-number-input-increase-button-border-radius| | | --jb-number-input-decrease-button-border-radius| | | --jb-number-input-increase-button-color | | | --jb-number-input-decrease-button-color | | | --jb-number-input-increase-button-color-hover | | | --jb-number-input-decrease-button-color-hover | |

control Buttons

you can add + and - button into your box element for easier access to change the number with just simple click or touch. if you want to add this buttons you just have to set showControlButton of component:

document.getElementByTagName('jb-number-input').showControlButton = true //or false

or you can set show-control-button attribute

<jb-number-input show-control-button>
<jb-number-input show-control-button="true">
<jb-number-input show-control-button="false">

after that if user click on the + or - value will increase or decrease base on the step you set in step attribute(default is 1).
click on + - button will call onChange event.

Other Related Docs: