|
| 1 | +package io.homeassistant.companion.android.developer.catalog |
| 2 | + |
| 3 | +import androidx.compose.foundation.layout.fillMaxSize |
| 4 | +import androidx.compose.foundation.lazy.LazyColumn |
| 5 | +import androidx.compose.foundation.lazy.LazyListScope |
| 6 | +import androidx.compose.material.icons.Icons |
| 7 | +import androidx.compose.material.icons.filled.Add |
| 8 | +import androidx.compose.material.icons.filled.Build |
| 9 | +import androidx.compose.material3.Icon |
| 10 | +import androidx.compose.runtime.Composable |
| 11 | +import androidx.compose.ui.Modifier |
| 12 | +import androidx.compose.ui.text.style.TextOverflow |
| 13 | +import androidx.compose.ui.tooling.preview.Devices.TABLET |
| 14 | +import androidx.compose.ui.tooling.preview.Preview |
| 15 | +import io.homeassistant.companion.android.common.compose.composable.ButtonSize |
| 16 | +import io.homeassistant.companion.android.common.compose.composable.ButtonVariant |
| 17 | +import io.homeassistant.companion.android.common.compose.composable.HAAccentButton |
| 18 | +import io.homeassistant.companion.android.common.compose.composable.HAFilledButton |
| 19 | +import io.homeassistant.companion.android.common.compose.composable.HAIconButton |
| 20 | +import io.homeassistant.companion.android.common.compose.composable.HAPlainButton |
| 21 | +import io.homeassistant.companion.android.common.compose.theme.HAThemeForPreview |
| 22 | + |
| 23 | +internal const val BIG_CONTENT = |
| 24 | + "Lorem ipsum dolor sit amet, consectetur adipiscing elit." |
| 25 | + |
| 26 | +fun LazyListScope.catalogButtonsAndIndicatorsSection(variant: ButtonVariant) { |
| 27 | + buttonSection(variant = variant, enabled = true) |
| 28 | + buttonSection(variant = variant, enabled = false) |
| 29 | + buttonsWithIcon(variant = variant) |
| 30 | + buttonsWithBigContent(variant = variant) |
| 31 | +} |
| 32 | + |
| 33 | +private fun LazyListScope.buttonSection(variant: ButtonVariant, enabled: Boolean) { |
| 34 | + catalogSection(title = "Buttons ${if (enabled) "enabled" else "disabled"}") { |
| 35 | + CatalogRow { |
| 36 | + ButtonSize.entries.forEach { |
| 37 | + HAAccentButton( |
| 38 | + text = "Label", |
| 39 | + enabled = enabled, |
| 40 | + onClick = {}, |
| 41 | + variant = variant, |
| 42 | + size = it, |
| 43 | + ) |
| 44 | + } |
| 45 | + ButtonSize.entries.forEach { |
| 46 | + HAFilledButton( |
| 47 | + text = "Label", |
| 48 | + enabled = enabled, |
| 49 | + onClick = {}, |
| 50 | + variant = variant, |
| 51 | + size = it, |
| 52 | + ) |
| 53 | + } |
| 54 | + ButtonSize.entries.forEach { |
| 55 | + HAPlainButton( |
| 56 | + text = "Label", |
| 57 | + enabled = enabled, |
| 58 | + onClick = {}, |
| 59 | + variant = variant, |
| 60 | + size = it, |
| 61 | + ) |
| 62 | + } |
| 63 | + HAIconButton( |
| 64 | + Icons.Default.Build, |
| 65 | + onClick = {}, |
| 66 | + contentDescription = null, |
| 67 | + variant = variant, |
| 68 | + enabled = enabled, |
| 69 | + ) |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +@Composable |
| 75 | +private fun AddIcon() { |
| 76 | + Icon( |
| 77 | + imageVector = Icons.Default.Add, |
| 78 | + contentDescription = null, |
| 79 | + modifier = Modifier.fillMaxSize(), |
| 80 | + ) |
| 81 | +} |
| 82 | + |
| 83 | +private fun LazyListScope.buttonsWithIcon(variant: ButtonVariant) { |
| 84 | + catalogSection(title = "Buttons with Icon") { |
| 85 | + CatalogRow { |
| 86 | + HAAccentButton( |
| 87 | + text = "Label", |
| 88 | + onClick = {}, |
| 89 | + variant = variant, |
| 90 | + prefix = { AddIcon() }, |
| 91 | + ) |
| 92 | + HAFilledButton( |
| 93 | + text = "Label", |
| 94 | + onClick = {}, |
| 95 | + variant = variant, |
| 96 | + suffix = { AddIcon() }, |
| 97 | + ) |
| 98 | + HAPlainButton( |
| 99 | + text = "Label", |
| 100 | + onClick = {}, |
| 101 | + variant = variant, |
| 102 | + prefix = { AddIcon() }, |
| 103 | + suffix = { AddIcon() }, |
| 104 | + ) |
| 105 | + HAAccentButton( |
| 106 | + text = "Label", |
| 107 | + onClick = {}, |
| 108 | + enabled = false, |
| 109 | + variant = variant, |
| 110 | + prefix = { AddIcon() }, |
| 111 | + suffix = { AddIcon() }, |
| 112 | + ) |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +private fun LazyListScope.buttonsWithBigContent(variant: ButtonVariant) { |
| 118 | + catalogSection(title = "Button with big content") { |
| 119 | + CatalogRow { |
| 120 | + HAAccentButton( |
| 121 | + text = BIG_CONTENT, |
| 122 | + onClick = {}, |
| 123 | + variant = variant, |
| 124 | + prefix = { AddIcon() }, |
| 125 | + suffix = { AddIcon() }, |
| 126 | + ) |
| 127 | + HAAccentButton( |
| 128 | + text = BIG_CONTENT, |
| 129 | + onClick = {}, |
| 130 | + variant = variant, |
| 131 | + prefix = { AddIcon() }, |
| 132 | + suffix = { AddIcon() }, |
| 133 | + maxLines = 1, |
| 134 | + textOverflow = TextOverflow.Ellipsis, |
| 135 | + ) |
| 136 | + HAFilledButton( |
| 137 | + text = BIG_CONTENT, |
| 138 | + onClick = {}, |
| 139 | + variant = variant, |
| 140 | + prefix = { AddIcon() }, |
| 141 | + suffix = { AddIcon() }, |
| 142 | + ) |
| 143 | + HAFilledButton( |
| 144 | + text = BIG_CONTENT, |
| 145 | + onClick = {}, |
| 146 | + variant = variant, |
| 147 | + prefix = { AddIcon() }, |
| 148 | + suffix = { AddIcon() }, |
| 149 | + |
| 150 | + maxLines = 1, |
| 151 | + textOverflow = TextOverflow.Ellipsis, |
| 152 | + ) |
| 153 | + HAPlainButton( |
| 154 | + text = BIG_CONTENT, |
| 155 | + onClick = {}, |
| 156 | + variant = variant, |
| 157 | + prefix = { AddIcon() }, |
| 158 | + suffix = { AddIcon() }, |
| 159 | + ) |
| 160 | + HAPlainButton( |
| 161 | + text = BIG_CONTENT, |
| 162 | + onClick = {}, |
| 163 | + variant = variant, |
| 164 | + prefix = { AddIcon() }, |
| 165 | + suffix = { AddIcon() }, |
| 166 | + maxLines = 1, |
| 167 | + textOverflow = TextOverflow.Ellipsis, |
| 168 | + ) |
| 169 | + } |
| 170 | + } |
| 171 | +} |
| 172 | + |
| 173 | +@Preview(showBackground = true, device = TABLET) |
| 174 | +@Composable |
| 175 | +private fun PreviewHAButtonsAndIndicatorsScreen() { |
| 176 | + HAThemeForPreview { |
| 177 | + LazyColumn { |
| 178 | + catalogButtonsAndIndicatorsSection(ButtonVariant.PRIMARY) |
| 179 | + } |
| 180 | + } |
| 181 | +} |
0 commit comments