Skip to content

SliderPreference

SliderPreference is a preference component in Miuix that combines a title/summary with a slider control. The slider is placed in the bottom action area of the BasicComponent, making it ideal for settings screens where users need to adjust values such as volume, brightness, or font size.

Import

kotlin
import top.yukonga.miuix.kmp.preference.SliderPreference

Basic Usage

kotlin
var sliderValue by remember { mutableFloatStateOf(0.5f) }

SliderPreference(
    value = sliderValue,
    onValueChange = { sliderValue = it },
    title = "Volume"
)

With Summary

kotlin
var brightness by remember { mutableFloatStateOf(0.8f) }

SliderPreference(
    value = brightness,
    onValueChange = { brightness = it },
    title = "Brightness",
    summary = "Adjust screen brightness level"
)

Component States

Disabled State

kotlin
var value by remember { mutableFloatStateOf(0.5f) }

SliderPreference(
    value = value,
    onValueChange = { value = it },
    title = "Disabled Slider",
    summary = "This slider is currently unavailable",
    enabled = false
)

Properties

SliderPreference Properties

Property NameTypeDescriptionDefault ValueRequired
valueFloatCurrent value of the slider. If outside of valueRange provided, value will be coerced to this range-Yes
onValueChange(Float) -> UnitCallback when value changes-Yes
titleString?Title of the preferencenullNo
modifierModifierModifier applied to the componentModifierNo
titleColorBasicComponentColorsTitle text color configurationBasicComponentDefaults.titleColor()No
summaryString?Summary descriptionnullNo
summaryColorBasicComponentColorsSummary text color configurationBasicComponentDefaults.summaryColor()No
startAction@Composable (() -> Unit)?Custom start side contentnullNo
valueTextString?Current slider value text displayed in the end area with summary-style formatting. Rendered inside the Row layout with center-vertical alignment and weightnullNo
endActions@Composable (RowScope.() -> Unit)?Custom end side content, rendered after valueText within the same RownullNo
bottomAction@Composable (() -> Unit)?Custom content at the top of the bottom area, above the slidernullNo
onClick(() -> Unit)?Callback triggered on click. When non-null, an arrow icon is displayed in the end areanullNo
holdDownStateBooleanWhether the component is in the pressed statefalseNo
enabledBooleanWhether the preference is enabledtrueNo
valueRangeClosedFloatingPointRange<Float>Range of values that this slider can take. The passed value will be coerced to this range0f..1fNo
stepsIntAmount of discrete allowable values. If 0, the slider will behave continuously. Must not be negative0No
onValueChangeFinished(() -> Unit)?Called when value change has endednullNo
reverseDirectionBooleanControls the direction of slider. When false (default), follows LayoutDirection (L-R in LTR, R-L in RTL). When true, reverses the direction.falseNo
sliderHeightDpHeight of the sliderSliderDefaults.MinHeightNo
sliderColorsSliderColorsColor configuration of the sliderSliderDefaults.sliderColors()No
hapticEffectSliderDefaults.SliderHapticEffectType of haptic feedbackSliderDefaults.DefaultHapticEffectNo
showKeyPointsBooleanWhether to show key point indicators on the slider. Only works when keyPoints is not nullfalseNo
keyPointsList<Float>?Custom key point values to display on the slider. If null, uses step positions from steps parameter. Values should be within valueRangenullNo
magnetThresholdFloatMagnetic snap threshold as a fraction (0.0 to 1.0). When slider value is within this distance from a key point, it will snap to that point. Only applies when keyPoints is set0.02fNo
insideMarginPaddingValuesInternal content paddingBasicComponentDefaults.InsideMarginNo

Advanced Usage

Custom Value Range with Steps

kotlin
var temperature by remember { mutableFloatStateOf(25f) }

SliderPreference(
    value = temperature,
    onValueChange = { temperature = it },
    title = "Temperature",
    summary = "Current: ${temperature.roundToInt()}°C",
    valueRange = 16f..32f,
    steps = 15,
    hapticEffect = SliderDefaults.SliderHapticEffect.Step
)

With Start Icon

kotlin
var volume by remember { mutableFloatStateOf(0.7f) }

SliderPreference(
    value = volume,
    onValueChange = { volume = it },
    title = "Volume",
    summary = "${(volume * 100).roundToInt()}%",
    startAction = {
        Icon(
            imageVector = MiuixIcons.Basic.Audio,
            contentDescription = "Volume Icon",
            tint = MiuixTheme.colorScheme.onBackground,
            modifier = Modifier.padding(end = 16.dp)
        )
    },
    valueRange = 0f..1f
)

With Custom Key Points

kotlin
var fontSize by remember { mutableFloatStateOf(14f) }

SliderPreference(
    value = fontSize,
    onValueChange = { fontSize = it },
    title = "Font Size",
    summary = "Current: ${fontSize.roundToInt()}sp",
    valueRange = 10f..24f,
    showKeyPoints = true,
    keyPoints = listOf(10f, 12f, 14f, 16f, 18f, 20f, 24f),
    magnetThreshold = 0.05f,
    hapticEffect = SliderDefaults.SliderHapticEffect.Step
)

Changelog

Released under the Apache-2.0 License