forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#27401 - refactor SelectableChip into Chip composable
- Loading branch information
1 parent
0c37b85
commit 26eab78
Showing
3 changed files
with
167 additions
and
59 deletions.
There are no files selected for viewing
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,78 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.compose | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material.ChipDefaults.chipColors | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import org.mozilla.fenix.theme.FirefoxTheme | ||
|
||
/** | ||
* Default layout for a clickable chip. | ||
* | ||
* @param text [String] displayed in this chip. | ||
* @param modifier [Modifier] used to be applied to the layout of the chip. | ||
* @param textColor Optional text [Color] for the chip. | ||
* @param backgroundColor Optional background [Color] for the chip. | ||
* @param enabled [Boolean] used to determine if chip responds to user input | ||
* @param onClick Optional Callback for when the user taps this chip. | ||
*/ | ||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun Chip( | ||
text: String, | ||
modifier: Modifier = Modifier, | ||
textColor: Color = FirefoxTheme.colors.textActionPrimary, | ||
backgroundColor: Color = FirefoxTheme.colors.actionPrimary, | ||
enabled: Boolean = true, | ||
onClick: () -> Unit, | ||
) { | ||
androidx.compose.material.Chip( | ||
onClick = onClick, | ||
enabled = enabled, | ||
modifier = modifier, | ||
colors = chipColors( | ||
backgroundColor = backgroundColor, | ||
contentColor = textColor, | ||
), | ||
) { | ||
Text( | ||
text = text, | ||
style = FirefoxTheme.typography.body2, | ||
color = textColor, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) | ||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) | ||
private fun ChipPreview() { | ||
FirefoxTheme { | ||
Column( | ||
modifier = Modifier | ||
.background(FirefoxTheme.colors.layer1), | ||
verticalArrangement = Arrangement.SpaceEvenly, | ||
) { | ||
Chip( | ||
text = "Chirp", | ||
onClick = {}, | ||
) | ||
Chip( | ||
text = "NoChirp", | ||
enabled = false, | ||
onClick = {}, | ||
) | ||
} | ||
} | ||
} |
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
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