Skip to content

Instantly share code, notes, and snippets.

@MansuriYamin
Created July 16, 2023 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MansuriYamin/bf679c3596d82432528514d26a7773c5 to your computer and use it in GitHub Desktop.
Save MansuriYamin/bf679c3596d82432528514d26a7773c5 to your computer and use it in GitHub Desktop.
/**
* Object to hold defaults used by [CustomSlider]
*/
object CustomSliderDefaults {
/**
* Composable function that represents the thumb of the slider.
*
* @param thumbValue The value to display on the thumb.
* @param modifier The modifier for styling the thumb.
* @param color The color of the thumb.
* @param size The size of the thumb.
* @param shape The shape of the thumb.
*/
@Composable
fun Thumb(
thumbValue: String,
modifier: Modifier = Modifier,
color: Color = PrimaryColor,
size: Dp = ThumbSize,
shape: Shape = CircleShape,
content: @Composable () -> Unit = {
Text(
text = thumbValue,
color = Color.White,
textAlign = TextAlign.Center
)
}
) {
Box(
modifier = modifier
.thumb(size = size, shape = shape)
.background(color)
.padding(2.dp),
contentAlignment = Alignment.Center
) {
content()
}
}
/**
* Composable function that represents the track of the slider.
*
* @param sliderPositions The positions of the slider.
* @param modifier The modifier for styling the track.
* @param trackColor The color of the track.
* @param progressColor The color of the progress.
* @param height The height of the track.
* @param shape The shape of the track.
*/
@Composable
fun Track(
sliderPositions: SliderPositions,
modifier: Modifier = Modifier,
trackColor: Color = TrackColor,
progressColor: Color = PrimaryColor,
height: Dp = TrackHeight,
shape: Shape = CircleShape
) {
Box(
modifier = modifier
.track(height = height, shape = shape)
.background(trackColor)
) {
Box(
modifier = Modifier
.progress(
sliderPositions = sliderPositions,
height = height,
shape = shape
)
.background(progressColor)
)
}
}
/**
* Composable function that represents the indicator of the slider.
*
* @param indicatorValue The value to display as the indicator.
* @param modifier The modifier for styling the indicator.
* @param style The style of the indicator text.
*/
@Composable
fun Indicator(
indicatorValue: String,
modifier: Modifier = Modifier,
style: TextStyle = TextStyle(fontSize = 10.sp, fontWeight = FontWeight.Normal)
) {
Box(modifier = modifier) {
Text(
text = indicatorValue,
style = style,
textAlign = TextAlign.Center
)
}
}
/**
* Composable function that represents the label of the slider.
*
* @param labelValue The value to display as the label.
* @param modifier The modifier for styling the label.
* @param style The style of the label text.
*/
@Composable
fun Label(
labelValue: String,
modifier: Modifier = Modifier,
style: TextStyle = TextStyle(fontSize = 12.sp, fontWeight = FontWeight.Normal)
) {
Box(modifier = modifier) {
Text(
text = labelValue,
style = style,
textAlign = TextAlign.Center
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment