@@ -36,7 +36,6 @@ import androidx.compose.ui.graphics.StrokeCap
3636import androidx.compose.ui.graphics.painter.Painter
3737import androidx.compose.ui.graphics.vector.ImageVector
3838import androidx.compose.ui.platform.LocalConfiguration
39- import androidx.compose.ui.res.painterResource
4039import androidx.compose.ui.res.stringResource
4140import androidx.compose.ui.semantics.hideFromAccessibility
4241import androidx.compose.ui.semantics.semantics
@@ -54,7 +53,6 @@ import com.orange.ouds.core.extensions.iconSize
5453import com.orange.ouds.core.theme.OudsTheme
5554import com.orange.ouds.core.theme.value
5655import com.orange.ouds.core.utilities.CheckedContent
57- import com.orange.ouds.core.utilities.LayeredTintedPainter
5856import com.orange.ouds.core.utilities.OudsPreview
5957import com.orange.ouds.core.utilities.OudsPreviewLightDark
6058import com.orange.ouds.core.utilities.PreviewGrid
@@ -174,7 +172,7 @@ fun OudsTag(
174172 }
175173 .padding(all = assetPadding),
176174 extraParameters = OudsTagAsset .ExtraParameters (
177- tint = assetColor(status = status, appearance = appearance, enabled = enabled, isBullet = isBulletAsset ),
175+ tint = assetColor(status = status, appearance = appearance, enabled = enabled),
178176 status = status,
179177 appearance = appearance,
180178 enabled = enabled
@@ -260,22 +258,13 @@ private fun backgroundColor(status: OudsTagStatus, appearance: OudsTagAppearance
260258}
261259
262260@Composable
263- private fun assetColor (status : OudsTagStatus , appearance : OudsTagAppearance , enabled : Boolean , isBullet : Boolean ): Color {
261+ private fun assetColor (status : OudsTagStatus , appearance : OudsTagAppearance , enabled : Boolean ): Color {
264262 return when (appearance) {
265263 OudsTagAppearance .Emphasized -> contentColor(status = status, appearance = appearance, hasLoader = false , enabled = enabled)
266- OudsTagAppearance .Muted -> when {
267- ! enabled -> OudsTheme .colorScheme.content.onAction.disabled
268- ! isBullet && status is OudsTagStatus .Warning -> Color .Unspecified // Case of two colors icon. Colors are managed by the `LayeredTintedPainter`.
269- else -> with (OudsTheme .colorScheme.content) {
270- when (status) {
271- is OudsTagStatus .Accent -> this .status.accent
272- is OudsTagStatus .Info -> this .status.info
273- is OudsTagStatus .Negative -> this .status.negative
274- is OudsTagStatus .Neutral -> default
275- is OudsTagStatus .Positive -> this .status.positive
276- is OudsTagStatus .Warning -> this .status.warning
277- }
278- }
264+ OudsTagAppearance .Muted -> if (! enabled) {
265+ OudsTheme .colorScheme.content.onAction.disabled
266+ } else {
267+ status.toAlertStatus(appearance, enabled).assetColor
279268 }
280269 }
281270}
@@ -510,9 +499,7 @@ sealed interface OudsTagAsset : OudsPolymorphicComponentContent {
510499 OudsTagAsset .ExtraParameters : :class.java,
511500 { icon ->
512501 with(icon.extraParameters) {
513- status.getDefaultIconPainter(appearance, enabled).orElse {
514- error("No default icon for status ${status::class.simpleName}")
515- }
502+ status.getPainter(appearance = appearance, enabled = enabled)
516503 }
517504 },
518505 { icon -> icon.extraParameters.status.defaultIconContentDescription }
@@ -564,13 +551,31 @@ enum class OudsTagSize {
564551 */
565552sealed class OudsTagStatus (val asset : OudsTagAsset ? = null ) {
566553
567- @Composable
568- internal open fun getDefaultIconPainter (appearance : OudsTagAppearance , enabled : Boolean ): Painter ? = null
554+ internal fun toAlertStatus (appearance : OudsTagAppearance , enabled : Boolean ): OudsAlertStatus {
555+ return when (this ) {
556+ is Neutral -> OudsAlertStatus .Neutral ()
557+ is Accent -> OudsAlertStatus .Accent ()
558+ is Positive -> OudsAlertStatus .Positive ()
559+ is Warning -> {
560+ val layeredTintedPainter = appearance != OudsTagAppearance .Emphasized && enabled && asset !is OudsTagAsset .Bullet
561+ OudsAlertStatus .Warning (layeredTintedPainter = layeredTintedPainter)
562+ }
563+ is Negative -> OudsAlertStatus .Negative ()
564+ is Info -> OudsAlertStatus .Info ()
565+ }
566+ }
569567
570568 internal open val defaultIconContentDescription: String
571569 @Composable
572570 get() = " "
573571
572+ @Composable
573+ internal fun getPainter (appearance : OudsTagAppearance , enabled : Boolean ): Painter {
574+ return OudsAlertStatus .getDefaultIconPainter(status = toAlertStatus(appearance, enabled)).orElse {
575+ error(" No painter for status ${this ::class .simpleName} " )
576+ }
577+ }
578+
574579 /* *
575580 * Default or inactive status. Used for standard labels, categories, or when no specific status needs to be communicated.
576581 * Its [asset] can be an [OudsTagAsset.Bullet], an [OudsTagAsset.Icon] or `null` if no asset is needed.
@@ -633,10 +638,6 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
633638 * Creates an instance of [OudsTagStatus.Positive] with no asset.
634639 */
635640 constructor () : this (null )
636-
637- @Composable
638- override fun getDefaultIconPainter (appearance : OudsTagAppearance , enabled : Boolean ) =
639- painterResource(OudsTheme .drawableResources.component.alert.tickConfirmationFill)
640641 }
641642
642643 /* *
@@ -658,10 +659,6 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
658659 * Creates an instance of [OudsTagStatus.Info] with no asset.
659660 */
660661 constructor () : this (null )
661-
662- @Composable
663- override fun getDefaultIconPainter (appearance : OudsTagAppearance , enabled : Boolean ) =
664- painterResource(OudsTheme .drawableResources.component.alert.infoFill)
665662 }
666663
667664 /* *
@@ -684,20 +681,6 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
684681 */
685682 constructor () : this (null )
686683
687- @Composable
688- override fun getDefaultIconPainter (appearance : OudsTagAppearance , enabled : Boolean ): Painter {
689- val iconTokens = OudsTheme .componentsTokens.icon
690- return when {
691- appearance == OudsTagAppearance .Emphasized || ! enabled -> painterResource(id = OudsTheme .drawableResources.component.alert.warningExternalShape)
692- else -> LayeredTintedPainter (
693- backPainter = painterResource(id = OudsTheme .drawableResources.component.alert.warningExternalShape),
694- backPainterColor = iconTokens.colorContentStatusWarningExternalShape.value,
695- frontPainter = painterResource(id = OudsTheme .drawableResources.component.alert.warningInternalShape),
696- frontPainterColor = iconTokens.colorContentStatusWarningInternalShape.value
697- )
698- }
699- }
700-
701684 override val defaultIconContentDescription
702685 @Composable
703686 get() = stringResource(id = R .string.core_common_warning_a11y)
@@ -723,10 +706,6 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
723706 */
724707 constructor () : this (null )
725708
726- @Composable
727- override fun getDefaultIconPainter (appearance : OudsTagAppearance , enabled : Boolean ) =
728- painterResource(OudsTheme .drawableResources.component.alert.importantFill)
729-
730709 override val defaultIconContentDescription
731710 @Composable
732711 get() = stringResource(id = R .string.core_common_error_a11y)
0 commit comments