Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions core/src/main/java/com/orange/ouds/core/component/OudsAlert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import com.orange.ouds.core.R
import com.orange.ouds.core.component.content.OudsComponentContent
import com.orange.ouds.core.component.content.OudsComponentIcon
import com.orange.ouds.core.theme.OudsTheme
Expand All @@ -29,25 +31,33 @@ import com.orange.ouds.foundation.extensions.orElse
* Base class for defining the semantic status of an alert component ([OudsInlineAlert] or [OudsAlertMessage]).
* It holds the common logic for determining the colors and default icons.
*/
internal sealed class OudsAlertStatus(private val defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?)) {
internal sealed class OudsAlertStatus(
private val defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?),
private val defaultIconContentDescriptionProvider: (@Composable (OudsAlertStatus) -> String) = { "" }
) {

class Accent(defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?) = { getDefaultIconPainter(it) }) :
OudsAlertStatus(defaultIconPainterProvider)

class Neutral(defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?) = { getDefaultIconPainter(it) }) :
OudsAlertStatus(defaultIconPainterProvider)

class Negative(defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?) = { getDefaultIconPainter(it) }) :
OudsAlertStatus(defaultIconPainterProvider)
class Negative(
defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?) = { getDefaultIconPainter(it) },
defaultIconContentDescriptionProvider: (@Composable (OudsAlertStatus) -> String) = { stringResource(R.string.core_common_error_a11y) }
) : OudsAlertStatus(defaultIconPainterProvider, defaultIconContentDescriptionProvider)

class Positive(defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?) = { getDefaultIconPainter(it) }) :
OudsAlertStatus(defaultIconPainterProvider)

class Info(defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?) = { getDefaultIconPainter(it) }) :
OudsAlertStatus(defaultIconPainterProvider)

class Warning(defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?) = { getDefaultIconPainter(it) }) :
OudsAlertStatus(defaultIconPainterProvider)
class Warning(
defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?) = { getDefaultIconPainter(it) },
defaultIconContentDescriptionProvider: (@Composable (OudsAlertStatus) -> String) = { stringResource(R.string.core_common_warning_a11y) }
) :
OudsAlertStatus(defaultIconPainterProvider, defaultIconContentDescriptionProvider)

companion object {

Expand Down Expand Up @@ -80,6 +90,10 @@ internal sealed class OudsAlertStatus(private val defaultIconPainterProvider: (@
@Composable
get() = defaultIconPainterProvider(this)

val defaultIconContentDescription: String
@Composable
get() = defaultIconContentDescriptionProvider(this)

/**
* The asset color associated with this status.
*/
Expand All @@ -103,45 +117,51 @@ internal sealed class OudsAlertStatus(private val defaultIconPainterProvider: (@
* This class handles the creation of the icon from different sources like [Painter], [ImageVector], or [ImageBitmap].
* An accessibility description is not required, as the alert's main `label` should provide the necessary context.
*/
open class OudsAlertIcon private constructor(graphicsObjectProvider: @Composable (OudsAlertIcon) -> Any) :
open class OudsAlertIcon private constructor(
graphicsObjectProvider: @Composable (OudsAlertIcon) -> Any,
contentDescriptionProvider: @Composable (OudsAlertIcon) -> String
) :
OudsComponentIcon<OudsAlertIcon.ExtraParameters, OudsAlertIcon>(
ExtraParameters::class.java,
graphicsObjectProvider,
{ "" }
contentDescriptionProvider
) {

/**
* The default icon of an [OudsAlertMessage] or an [OudsInlineAlert].
* This icon is non-clickable. No content description is needed because an alert always contains a label.
* This icon is non-clickable. A content description is only set for Warning and Error statuses to provide context. No content description is needed
* for other statuses because the alert's `label` should provide the necessary context.
*/
object Default : OudsAlertIcon({ icon ->
with(icon.extraParameters) {
status.defaultIconPainter.orElse {
error("No default icon for status ${status::class.simpleName}")
object Default : OudsAlertIcon(
{ icon ->
with(icon.extraParameters) {
status.defaultIconPainter.orElse {
error("No default icon for status ${status::class.simpleName}")
}
}
}
})
},
{ icon -> icon.extraParameters.status.defaultIconContentDescription })

/**
* Creates an instance of [OudsAlertIcon].
*
* @property painter Painter of the icon.
*/
constructor(painter: Painter) : this({ painter })
constructor(painter: Painter) : this({ painter }, { "" })

/**
* Creates an instance of [OudsAlertIcon].
*
* @property imageVector Image vector of the icon.
*/
constructor(imageVector: ImageVector) : this({ imageVector })
constructor(imageVector: ImageVector) : this({ imageVector }, { "" })

/**
* Creates an instance of [OudsAlertIcon].
*
* @property bitmap Image bitmap of the icon.
*/
constructor(bitmap: ImageBitmap) : this({ bitmap })
constructor(bitmap: ImageBitmap) : this({ bitmap }, { "" })

override val tint: Color?
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -124,6 +125,7 @@ fun OudsAlertMessage(
border(width = it, color = status.borderColor, shape = shape)
} ?: this
}
.semantics(mergeDescendants = true) {}
.padding(start = spacePaddingInline.value, end = if (hasCloseButton) 0.dp else spacePaddingInline.value),
horizontalArrangement = Arrangement.spacedBy(spaceColumnGap.value)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
Expand All @@ -38,7 +39,7 @@ import com.orange.ouds.theme.OudsThemeContract

/**
* Inline alert is a lightweight UI element, placed in the content flow, that displays information, system feedback, status changes throughout short, prominent,
* persistent and non actionable communication. Inline alert includes functional icon and semantic colour, and does not include a close button and/or action
* persistent and non-actionable communication. Inline alert includes functional icon and semantic colour, and does not include a close button and/or action
* link. Inline alert does not disappear and remains visible.
*
* > Design guidelines: [unified-design-system.orange.com](https://r.orange.fr/r/S-ouds-doc-inline-alert)
Expand Down Expand Up @@ -69,7 +70,10 @@ fun OudsInlineAlert(
) {
with(OudsTheme.componentsTokens.alert) {
val scale = LocalConfiguration.current.fontScale
Row(modifier = modifier, horizontalArrangement = Arrangement.spacedBy(spaceColumnGap.value)) {
Row(
modifier = modifier.semantics(mergeDescendants = true) {},
horizontalArrangement = Arrangement.spacedBy(spaceColumnGap.value)
) {
status.icon.Content(
modifier = Modifier
.size(sizeIcon.value * scale),
Expand Down
22 changes: 16 additions & 6 deletions core/src/main/java/com/orange/ouds/core/component/OudsTag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ fun OudsTag(
horizontalArrangement = Arrangement.spacedBy(betweenAssetAndLabelSpace(size = size), Alignment.CenterHorizontally),
) {
if (hasAsset) {
Box(
modifier = Modifier
.semantics { hideFromAccessibility() }
) {
Box {
if (hasLoader) {
ProgressIndicator(status = status, appearance = appearance, size = size, progress = loader.progress, enabled = enabled)
} else {
Expand Down Expand Up @@ -479,7 +476,8 @@ sealed interface OudsTagAsset : OudsPolymorphicComponentContent {

/**
* The default icon of an [OudsTag].
* This icon is non-clickable. No content description is needed because a tag always contains a label.
* This icon is non-clickable. A content description is only set for Warning and Error statuses to provide context. No content description is needed
Comment thread
florentmaitre marked this conversation as resolved.
* for other statuses because the tag's `label` should provide the necessary context.
*/
data object Default : OudsTagAsset, OudsComponentIcon<OudsTagAsset.ExtraParameters, Default>(
OudsTagAsset.ExtraParameters::class.java,
Expand All @@ -490,7 +488,7 @@ sealed interface OudsTagAsset : OudsPolymorphicComponentContent {
}
}
},
{ "" }
{ icon -> icon.extraParameters.status.defaultIconContentDescription }
) {

override val tint: Color?
Expand Down Expand Up @@ -541,6 +539,10 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
@Composable
internal open fun getDefaultIconPainter(appearance: OudsTagAppearance): Painter? = null

internal open val defaultIconContentDescription: String
@Composable
get() = ""

/**
* Default or inactive status. Used for standard labels, categories, or when no specific status needs to be communicated.
* Its [asset] can be an [OudsTagAsset.Bullet], an [OudsTagAsset.Icon] or `null` if no asset is needed.
Expand Down Expand Up @@ -665,6 +667,10 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
)
}
}

override val defaultIconContentDescription
@Composable
get() = stringResource(id = R.string.core_common_warning_a11y)
}

/**
Expand All @@ -689,6 +695,10 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {

@Composable
override fun getDefaultIconPainter(appearance: OudsTagAppearance) = painterResource(OudsTheme.drawableResources.component.alert.importantFill)

override val defaultIconContentDescription
@Composable
get() = stringResource(id = R.string.core_common_error_a11y)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ internal fun OudsTextInputDecorator(
Icon(
modifier = Modifier.size(buttonTokens.sizeIconOnly.value * iconScale),
painter = painterResource(id = OudsTheme.drawableResources.component.alert.importantFill),
contentDescription = if (error.message.isBlank()) stringResource(R.string.core_textInput_error_a11y) else null,
contentDescription = if (error.message.isBlank()) stringResource(R.string.core_common_error_a11y) else null,
tint = errorIconColor(state = state)
)
}
Expand Down
13 changes: 7 additions & 6 deletions core/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
-->

<resources>
<string name="core_common_error_a11y">خطأ</string>
<string name="core_common_loading_a11y">جاري التحميل</string>
<string name="core_common_warning_a11y">تحذير</string>

<string name="core_alertMessage_close_a11y">إغلاق alert message</string>

Expand All @@ -27,13 +29,12 @@

<string name="core_inputTag_remove_a11y">يزيل</string>

<string name="core_topAppBar_backNavigationIcon_a11y">رجوع</string>
<string name="core_topAppBar_closeNavigationIcon_a11y">إغلاق</string>
<string name="core_topAppBar_menuNavigationIcon_a11y">القائمة</string>
<string name="core_passwordInput_hidePassword_a11y">Hide password</string>
<string name="core_passwordInput_showPassword_a11y">Show password</string>

<string name="core_textInput_empty_a11y">فارغ</string>
<string name="core_textInput_error_a11y">خطأ</string>

<string name="core_passwordInput_showPassword_a11y">Show password</string>
<string name="core_passwordInput_hidePassword_a11y">Hide password</string>
<string name="core_topAppBar_backNavigationIcon_a11y">رجوع</string>
<string name="core_topAppBar_closeNavigationIcon_a11y">إغلاق</string>
<string name="core_topAppBar_menuNavigationIcon_a11y">القائمة</string>
</resources>
14 changes: 7 additions & 7 deletions core/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
-->

<resources>
<string name="core_common_error_a11y">Erreur</string>
<string name="core_common_loading_a11y">Chargement</string>
<string name="core_common_warning_a11y">Avertissement</string>

<string name="core_alertMessage_close_a11y">Fermer le message d\'alerte</string>

Expand All @@ -23,14 +25,12 @@

<string name="core_inputTag_remove_a11y">Supprimer</string>

<string name="core_topAppBar_backNavigationIcon_a11y">Retour</string>
<string name="core_topAppBar_closeNavigationIcon_a11y">Fermer</string>
<string name="core_topAppBar_menuNavigationIcon_a11y">Menu</string>
<string name="core_passwordInput_hidePassword_a11y">Masquer le mot de passe</string>
<string name="core_passwordInput_showPassword_a11y">Afficher le mot de passe</string>

<string name="core_textInput_empty_a11y">Vide</string>
<string name="core_textInput_error_a11y">Erreur</string>

<string name="core_passwordInput_showPassword_a11y">Afficher le mot de passe</string>
<string name="core_passwordInput_hidePassword_a11y">Masquer le mot de passe</string>

<string name="core_topAppBar_backNavigationIcon_a11y">Retour</string>
<string name="core_topAppBar_closeNavigationIcon_a11y">Fermer</string>
<string name="core_topAppBar_menuNavigationIcon_a11y">Menu</string>
</resources>
13 changes: 7 additions & 6 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
-->

<resources>
<string name="core_common_error_a11y">Error</string>
<string name="core_common_loading_a11y">Loading</string>
<string name="core_common_warning_a11y">Warning</string>

<string name="core_alertMessage_close_a11y">Close alert message</string>

Expand All @@ -23,13 +25,12 @@

<string name="core_inputTag_remove_a11y">Remove</string>

<string name="core_topAppBar_backNavigationIcon_a11y">Back</string>
<string name="core_topAppBar_closeNavigationIcon_a11y">Close</string>
<string name="core_topAppBar_menuNavigationIcon_a11y">Menu</string>
<string name="core_passwordInput_hidePassword_a11y">Hide password</string>
<string name="core_passwordInput_showPassword_a11y">Show password</string>

<string name="core_textInput_empty_a11y">Empty</string>
<string name="core_textInput_error_a11y">Error</string>

<string name="core_passwordInput_showPassword_a11y">Show password</string>
<string name="core_passwordInput_hidePassword_a11y">Hide password</string>
<string name="core_topAppBar_backNavigationIcon_a11y">Back</string>
<string name="core_topAppBar_closeNavigationIcon_a11y">Close</string>
<string name="core_topAppBar_menuNavigationIcon_a11y">Menu</string>
</resources>