|
| 1 | +/* |
| 2 | + * Copyright 2025 New Vector Ltd. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | + * Please see LICENSE files in the repository root for full details. |
| 6 | + */ |
| 7 | + |
| 8 | +package io.element.android.libraries.designsystem.atomic.atoms |
| 9 | + |
| 10 | +import androidx.compose.foundation.layout.Arrangement |
| 11 | +import androidx.compose.foundation.layout.Box |
| 12 | +import androidx.compose.foundation.layout.Column |
| 13 | +import androidx.compose.foundation.layout.padding |
| 14 | +import androidx.compose.foundation.layout.size |
| 15 | +import androidx.compose.foundation.selection.toggleable |
| 16 | +import androidx.compose.runtime.Composable |
| 17 | +import androidx.compose.ui.Modifier |
| 18 | +import androidx.compose.ui.semantics.Role |
| 19 | +import androidx.compose.ui.unit.dp |
| 20 | +import io.element.android.compound.theme.ElementTheme |
| 21 | +import io.element.android.compound.tokens.generated.CompoundIcons |
| 22 | +import io.element.android.libraries.designsystem.preview.ElementPreview |
| 23 | +import io.element.android.libraries.designsystem.preview.PreviewsDayNight |
| 24 | +import io.element.android.libraries.designsystem.theme.components.Icon |
| 25 | + |
| 26 | +@Composable |
| 27 | +fun SelectedIndicatorAtom( |
| 28 | + checked: Boolean, |
| 29 | + enabled: Boolean, |
| 30 | + modifier: Modifier = Modifier, |
| 31 | +) { |
| 32 | + if (checked) { |
| 33 | + Icon( |
| 34 | + modifier = modifier.toggleable( |
| 35 | + value = true, |
| 36 | + role = Role.Companion.Checkbox, |
| 37 | + enabled = enabled, |
| 38 | + onValueChange = {}, |
| 39 | + ), |
| 40 | + imageVector = CompoundIcons.CheckCircleSolid(), |
| 41 | + contentDescription = null, |
| 42 | + tint = if (enabled) { |
| 43 | + ElementTheme.colors.iconAccentPrimary |
| 44 | + } else { |
| 45 | + ElementTheme.colors.iconDisabled |
| 46 | + }, |
| 47 | + ) |
| 48 | + } else { |
| 49 | + Box(modifier) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +@Composable |
| 54 | +@PreviewsDayNight |
| 55 | +internal fun SelectedIndicatorAtomPreview() = ElementPreview { |
| 56 | + Column( |
| 57 | + modifier = Modifier.padding(8.dp), |
| 58 | + verticalArrangement = Arrangement.spacedBy(8.dp), |
| 59 | + ) { |
| 60 | + SelectedIndicatorAtom( |
| 61 | + modifier = Modifier.size(24.dp), |
| 62 | + checked = false, |
| 63 | + enabled = false, |
| 64 | + ) |
| 65 | + SelectedIndicatorAtom( |
| 66 | + modifier = Modifier.size(24.dp), |
| 67 | + checked = true, |
| 68 | + enabled = false, |
| 69 | + ) |
| 70 | + SelectedIndicatorAtom( |
| 71 | + modifier = Modifier.size(24.dp), |
| 72 | + checked = false, |
| 73 | + enabled = true, |
| 74 | + ) |
| 75 | + SelectedIndicatorAtom( |
| 76 | + modifier = Modifier.size(24.dp), |
| 77 | + checked = true, |
| 78 | + enabled = true, |
| 79 | + ) |
| 80 | + } |
| 81 | +} |
0 commit comments