Giter VIP home page Giter VIP logo

semantic-ui-react-numberinput's Introduction

semantic-ui-react-numberinput

Numeric input control with step buttons for Semantic UI React

version build Downloads coverage Quality Gate Status Bugs Vulnerabilities MIT License

Example image of numberInput

Example image of numberInput

Prerequisites

"react": "^16.0.0",
"react-dom": "^16.0.0",
"semantic-ui-react": "^0.87.0"

Installation

npm install --save semantic-ui-react-numberinput

Demo

NumberInput demo

Example usage

import React from 'react';
import NumberInput from 'semantic-ui-react-numberinput';

class NumberInputExample extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            value: '0'
        };
    }

    changeValue = (newValue) => {
        this.setState({ value: newValue });
    }

    render() => {(
        <NumberInput value={this.state.value} onChange={this.changeValue} />
    )};
}

Render NumberInput with step buttons on left and right side of the input (this is default behavior, if buttonPlacement is not specified)

<NumberInput buttonPlacement="leftAndRight" value={this.state.value} onChange={this.changeValue} />

Render NumberInput with step buttons on the right side of the input

<NumberInput buttonPlacement="right" value={this.state.value} onChange={this.changeValue} />

Specify allowed number range to be between 0 and 100

<NumberInput minValue={0} maxValue={100} value={this.state.value} onChange={this.changeValue} />

Specify buttons to increment/decrement by 5

<NumberInput stepAmount={5} value={this.state.value} onChange={this.changeValue} />

Specify decimal NumberInput with increment/decrement step of 0.25 and default precision of 2

<NumberInput valueType="decimal" stepAmount={0.25} value={this.state.value} onChange={this.changeValue} />

Specify decimal NumberInput with increment/decrement step of 0.1 and precision of 1

<NumberInput valueType="decimal" stepAmount={0.1} precision={1} value={this.state.value} onChange={this.changeValue} />

More examples in demo/demo.js file

Mandatory NumberInput properties

value: string, // must be parseable to integer or decimal number depending on valueType
onChange: (newValue: string) => void,

Optional NumberInput properties

property description
allowEmptyValue Specifies if value can be empty
allowMouseWheel Specifies if mouse wheel can used to change input value
buttonPlacement Specifies how step buttons are placed
id id for HTML outer div element
className class name(s) for HTML outer div element
defaultValue Specifies default value to be used when value is empty (must be integer or decimal number depending on valueType)
disabled Specifies if NumberInput is disabled
doubleClickStepAmount Specifies how much double click of a button increments/decrements the value, zero value disables double click feature
minValue Minimum value accepted for NumberInput (must be integer or decimal number depending on valueType)
maxValue Maximum value accepted for NumberInput (must be integer or decimal number depending on valueType)
maxLength Maximum length of HTML input value (must be a positive integer)
placeholder Placeholder text for input element when value is empty, applicable only when allowEmptyValue is true
precision Decimal number precision when valueType is 'decimal'
showError Specifies if HTML input element should show error style
showTooltips Specifies if tooltips are shown
size Specifies the size of the control
stepAmount Specifies how much buttons increment/decrement the value (must be a positive integer or decimal number depending on valueType)
valueType Specifies if value is integer or decimal number

Optional NumberInput property types

allowEmptyValue: boolean,
allowMouseWheel: boolean,
buttonPlacement: 'right' | 'leftAndRight' | 'none',  
id: string,
className: string,
defaultValue: number,
disabled: boolean,
doubleClickStepAmount: number,
minValue: number, 
maxValue: number,   
maxLength: number,
placeholder: string,
precision: number,
showError: boolean,
showTooltips: boolean,
size: 'mini' | 'small' | 'large' | 'big' | 'huge' | 'massive',
stepAmount: number,
valueType: 'integer' | 'decimal'

Default values for optional properties

allowEmptyValue: false,
allowMouseWheel: false,
buttonPlacement: 'leftAndRight',
id: undefined,
className: undefined,
defaultValue: undefined,
disabled: false,
doubleClickStepAmount: 0,
minValue: 0,
maxValue: 9999999999,
maxLength: 10,
placeholder: 'Enter a value',
precision: 2,
showError: false,
showTooltips: true,
size: 'small',
stepAmount: 1,
valueType: 'integer'

Keyboard actions

Key Action
ArrowUp Increments value by stepAmount
ArrowDown Decrements value by stepAmount
+ Increments value by stepAmount
- Decrements value by stepAmount
PageUp Increments value by doubleClickStepAmount
PageDown Decrements value by doubleClickStepAmount
Ctrl + ArrowUp Increments value by doubleClickStepAmount
Ctrl + ArrowDown Decrements value by doubleClickStepAmount
Ctrl + + Increments value by doubleClickStepAmount
Ctrl + - Decrements value by doubleClickStepAmount

Styling example

Example image of numberInput

styles.css

.numberInput .ui.button {
  background-color: red;
  border-radius: 0 !important;
  color: white;
}

.numberInput .ui.input > input {
  border-color: red;
  color: red;
  font-weight: bold;
  width: 50px;
}

Applying CSS using className

<NumberInput className="numberInput" value={this.state.value} onChange={this.changeValue} />

License

MIT License

My other Semantic UI React components

semantic-ui-react-numberinput's People

Contributors

dependabot[bot] avatar hexpl0it avatar pksilen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

semantic-ui-react-numberinput's Issues

disabled functionality

All the core Semantic UI React input components support a disabled property, which is really useful. May I suggest this is added to NumberInput too?

TypeScript Types

Hi there,

are there any plans to release typescript types for your package?

Greets,
Werner

Bubble or handle button events

Hi there,

if using buttons for increment/decrement the click-event is bubbling.
Please propagate the event for user handling or stop propagation like using keys.

Greets

button type

Currently, clicking on a button submits a form. Could you please add type='button' to button component?

Option to stop event propagation?

Hi

I'm trying to use this component together with react-collapsible. Sadly clicking on the NumberInput or pressing Enter while in the input field, triggers the opening/closing of the collapsible.

The creator of Collapsible said here that it can be fixed by disabling event propagation . But with the NumberInput API I don't have access to the events.

So I'd like to be able to access the events, or have an option to disable the events propagating from NumberInput.

Why an unclassed div with display: flex?

Nice component, except it's very difficult to make it fit in with other form elements the way it's constructed, as an unclassed div with display: flex - why not inline-block, for example?

Can't type . when input type is decimal

Hello,
When the valueType is set to decimal, I cannot enter the decimal point, e.g. "9.". The value is always rounded to an integer. This makes it not possible to enter decimal values like "9.23" without using the step button. Is it possible to fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.