Command palette

@yasinsensoy/native

React Native · Components

Slider

Slider: a single value or a range.

4 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Try dragging, tapping the track or the ←/→, Shift, Home/End keys.

Code

import { SliderField } from "@yasinsensoy/native";

<SliderField label="Price range" name="price" max={1000} step={10} minStepsBetween={5} draggableRange
  defaultValue={[200, 600]}
  marks={[{ value: 0, label: "₺0" }, …]}
  format={{ style: "currency", currency: "TRY", maximumFractionDigits: 0 }}
  onValueCommit={search} />

Events

  1. Events appear here when you interact with the preview.

Volume: a single value, bubble on hover

Storage: marks only (1, 2, 4, 8, 16 GB)

Balance: fill in both directions from the middle (origin)

Working hours: three thumbs, value always visible

Vertical: equalizer

Controlled: catch the value with onValueCommit

Live: [25,75] · On release: [25,75]

Import

import { Slider } from "@yasinsensoy/native";

Slider

component

Slider: a single value or a range. Same calculations (@yasinsensoy/core/slider-math) and same look as the web Slider. Tapping anywhere on the track moves the nearest thumb there; dragging locks vertical scrolling while moving horizontally. With a screen reader, swiping up/down changes it step by step.

Slider(props: SliderProps<V>): ReactElement<unknown, string | JSXElementConstructor<any>>

Examples

<Slider label="Volume" defaultValue={40} />
<Slider label="Price" defaultValue={[100, 500]} min={0} max={1000} step={10}
  format={{ style: "currency", currency: "TRY", maximumFractionDigits: 0 }} />
<Slider marks={[1, 2, 4, 8, 16]} snapToMarks format={(v) => `${v} GB`} />

SliderMark

interface

A mark on the slider. Label is the label type (ReactNode on web and React Native).

NameTypeDescription
valuenumberValue of the mark.
label?LabelLabel written under the mark (beside it when vertical). Only a dot is drawn when omitted.

Slider value: a single number or a range ([20, 80]).

type SliderValue = number | readonly number[]

SliderProps

interface

Slider props.

Extends: FieldProps

NameTypeDefaultDescription
value?VValue (controlled). With an array, one thumb is drawn per element.
defaultValue?VminInitial value (uncontrolled).
onValueChange?(value: V) => voidWhenever the value changes (every step while dragging).
onValueCommit?(value: V) => voidWith the final value when the finger lifts; for expensive work such as server requests.
min?number0Minimum value.
max?number100Maximum value.
step?number1Step size.
minStepsBetween?number0Minimum number of steps kept between thumbs in a range.
marks?boolean | readonly (number | SliderMark<ReactNode>)[]Marks on the track: true a dot at every step, a number array dots only, a { value, label } array also draws labels below.
snapToMarks?booleanfalseThe value can only be one of the marks; marks are spaced evenly.
valueLabel?"auto" | "always" | "never""auto"Value bubble above the thumb: "auto" while dragging.
format?Intl.NumberFormatOptions | ((value: number) => ReactNode)How the value is written: Intl.NumberFormat options or a function.
locale?string{@link UIProvider} `localeLanguage of the numbers.
orientation?"horizontal" | "vertical""horizontal"Orientation; vertical increases bottom to top (height via style).
origin?numberminValue where the fill starts with a single thumb (0 for -50…50).
tone?Tone"primary"Color.
size?Size"md"Thickness and thumb size (16, 20, 24 px).
readOnly?booleanThe value is visible but cannot be changed.
thumbLabels?readonly string[]"Başlangıç" / "Bitiş" for a rangeThumb names for screen readers.
style?StyleProp<ViewStyle>Container style.