DocsBlog
  • 0.25.3

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Styling
Theming

Concepts

OverviewCompositionTesting

Layout

Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

Number Input

The Number Input component is used to manage numeric input fields.

  • npm
  • source
  • recipe
  • Ark
import { NumberInput } from '@cerberus/react'

Usage

The NumberInput component provides a way to create input fields specifically for numeric values. It includes features such as increment and decrement buttons, and can be easily integrated with form libraries.

Choose your quantity.
Copy
import { Field, NumberInput } from '@cerberus/react'
import { Box } from 'styled-system/jsx'
export function NumberInputDemo() {
return (
<Box w="1/2">
<Field label="How many?" helperText="Choose your quantity.">
<NumberInput />
</Field>
</Box>
)
}

Scrubber

The NumberInput supports the scrubber interaction pattern. To use this pattern, use the scrubber prop. It uses the Pointer lock API and tracks the pointer movement. It also renders a virtual cursor which mimics the real cursor's pointer

Use your mouse wheel to change the value.
Copy
import { Box } from 'styled-system/jsx'
import { Field, NumberInput } from '@cerberus/react'
export function ScrubberDemo() {
return (
<Box w="1/2">
<Field
label="How many?"
helperText="Use your mouse wheel to change the value."
>
<NumberInput scrubber />
</Field>
</Box>
)
}

Sizes

The NumberInput component supports different sizes to accommodate various design requirements. You can specify the size using the size prop.

Copy
import { Field, NumberInput } from '@cerberus/react'
import { Box, HStack } from 'styled-system/jsx'
export function SizesDemo() {
return (
<HStack w="3/4">
<Field label="Small size">
<NumberInput size="sm" />
</Field>
<Field label="Medium size">
<NumberInput size="md" />
</Field>
<Field label="Large size">
<NumberInput size="lg" />
</Field>
</HStack>
)
}

Primitives

You can utilize the primitive components or the css prop to customize the number input.

ComponentDescription
NumberInputRootThe context provider for the NumberInput parts
NumberInputLabelThe label of the NumberInput
NumberInputControlThe wrapper of the NumberInput contents
NumberInputInputThe input of the NumberInput
NumberInputIncrementTriggerThe increment button of the NumberInput
NumberInputDecrementTriggerThe decrement button of the NumberInput
NumberInputScrubberThe scrubber of the NumberInput
Copy
import { NumberInputParts } from '@cerberus/react'
import { Add, Subtract } from '@carbon/icons-react'
import { HStack } from 'styled-system/jsx'
export function CustomDemo() {
return (
<HStack w="1/2">
<NumberInputParts.Root
css={{
display: 'flex',
w: 'full',
}}
>
<NumberInputParts.Label
css={{
textStyle: 'heading-xs',
}}
>
This is custom
</NumberInputParts.Label>
<NumberInputParts.Control>
<NumberInputParts.Input />
<NumberInputParts.IncrementTrigger
css={{
bgColor: 'success.surface.initial',
color: 'success.text.initial',
}}
>
<Add />
</NumberInputParts.IncrementTrigger>
<NumberInputParts.DecrementTrigger
css={{
bgColor: 'danger.surface.initial',
color: 'danger.text.inverse',
}}
>
<Subtract />
</NumberInputParts.DecrementTrigger>
<NumberInputParts.Scrubber />
</NumberInputParts.Control>
</NumberInputParts.Root>
</HStack>
)

API

Props

The NumberInput component is an abstraction of the primitives and accepts the following props:

NameDefaultDescription
scrubberfalseUse scrubber controls for the number input.

The NumberInput component also accepts all the props of the NumberInputRoot primitive props

Parts

The NumberInputParts API is an Object containing the full family of components.

Note

It is best to only use the NumberInputParts if you are building a custom solution. Importing Object based components will ship every property it includes into your bundle, regardless if you use it or not.

NameDescription
RootThe NumberInputRoot component which is the Provider for the family.
LabelThe NumberInputLabel component which displays the label and "required" notice.
InputThe NumberInputInput component which is the input field.
ControlThe NumberInputControl component which is the wrapper for the input and buttons.
IncrementTriggerThe NumberInputIncrementTrigger component which is the increment button.
DecrementTriggerThe NumberInputDecrementTrigger component which is the decrement button.
ScrubberThe NumberInputScrubber component which is the scrubber control.

On this page

  • Edit this page on Github
Cerberus Design System | Docs