Skip to content

Commit

Permalink
[#305] Remove customization for outlined chips
Browse files Browse the repository at this point in the history
By default all chips are outlined
  • Loading branch information
paulinea committed Nov 24, 2022
1 parent 186b3c8 commit a1521b8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ fun Chip() {
chipCustomizationState.resetLeadingElement()
}

CheckboxListItem(labelRes = R.string.component_state_outlined, checked = chipCustomizationState.outlinedChecked)
CheckboxListItem(labelRes = R.string.component_state_disabled, checked = chipCustomizationState.disabledChecked)

}) {
Expand Down Expand Up @@ -103,7 +102,7 @@ private fun Chip(chipCustomizationState: ChipCustomizationState) {

with(chipCustomizationState) {
if (isChoiceChip) {
OdsChoiceChipsFlowRow(selectedChip = choiceChipIndexSelected, outlinedChips = isOutlined) {
OdsChoiceChipsFlowRow(selectedChip = choiceChipIndexSelected) {
for (index in 1..4) {
OdsChoiceChip(
text = "${stringResource(id = chipType.value.nameRes)} $index",
Expand All @@ -116,7 +115,6 @@ private fun Chip(chipCustomizationState: ChipCustomizationState) {
OdsChip(
text = stringResource(id = R.string.component_chip_type, stringResource(id = chipType.value.nameRes)),
onClick = { clickOnElement(context, chipLabel) },
outlined = outlinedChecked.value,
leadingIcon = if (isActionChip || hasLeadingIcon) painterResource(id = R.drawable.ic_heart) else null,
leadingAvatar = if (hasLeadingAvatar) painterResource(id = R.drawable.placeholder_small) else null,
enabled = !disabledChecked.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ fun rememberChipCustomizationState(
chipType: MutableState<ChipType> = rememberSaveable { mutableStateOf(ChipType.Input) },
leadingElement: MutableState<LeadingElement> = rememberSaveable { mutableStateOf(LeadingElement.None) },
disabledChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(false) },
outlinedChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(false) },
choiceChipIndexSelected: MutableState<Int?> = rememberSaveable { mutableStateOf(null) }
) =
remember(chipType, leadingElement, disabledChecked, outlinedChecked, choiceChipIndexSelected) {
ChipCustomizationState(chipType, leadingElement, disabledChecked, outlinedChecked, choiceChipIndexSelected)
remember(chipType, leadingElement, disabledChecked, choiceChipIndexSelected) {
ChipCustomizationState(chipType, leadingElement, disabledChecked, choiceChipIndexSelected)
}

class ChipCustomizationState(
val chipType: MutableState<ChipType>,
val leadingElement: MutableState<LeadingElement>,
val disabledChecked: MutableState<Boolean>,
val outlinedChecked: MutableState<Boolean>,
val choiceChipIndexSelected: MutableState<Int?>
) {

Expand All @@ -50,7 +48,7 @@ class ChipCustomizationState(
Choice -> R.string.component_chip_type_choice
Filter -> R.string.component_chip_type_filter
}

val descriptionRes: Int
get() = when (this) {
Input -> R.string.component_chip_type_input_description
Expand Down Expand Up @@ -82,9 +80,6 @@ class ChipCustomizationState(
val isEnabled
get() = !disabledChecked.value

val isOutlined
get() = outlinedChecked.value

fun resetLeadingElement() {
leadingElement.value = LeadingElement.None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fun ChipFilter() {
OdsChoiceChip(textRes = R.string.component_element_avatar, value = ChipCustomizationState.LeadingElement.Avatar)
}

CheckboxListItem(labelRes = R.string.component_state_outlined, checked = chipCustomizationState.outlinedChecked)
CheckboxListItem(labelRes = R.string.component_state_disabled, checked = chipCustomizationState.disabledChecked)

}) {
Expand All @@ -71,7 +70,6 @@ private fun FilterChip(index: Int, customizationState: ChipCustomizationState) {
leadingAvatar = if (customizationState.hasLeadingAvatar) painterResource(id = R.drawable.placeholder_small) else null,
onClick = { selected.value = !selected.value },
selected = selected.value,
outlined = customizationState.outlinedChecked.value,
enabled = !customizationState.disabledChecked.value,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import com.orange.ods.utilities.extension.noRippleClickable
* @param text Text to display in the chip.
* @param onClick called when the chip is clicked.
* @param modifier Modifier to be applied to the chip
* @param outlined If set to true, a border will be drawn around the chip.
* @param outlined If true, a border will be drawn around the chip otherwise a filled chip will be displayed.
* @param enabled When disabled, chip will not respond to user input. It will also appear visually
* disabled and disabled to accessibility services.
* @param selected When selected the chip is highlighted (useful for choice chips).
Expand All @@ -72,7 +72,7 @@ fun OdsChip(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
outlined: Boolean = false,
outlined: Boolean = true,
enabled: Boolean = true,
selected: Boolean = false,
leadingIcon: Painter? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ import com.orange.ods.compose.component.utilities.UiModePreviews
*
* @param selectedChip The selected chips value state.
* @param modifier Modifier to be applied to the flow row.
* @param outlinedChips If set to true, a border will be drawn around [FlowRow] chips.
* @param outlinedChips If true, a border will be drawn around [FlowRow] chips. Otherwise chips will be filled.
* @param content The content of the choice chips [FlowRow].
*/
@Composable
@OdsComponentApi
fun <T> OdsChoiceChipsFlowRow(
selectedChip: MutableState<T>,
modifier: Modifier = Modifier,
outlinedChips: Boolean = false,
outlinedChips: Boolean = true,
content: @Composable OdsChoiceChipsFlowRowScope<T>.() -> Unit
) {
FlowRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import com.orange.ods.compose.theme.OdsTheme
* @param text Text to display in the chip.
* @param onClick called when the chip is clicked.
* @param modifier Modifier to be applied to the chip
* @param outlined If set to true, a border will be drawn around the chip.
* @param outlined If true, a border will be drawn around the chip otherwise the chip will be filled.
* @param enabled When disabled, chip will not respond to user input. It will also appear visually
* disabled and disabled to accessibility services.
* @param selected Highlight the chip and display a selected icon if set to true.
Expand All @@ -69,7 +69,7 @@ fun OdsFilterChip(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
outlined: Boolean = false,
outlined: Boolean = true,
enabled: Boolean = true,
selected: Boolean = false,
leadingAvatar: Painter? = null,
Expand All @@ -86,7 +86,7 @@ fun OdsFilterChip(
} else null,
enabled = enabled,
interactionSource = if (enabled) remember { MutableInteractionSource() } else remember { DisabledInteractionSource() },
colors = OdsChipDefaults.filterChipColors(),
colors = odsFilterChipColors(outlined = outlined),
leadingIcon = when {
leadingAvatar != null -> {
{
Expand Down Expand Up @@ -122,6 +122,10 @@ fun OdsFilterChip(
}
}

@OptIn(ExperimentalMaterialApi::class)
@Composable
private fun odsFilterChipColors(outlined: Boolean) = if (outlined) OdsChipDefaults.outlinedFilterChipColors() else OdsChipDefaults.filterChipColors()

@Composable
private fun OdsChipSelectedIcon(tint: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)) {
Icon(
Expand Down

0 comments on commit a1521b8

Please sign in to comment.