-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96661e2
commit 9a1c5fe
Showing
3 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
core/design-system/src/main/kotlin/xyz/ksharma/krail/design/system/LocalStyle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package xyz.ksharma.krail.design.system | ||
|
||
import androidx.compose.runtime.compositionLocalOf | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.TextStyle | ||
|
||
internal val LocalTextStyle = compositionLocalOf { TextStyle.Default } | ||
internal val LocalTextColor = compositionLocalOf { Color.Unspecified } |
93 changes: 93 additions & 0 deletions
93
core/design-system/src/main/kotlin/xyz/ksharma/krail/design/system/components/TextField.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package xyz.ksharma.krail.design.system.components | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.foundation.text.BasicTextField | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.foundation.text.input.TextFieldLineLimits | ||
import androidx.compose.foundation.text.input.TextFieldState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.SolidColor | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.input.ImeAction | ||
import androidx.compose.ui.text.input.KeyboardCapitalization | ||
import androidx.compose.ui.text.input.KeyboardType | ||
import androidx.compose.ui.text.intl.LocaleList | ||
import androidx.compose.ui.tooling.preview.PreviewLightDark | ||
import androidx.compose.ui.unit.dp | ||
import xyz.ksharma.krail.design.system.LocalTextColor | ||
import xyz.ksharma.krail.design.system.LocalTextStyle | ||
import xyz.ksharma.krail.design.system.theme.KrailTheme | ||
|
||
@Composable | ||
fun TextField( | ||
modifier: Modifier = Modifier, | ||
enabled: Boolean = true, | ||
textStyle: TextStyle? = null, | ||
readOnly: Boolean = false, | ||
imeAction: ImeAction = ImeAction.Default, | ||
) { | ||
val textFieldState by remember { | ||
mutableStateOf(TextFieldState()) | ||
} | ||
|
||
CompositionLocalProvider( | ||
LocalTextColor provides KrailTheme.colors.onSecondaryContainer, | ||
LocalTextStyle provides KrailTheme.typography.titleLarge, | ||
) { | ||
Box( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.height(48.dp) | ||
.clip(RoundedCornerShape(12.dp)) | ||
.background(color = KrailTheme.colors.secondaryContainer) | ||
.padding(horizontal = 12.dp), | ||
contentAlignment = Alignment.Center | ||
) { | ||
|
||
BasicTextField( | ||
state = textFieldState, | ||
enabled = enabled, | ||
modifier = Modifier.fillMaxWidth(), | ||
textStyle = textStyle ?: LocalTextStyle.current, | ||
keyboardOptions = KeyboardOptions( | ||
capitalization = KeyboardCapitalization.None, | ||
autoCorrectEnabled = false, | ||
keyboardType = KeyboardType.Text, | ||
imeAction = imeAction, | ||
hintLocales = LocaleList.current | ||
), | ||
lineLimits = TextFieldLineLimits.SingleLine, | ||
readOnly = readOnly, | ||
cursorBrush = SolidColor(KrailTheme.colors.onSecondaryContainer), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
private fun TextFieldEnabledPreview() { | ||
KrailTheme { | ||
TextField() | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
private fun TextFieldDisabledPreview() { | ||
KrailTheme { | ||
TextField(enabled = false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters