Merge pull request #5485 from element-hq/feature/bma/previewOnAllIcons
Add preview with all icons in the Showkase browser
This commit is contained in:
commit
ae9ca6e944
4 changed files with 106 additions and 2 deletions
|
|
@ -18,8 +18,6 @@ enum class Theme {
|
|||
Light,
|
||||
}
|
||||
|
||||
val themes = listOf(Theme.System, Theme.Dark, Theme.Light)
|
||||
|
||||
@Composable
|
||||
fun Theme.isDark(): Boolean {
|
||||
return when (this) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.compound.theme
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import app.cash.molecule.RecompositionMode
|
||||
import app.cash.molecule.moleculeFlow
|
||||
import app.cash.turbine.test
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
||||
class ThemeTest {
|
||||
@Test
|
||||
fun `isDark for System dark returns true`() {
|
||||
`isDark for System`(
|
||||
uiMode = Configuration.UI_MODE_NIGHT_YES,
|
||||
expected = true,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isDark for System light return false`() {
|
||||
`isDark for System`(
|
||||
uiMode = Configuration.UI_MODE_NIGHT_NO,
|
||||
expected = false,
|
||||
)
|
||||
}
|
||||
|
||||
fun `isDark for System`(
|
||||
uiMode: Int,
|
||||
expected: Boolean,
|
||||
) = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
var result: Boolean? = null
|
||||
CompositionLocalProvider(
|
||||
// Let set the system to dark
|
||||
LocalConfiguration provides Configuration().apply {
|
||||
this.uiMode = uiMode
|
||||
},
|
||||
) {
|
||||
result = Theme.System.isDark()
|
||||
}
|
||||
result
|
||||
}.test {
|
||||
assertThat(awaitItem()).isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isDark for Light returns false`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
Theme.Light.isDark()
|
||||
}.test {
|
||||
assertThat(awaitItem()).isFalse()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isDark for Dark returns true`() = runTest {
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
Theme.Dark.isDark()
|
||||
}.test {
|
||||
assertThat(awaitItem()).isTrue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,11 @@
|
|||
package io.element.android.libraries.designsystem.theme.components
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
|
|
@ -15,9 +20,12 @@ import androidx.compose.ui.graphics.Color
|
|||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||
|
||||
|
|
@ -134,3 +142,24 @@ fun Icon(
|
|||
internal fun IconImageVectorPreview() = ElementThemedPreview {
|
||||
Icon(imageVector = CompoundIcons.Close(), contentDescription = null)
|
||||
}
|
||||
|
||||
@Preview(group = PreviewGroup.Icons)
|
||||
@Composable
|
||||
internal fun AllIconsPreview() = ElementPreview {
|
||||
LazyVerticalGrid(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
columns = GridCells.Adaptive(32.dp),
|
||||
contentPadding = PaddingValues(2.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
CompoundIcons.allResIds.forEach { icon ->
|
||||
item {
|
||||
Icon(
|
||||
painter = painterResource(icon),
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c327e27f5b471a9413399818482be76bccd87fd5f2a9c53e312d8900587b069b
|
||||
size 102657
|
||||
Loading…
Add table
Add a link
Reference in a new issue