Stepper / Dev

Install

yarn add @ntds/stepper

Import

import { Stepper } from '@ntds/stepper';

Props

Stepper

PropType & Description
name
string

The name of the input. Mainly used to make the internal id of the component unique

valueRange
[number, number] | number[]

The valid value range given as an chronological array of numbers

Floating range (integer between min and max): [min, max]

Fixed values: [min, B, C, D, ..., max]

onIncrement
(value: number, direction: number) => number
Default value: "(val: number, increment: number) => ((val + increment > 1000) ? 1000 : (val + increment > 100) ? 100 : (val + increment > 10) ? 10 : 1)"

Create a custom increments function. Here you can decide the amount it will increase or decrease for each button click. Default it looks like this:

((val, increment) => ((val + increment > 1000) ? 1000 : (val + increment > 100) ? 100 : (val + increment > 10) ? 10 : 1))

align
"left" | "center" | "right"
Default value: "'center'"

How the stepper should align itself in the container

ariaLabelButtonIncrease
string

Since the button uses symbols to convey visual meaning, you need to provide the decrease/increase-button with appropriate label. Try to provide a semantic message, that includes the unit (e.g. weeks, coupons, ...)

ariaLabelButtonDecrease
string

See ariaLabelButtonIncrease.

ariaValueText
(value: number) => string

Provide a more semantic read-out when the value change for screen readers

For example: "1 uke" "2 uker" "4 kuponger"

label
string | ((info: InfoProps) => string)

Label for the (actual) number input.

errorMessage
(info: InfoProps) => string

If the user provides a invalid, too big/small or empty value, an inline error message will be shown under input. Provide a contextual message with the correct range (use the info-object to get the min, max values, for example)

value
number

Used together with onChange to control the input-component like a controlled component.

disabled
boolean

Disables the stepper both visually and interactively

onChange
(nextValue: number) => void

Called for every value change. Typically for updating the value externally.

Important! The Stepper will return NaN on ALL invalid input (empty values, too big/small values and letters). If the value becomes invalid, the component will display an error message that you provide via the errorMessage-prop.

Use Number.isNaN(value) to check if the input is valid, for example:

{Number.isNaN(customWeekCount) && (
    <div>Value is in invalid</div>
  )
}
suffix
string

Custom suffix for the input

This guide is based on version: 2.1.2