OneScript

Stepper

Increment or decrement a value.

A controlled stepper with plus and minus buttons. children is the label and usually shows the current value.

import { Stepper, useState } from "onescript/views"

function QuantityStepper() {
  const [count, setCount] = useState(1)
  return (
    <Stepper
      value={count}
      onChange={setCount}
      min={1}
      max={10}
    >
      {`Quantity: ${count}`}
    </Stepper>
  )
}
PropTypeDescription
valuenumberCurrent value.
onChange(value: number) => voidRuns when the user taps plus or minus.
minnumberOptional lower bound.
maxnumberOptional upper bound. Must be greater than min.
stepnumberPositive step. Defaults to 1.
onEditingChanged(editing: boolean) => voidReceives true while the user holds a button to repeat and false when they release.
childrenViewChildThe label.

The matching button is disabled at min or max.

Custom increment and decrement

Pass onIncrement and onDecrement instead of value to handle each press yourself. The side without a handler is disabled. These props cannot be combined with value, onChange, min, max, or step.

import { Stepper, useState } from "onescript/views"

function Pager({ pageCount }: { pageCount: number }) {
  const [page, setPage] = useState(1)
  return (
    <Stepper
      onIncrement={page < pageCount ? () => setPage(page + 1) : undefined}
      onDecrement={page > 1 ? () => setPage(page - 1) : undefined}
    >
      {`Page ${page}`}
    </Stepper>
  )
}
PropTypeDescription
onIncrement() => voidRuns when the user taps plus.
onDecrement() => voidRuns when the user taps minus.

At least one of them is required. Also accepts Modifiers. It is only available in App and Action view sessions; widgets reject it with an unsupported view type error.

How is this guide?

Last updated on

On this page