Skip to content

Commit

Permalink
Merge pull request #35 from kiwicom/parameter_name
Browse files Browse the repository at this point in the history
radio|checkbox: sync isError parameter name with MDC
  • Loading branch information
hrach committed Sep 23, 2021
2 parents 27502be + 2102cbe commit 3a329d7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun CheckboxScreenInner() {
Spacer(Modifier.size(32.dp))

var checkbox3 by remember { mutableStateOf(false) }
Checkbox(checked = checkbox3, error = true, onCheckedChange = { checkbox3 = !checkbox3 })
Checkbox(checked = checkbox3, isError = true, onCheckedChange = { checkbox3 = !checkbox3 })

Spacer(Modifier.size(32.dp))

Expand All @@ -65,7 +65,7 @@ fun CheckboxScreenInner() {

Spacer(Modifier.size(32.dp))

Checkbox(checked = false, enabled = false, error = true, onCheckedChange = {})
Checkbox(checked = false, enabled = false, isError = true, onCheckedChange = {})
}

Spacer(Modifier.size(32.dp))
Expand Down Expand Up @@ -111,7 +111,7 @@ fun CheckboxScreenInner() {
checked = checkbox5,
onCheckedChange = { checkbox5 = !checkbox5 },
modifier = Modifier.fillMaxWidth(),
error = true,
isError = true,
description = { Text("May the Force be with you.") },
) {
Text("Star Wars")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fun RadioScreenInner() {

Spacer(Modifier.size(32.dp))

Radio(selected = selected == 2, onClick = { selected = 2 }, error = true)
Radio(selected = selected == 2, onClick = { selected = 2 }, isError = true)

Spacer(Modifier.size(32.dp))

Expand All @@ -63,7 +63,7 @@ fun RadioScreenInner() {

Spacer(Modifier.size(32.dp))

Radio(selected = false, enabled = false, onClick = {}, error = true)
Radio(selected = false, enabled = false, onClick = {}, isError = true)
}

Spacer(Modifier.size(32.dp))
Expand Down Expand Up @@ -106,7 +106,7 @@ fun RadioScreenInner() {
selected = selected2 == 1,
onClick = { selected2 = 1 },
modifier = Modifier.fillMaxWidth(),
error = true,
isError = true,
description = { Text("May the Force be with you.") },
) {
Text("Star Wars")
Expand Down Expand Up @@ -137,7 +137,7 @@ fun RadioScreenInner() {
onClick = { selected3 = 1 },
modifier = Modifier.fillMaxWidth(),
enabled = false,
error = true,
isError = true,
description = { Text("May the Force be with you.") },
) {
Text("Star Wars")
Expand Down
4 changes: 2 additions & 2 deletions ui/src/main/java/kiwi/orbit/compose/ui/controls/Checkbox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public fun Checkbox(
onCheckedChange: (() -> Unit)?,
modifier: Modifier = Modifier,
enabled: Boolean = true,
error: Boolean = false,
isError: Boolean = false,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
) {
val borderColor by animateColorAsState(
Expand Down Expand Up @@ -75,7 +75,7 @@ public fun Checkbox(
}

val errorAlpha by animateFloatAsState(
targetValue = if (error && enabled) 1.0f else 0.0f,
targetValue = if (isError && enabled) 1.0f else 0.0f,
animationSpec = tween(durationMillis = CheckboxAnimationDuration)
)
val errorStrokeColor = OrbitTheme.colors.critical.main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public fun CheckboxField(
onCheckedChange: (() -> Unit)?,
modifier: Modifier = Modifier,
enabled: Boolean = true,
error: Boolean = false,
isError: Boolean = false,
contentPadding: PaddingValues = PaddingValues(horizontal = 16.dp, vertical = 12.dp),
description: (@Composable () -> Unit)? = null,
label: @Composable ColumnScope.() -> Unit,
Expand Down Expand Up @@ -65,7 +65,7 @@ public fun CheckboxField(
end = 10.dp
),
enabled = enabled,
error = error,
isError = isError,
interactionSource = interactionSource,
)
val topPadding = contentPadding.calculateTopPadding().coerceAtLeast(checkboxVerticalShift)
Expand Down
20 changes: 10 additions & 10 deletions ui/src/main/java/kiwi/orbit/compose/ui/controls/Radio.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public fun Radio(
onClick: (() -> Unit)?,
modifier: Modifier = Modifier,
enabled: Boolean = true,
error: Boolean = false,
isError: Boolean = false,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
) {
val borderWidth by animateDpAsState(
Expand Down Expand Up @@ -67,7 +67,7 @@ public fun Radio(
}

val errorAlpha by animateFloatAsState(
targetValue = if (error && enabled) 1f else 0f,
targetValue = if (isError && enabled) 1f else 0f,
animationSpec = tween(durationMillis = RadioAnimationDuration)
)
val errorStrokeColor = OrbitTheme.colors.critical.main
Expand All @@ -90,15 +90,15 @@ private fun DrawScope.drawRadio(borderWidth: Dp, borderColor: Color, backgroundC
}

private fun DrawScope.drawError(strokeColor: Color, shadowColor: Color, alpha: Float) {
if (alpha != 0f) {
val shadowWidth = 4.dp.toPx()
val shadowRadius = ErrorShadowRadius.toPx() - shadowWidth / 2
drawCircle(shadowColor, shadowRadius, alpha = alpha, style = Stroke(shadowWidth))
if (alpha == 0f) return

val strokeWidth = 2.dp.toPx()
val strokeRadius = RadioRadiusSize.toPx() - strokeWidth / 2
drawCircle(strokeColor, strokeRadius, alpha = alpha, style = Stroke(strokeWidth))
}
val shadowWidth = 4.dp.toPx()
val shadowRadius = ErrorShadowRadius.toPx() - shadowWidth / 2
drawCircle(shadowColor, shadowRadius, alpha = alpha, style = Stroke(shadowWidth))

val strokeWidth = 2.dp.toPx()
val strokeRadius = RadioRadiusSize.toPx() - strokeWidth / 2
drawCircle(strokeColor, strokeRadius, alpha = alpha, style = Stroke(strokeWidth))
}

private const val RadioAnimationDuration = 100
Expand Down
4 changes: 2 additions & 2 deletions ui/src/main/java/kiwi/orbit/compose/ui/controls/RadioField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public fun RadioField(
onClick: (() -> Unit)?,
modifier: Modifier = Modifier,
enabled: Boolean = true,
error: Boolean = false,
isError: Boolean = false,
contentPadding: PaddingValues = PaddingValues(horizontal = 16.dp, vertical = 12.dp),
description: (@Composable () -> Unit)? = null,
label: @Composable ColumnScope.() -> Unit,
Expand Down Expand Up @@ -66,7 +66,7 @@ public fun RadioField(
end = 10.dp
),
enabled = enabled,
error = error,
isError = isError,
interactionSource = interactionSource,
)
val topPadding = contentPadding.calculateTopPadding().coerceAtLeast(radioVerticalShift)
Expand Down

0 comments on commit 3a329d7

Please sign in to comment.