@@ -30,10 +30,8 @@ import androidx.compose.foundation.layout.widthIn
3030import androidx.compose.foundation.shape.RoundedCornerShape
3131import androidx.compose.material3.CircularProgressIndicator
3232import androidx.compose.material3.ExperimentalMaterial3Api
33- import androidx.compose.material3.LocalRippleConfiguration
3433import androidx.compose.material3.Text
3534import androidx.compose.runtime.Composable
36- import androidx.compose.runtime.CompositionLocalProvider
3735import androidx.compose.runtime.getValue
3836import androidx.compose.runtime.remember
3937import androidx.compose.ui.Alignment
@@ -202,9 +200,9 @@ fun OudsButton(
202200 * @param interactionSource An optional hoisted [MutableInteractionSource] for observing and emitting [Interaction]s for this button. Note that if `null`
203201 * is provided, interactions will still happen internally.
204202 *
205- * @sample com.orange.ouds.core.component.samples.OudsButtonIconAndTextSample
203+ * @sample com.orange.ouds.core.component.samples.OudsButtonTextAndIconSample
206204 *
207- * @sample com.orange.ouds.core.component.samples.OudsButtonIconAndTextOnColoredBackgroundSample
205+ * @sample com.orange.ouds.core.component.samples.OudsButtonTextAndIconOnColoredBackgroundSample
208206 */
209207@Composable
210208fun OudsButton (
@@ -258,87 +256,85 @@ private fun OudsButton(
258256 val maxHeight = if (icon != null && label == null ) buttonTokens.sizeMaxHeightIconOnly.dp * iconScale else Dp .Unspecified
259257 val shape = RoundedCornerShape (buttonTokens.borderRadius.value)
260258
261- CompositionLocalProvider (LocalRippleConfiguration provides null ) {
262- val stateDescription = if (state == OudsButton .State .Loading ) stringResource(id = R .string.core_button_loading_a11y) else " "
263- val contentColor = rememberInteractionColor(interactionState = interactionState) { buttonInteractionState ->
264- val buttonState = getButtonState(enabled = enabled, style = style, interactionState = buttonInteractionState)
265- contentColor(hierarchy = hierarchy, state = buttonState)
266- }
267- val backgroundColor = rememberInteractionColor(interactionState = interactionState) { buttonInteractionState ->
268- val buttonState = getButtonState(enabled = enabled, style = style, interactionState = buttonInteractionState)
269- backgroundColor(hierarchy = hierarchy, state = buttonState)
270- }
271- val borderWidth = rememberInteractionValue(
272- interactionState = interactionState,
273- toAnimatableFloat = { it?.value.orElse { 0f } },
274- fromAnimatableFloat = { it.dp }
275- ) { buttonInteractionState ->
276- val buttonState = getButtonState(enabled = enabled, style = style, interactionState = buttonInteractionState)
277- borderWidth(hierarchy = hierarchy, state = buttonState)
278- }
279- val borderColor = rememberNullableInteractionColor(interactionState = interactionState) { buttonInteractionState ->
280- val buttonState = getButtonState(enabled = enabled, style = style, interactionState = buttonInteractionState)
281- borderColor(hierarchy = hierarchy, state = buttonState)
282- }
259+ val stateDescription = if (state == OudsButton .State .Loading ) stringResource(id = R .string.core_button_loading_a11y) else " "
260+ val contentColor = rememberInteractionColor(interactionState = interactionState) { buttonInteractionState ->
261+ val buttonState = getButtonState(enabled = enabled, style = style, interactionState = buttonInteractionState)
262+ contentColor(hierarchy = hierarchy, state = buttonState)
263+ }
264+ val backgroundColor = rememberInteractionColor(interactionState = interactionState) { buttonInteractionState ->
265+ val buttonState = getButtonState(enabled = enabled, style = style, interactionState = buttonInteractionState)
266+ backgroundColor(hierarchy = hierarchy, state = buttonState)
267+ }
268+ val borderWidth = rememberInteractionValue(
269+ interactionState = interactionState,
270+ toAnimatableFloat = { it?.value.orElse { 0f } },
271+ fromAnimatableFloat = { it.dp }
272+ ) { buttonInteractionState ->
273+ val buttonState = getButtonState(enabled = enabled, style = style, interactionState = buttonInteractionState)
274+ borderWidth(hierarchy = hierarchy, state = buttonState)
275+ }
276+ val borderColor = rememberNullableInteractionColor(interactionState = interactionState) { buttonInteractionState ->
277+ val buttonState = getButtonState(enabled = enabled, style = style, interactionState = buttonInteractionState)
278+ borderColor(hierarchy = hierarchy, state = buttonState)
279+ }
283280
284- Box (
285- modifier = modifier
286- .widthIn(min = buttonTokens.sizeMinWidth.dp)
287- .heightIn(min = buttonTokens.sizeMinHeight.dp, max = maxHeight)
288- .background(color = backgroundColor.value, shape = shape)
289- .run {
290- ifNotNull(borderWidth.value, borderColor.value) { borderWidth, borderColor ->
291- border(width = borderWidth, color = borderColor, shape = shape)
292- }.orElse {
293- this
294- }
281+ Box (
282+ modifier = modifier
283+ .widthIn(min = buttonTokens.sizeMinWidth.dp)
284+ .heightIn(min = buttonTokens.sizeMinHeight.dp, max = maxHeight)
285+ .background(color = backgroundColor.value, shape = shape)
286+ .run {
287+ ifNotNull(borderWidth.value, borderColor.value) { borderWidth, borderColor ->
288+ border(width = borderWidth, color = borderColor, shape = shape)
289+ }.orElse {
290+ this
295291 }
296- .outerBorder(state = state, shape = shape)
297- .semantics {
298- this .stateDescription = stateDescription
299- }
300- .clickable(
301- enabled = state !in remember { listOf (OudsButton .State .Disabled , OudsButton .State .Loading ) },
302- interactionSource = interactionSource,
303- indication = InteractionValuesIndication (contentColor, backgroundColor, borderColor, borderWidth),
304- onClick = onClick
305- ),
306- contentAlignment = Alignment .Center
307- ) {
308- if (state == OudsButton .State .Loading ) {
309- val loadingStyle = style as ? OudsButton .Style .Loading
310- val progress = if (getPreviewState<OudsButton .State >() == OudsButton .State .Loading ) 0.75f else loadingStyle?.progress
311- LoadingIndicator (hierarchy = hierarchy, progress = progress, scale = iconScale)
312292 }
293+ .outerBorder(state = state, shape = shape)
294+ .semantics {
295+ this .stateDescription = stateDescription
296+ }
297+ .clickable(
298+ enabled = state !in remember { listOf (OudsButton .State .Disabled , OudsButton .State .Loading ) },
299+ interactionSource = interactionSource,
300+ indication = InteractionValuesIndication (contentColor, backgroundColor, borderColor, borderWidth),
301+ onClick = onClick
302+ ),
303+ contentAlignment = Alignment .Center
304+ ) {
305+ if (state == OudsButton .State .Loading ) {
306+ val loadingStyle = style as ? OudsButton .Style .Loading
307+ val progress = if (getPreviewState<OudsButton .State >() == OudsButton .State .Loading ) 0.75f else loadingStyle?.progress
308+ LoadingIndicator (hierarchy = hierarchy, progress = progress, scale = iconScale)
309+ }
313310
314- val alpha = if (state == OudsButton .State .Loading ) 0f else 1f
315- Row (
316- modifier = Modifier
317- .alpha(alpha = alpha)
318- .padding(contentPadding(icon = icon, label = label)),
319- horizontalArrangement = Arrangement .spacedBy(buttonTokens.spaceColumnGapIcon.value),
320- verticalAlignment = Alignment .CenterVertically
321- ) {
322- if (icon != null ) {
323- val size = if (label == null ) buttonTokens.sizeIconOnly else buttonTokens.sizeIcon
324- icon.Content (
325- modifier = Modifier
326- .size(size.value * iconScale)
327- .semantics {
328- contentDescription = if (label == null ) icon.contentDescription else " "
329- },
330- extraParameters = OudsButton .Icon .ExtraParameters (tint = contentColor.value)
331- )
332- }
333- if (label != null ) {
334- Text (
335- modifier = modifier,
336- text = label,
337- color = contentColor.value,
338- style = OudsTheme .typography.label.strong.large,
339- textAlign = TextAlign .Center
340- )
341- }
311+ val alpha = if (state == OudsButton .State .Loading ) 0f else 1f
312+ Row (
313+ modifier = Modifier
314+ .alpha(alpha = alpha)
315+ .padding(contentPadding(icon = icon, label = label)),
316+ horizontalArrangement = Arrangement .spacedBy(buttonTokens.spaceColumnGapIcon.value),
317+ verticalAlignment = Alignment .CenterVertically
318+ ) {
319+ if (icon != null ) {
320+ val size = if (label == null ) buttonTokens.sizeIconOnly else buttonTokens.sizeIcon
321+ icon.Content (
322+ modifier = Modifier
323+ .size(size.value * iconScale)
324+ .semantics {
325+ contentDescription = if (label == null ) icon.contentDescription else " "
326+ },
327+ extraParameters = OudsButton .Icon .ExtraParameters (tint = contentColor.value)
328+ )
329+ }
330+ if (label != null ) {
331+ Text (
332+ modifier = modifier,
333+ text = label,
334+ color = contentColor.value,
335+ style = OudsTheme .typography.label.strong.large,
336+ textAlign = TextAlign .Center
337+ )
342338 }
343339 }
344340 }
@@ -577,8 +573,7 @@ object OudsButtonDefaults {
577573object OudsButton {
578574
579575 /* *
580- * A button icon in an [OudsButton].
581- * It is non-clickable and no content description is needed because a button label is always present.
576+ * An icon in an [OudsButton].
582577 */
583578 class Icon private constructor(
584579 graphicsObject : Any ,
0 commit comments