Skip to content

Slider - Frameworks

Sliders allow users to adjust a numeric value within a given range.

AndroidreleasediOSreleasedReactreleasedReact 19releasedVuereleased

Android

Syntax

kotlin
@Composable
fun WarpSlider(
    modifier: Modifier = Modifier,
    value: Float = 0f,
    onValueChange: (Float) -> Unit,
    valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
    enabled: Boolean = true,
    onValueChangeFinished: (() -> Unit)? = null,
    showRange: Boolean = false,
    rangeStartText: String? = null,
    rangeEndText: String? = null,
    showTooltip: Boolean = true,
    formattedTooltipText: String? = null,
    @IntRange(from = 0) steps: Int = 0,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }
)

General functionality

The slider accepts a range of floats as values and returns the selected value in the onValueChange method. Basic usage example:

kotlin
var value by remember { mutableFloatStateOf(33f) }
val values = 0f..100f
        
WarpSlider(
    value = value,
    onValueChange = { value = it },
    valueRange = values,
    )

Visual options

The slider can show a tooltip with the currently selected value above the thumb when dragging. You can pass a custom formatted text to be shown on the tooltip, but if not provided the values toString() method will be used. It can also show indicators below the track showing the total possible range of values. It's possible to pass a custom range starting and/or ending text. If nothing is passed, the values toString() method will be used.

kotlin
WarpSlider(
    modifier = Modifier.padding(horizontal = dimensions.space2),
    value = value,
    onValueChange = { value = it },
    valueRange = values,
    showRange = true,
    rangeStartText = values.start.roundToInt().toString(),
    rangeEndText = values.endInclusive.roundToInt().toString(),
    showTooltip = true,
    formattedTooltipText = "${value.roundToInt()}"
)

Legacy support

Not supported.

Parameters

Required props

NameTypeDefaultDescription
onValueChange(Float) -> UnitThe function to be invoked when a value is selected

Optional Props

NameTypeDefaultDescription
modifierModifierModifierModifier for the slider
valueFloat0fThe pre-selected value
valueRangeClosedFloatingPointRange0f..1fThe value range
enabledBooleantrueDisables the slider if false
onValueChangeFinished(() -> Unit)nullThe function to be invoked when value selection is done
rangeStartTextString?null, but if showRange is true, it will be the first value of the range using its toString() methodThe string displayed as starting value
rangeEndTextString?null, but if showRange is true, it will be the last value of the range using its toString() methodThe string displayed as end value
formattedTooltipTextString?null, but if showTooltip is true, it will be the current value of the slider using its toString() methodThe string displayed in the tooltip
showTooltipBooleantrueWhether to show the tooltip with the current value when dragging
showRangeBooleanfalseWhether to show range indicators below the slider
steps@IntRange(from = 0)0Amount of steps that the slider can snap to
interactionSourceMutableInteractionSourceMutableInteractionSourceThe interaction source to be used for the start thumb

Questions?

Feel free to ask any questions on usage in the Warp DS Slack channel: #warp-design-system