Skip to content

Commit

Permalink
UI: Add multipreview annotation ComponentPreviewLightDark (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz authored Sep 28, 2024
1 parent 2cea9e9 commit d9d8f4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package xyz.ksharma.krail.design.system.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
Expand All @@ -8,7 +10,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.PreviewLightDark
import xyz.ksharma.krail.design.system.preview.ComponentPreviewLightDark
import xyz.ksharma.krail.design.system.theme.KrailTheme

val LocalTextStyle = compositionLocalOf { TextStyle.Default }
Expand Down Expand Up @@ -39,13 +41,15 @@ fun Text(
}
}

@PreviewLightDark
@ComponentPreviewLightDark
@Composable
private fun TextPreview() {
KrailTheme {
Text(text = "Hello World!")
Text(text = "Hello World!", style = KrailTheme.typography.displayLarge)
Text(text = "Hello World!", style = KrailTheme.typography.displayMedium)
Text(text = "Hello World!", style = KrailTheme.typography.displaySmall)
Column(modifier = Modifier.background(color = KrailTheme.colors.background)) {
Text(text = "Typography")
Text(text = "DisplayLarge", style = KrailTheme.typography.displayLarge)
Text(text = "displayMedium", style = KrailTheme.typography.displayMedium)
Text(text = "displaySmall", style = KrailTheme.typography.displaySmall)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package xyz.ksharma.krail.design.system.preview

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.content.res.Configuration.UI_MODE_TYPE_NORMAL
import androidx.compose.ui.tooling.preview.Preview

/**
* A MultiPreview annotation for displaying a component using light and dark themes.
*/
@Retention(AnnotationRetention.BINARY)
@Target(
AnnotationTarget.ANNOTATION_CLASS,
AnnotationTarget.FUNCTION
)
@Preview(name = "Light", showBackground = true)
@Preview(name = "Dark", uiMode = UI_MODE_NIGHT_YES or UI_MODE_TYPE_NORMAL, showBackground = true)
annotation class ComponentPreviewLightDark

0 comments on commit d9d8f4b

Please sign in to comment.