Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@

<issue
id="InvalidDaxTextColorUsage"
message="Use DuckDuckGoTheme.textColors instead of arbitrary Color values to maintain design system consistency and theme support.&#xA;&#xA;Examples:&#xA;• DuckDuckGoTheme.textColors.primary&#xA;• DuckDuckGoTheme.textColors.secondary&#xA;&#xA;For one-off cases requiring custom colors, use good judgement or consider raising it in the Android Design System AOR."
message="Use DuckDuckGoTheme.colors.text instead of arbitrary Color values to maintain design system consistency and theme support.&#xA;&#xA;Examples:&#xA;• DuckDuckGoTheme.colors.text.primary&#xA;• DuckDuckGoTheme.colors.text.secondary&#xA;&#xA;For one-off cases requiring custom colors, use good judgement or consider raising it in the Android Design System AOR."
errorLine1=" color = DuckDuckGoTheme.colors.destructive,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ColorPaletteFragment : Fragment() {
DaxColorAttributeListItem(
text = "Primary Text",
dotColors = DaxColorDotColors(
fillColor = DuckDuckGoTheme.textColors.primary,
fillColor = DuckDuckGoTheme.colors.text.primary,
strokeColor = DuckDuckGoTheme.colors.backgrounds.backgroundInverted,
),
)
Expand All @@ -162,7 +162,7 @@ class ColorPaletteFragment : Fragment() {
DaxColorAttributeListItem(
text = "Secondary Text",
dotColors = DaxColorDotColors(
fillColor = DuckDuckGoTheme.textColors.secondary,
fillColor = DuckDuckGoTheme.colors.text.secondary,
strokeColor = DuckDuckGoTheme.colors.backgrounds.backgroundInverted,
),
)
Expand All @@ -173,7 +173,7 @@ class ColorPaletteFragment : Fragment() {
DaxColorAttributeListItem(
text = "Text Disabled",
dotColors = DaxColorDotColors(
fillColor = DuckDuckGoTheme.textColors.disabled,
fillColor = DuckDuckGoTheme.colors.text.disabled,
strokeColor = DuckDuckGoTheme.colors.backgrounds.backgroundInverted,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.SheetState
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -41,9 +40,7 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import com.duckduckgo.common.ui.compose.text.DaxText
import com.duckduckgo.common.ui.compose.theme.DuckDuckGoTextStyle
import com.duckduckgo.common.ui.compose.theme.DuckDuckGoTheme
import com.duckduckgo.common.ui.compose.theme.asTextStyle
import com.duckduckgo.mobile.android.R

/**
Expand Down Expand Up @@ -110,11 +107,10 @@ private fun DaxActionTitleBottomSheetDialog(
contentColor: Color = DaxActionBottomSheetDefaults.contentColor,
style: TextStyle = DaxActionBottomSheetDefaults.style,
) {
val daxStyle = remember(style) { DuckDuckGoTextStyle(style) }
DaxText(
text = text,
color = contentColor,
style = daxStyle,
style = style,
modifier = modifier
.padding(DaxActionBottomSheetDefaults.sheetActionTitleContentPadding),
)
Expand All @@ -123,7 +119,7 @@ private fun DaxActionTitleBottomSheetDialog(
object DaxActionBottomSheetDefaults {
internal val style: TextStyle
@Composable
get() = DuckDuckGoTheme.typography.body1.asTextStyle
get() = DuckDuckGoTheme.typography.body1

internal val contentColor: Color
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@

package com.duckduckgo.common.ui.compose.text

import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.PreviewLightDark
import com.duckduckgo.common.ui.compose.theme.DuckDuckGoTextStyle
import com.duckduckgo.common.ui.compose.theme.DuckDuckGoTheme
import com.duckduckgo.common.ui.compose.theme.asTextStyle
import com.duckduckgo.common.ui.compose.tools.PreviewBox
import com.duckduckgo.common.ui.compose.tools.PreviewBoxInverted

/**
* Base text component for the DuckDuckGo design system.
*
* @param color The text color. Should use colors from [DuckDuckGoTheme.textColors] for consistency
* with the design system (e.g., [DuckDuckGoTheme.textColors.primary], [DuckDuckGoTheme.textColors.secondary]).
* @param color The text color. Should use colors from [DuckDuckGoTheme.colors.text] for consistency
* with the design system (e.g., [DuckDuckGoTheme.colors.text.primary], [DuckDuckGoTheme.colors.text.secondary]).
* A lint rule will warn if arbitrary colors are used.
*
* Asana Task: https://app.asana.com/1/137249556945/project/1202857801505092/task/1211634956773768
Expand All @@ -43,16 +45,17 @@ import com.duckduckgo.common.ui.compose.tools.PreviewBoxInverted
fun DaxText(
text: String,
modifier: Modifier = Modifier,
style: DuckDuckGoTextStyle = DuckDuckGoTheme.typography.body1,
color: Color = DuckDuckGoTheme.textColors.primary,
color: Color = Color.Unspecified,
style: TextStyle = LocalTextStyle.current,
textAlign: TextAlign? = null,
overflow: TextOverflow = TextOverflow.Ellipsis,
maxLines: Int = Int.MAX_VALUE,
) {
val textColor = color.takeOrElse { style.color.takeOrElse { LocalContentColor.current } }
Text(
text = text,
color = color,
style = style.asTextStyle,
color = textColor,
style = style,
textAlign = textAlign,
overflow = overflow,
maxLines = maxLines,
Expand Down Expand Up @@ -170,7 +173,7 @@ private fun DaxTextColorPrimaryPreview() {
PreviewBox {
DaxText(
text = "Primary Color",
color = DuckDuckGoTheme.textColors.primary,
color = DuckDuckGoTheme.colors.text.primary,
)
}
}
Expand All @@ -181,7 +184,7 @@ private fun DaxTextColorPrimaryInvertedPreview() {
PreviewBoxInverted {
DaxText(
text = "Primary Inverted",
color = DuckDuckGoTheme.textColors.primaryInverted,
color = DuckDuckGoTheme.colors.text.primaryInverted,
)
}
}
Expand All @@ -192,7 +195,7 @@ private fun DaxTextColorSecondaryPreview() {
PreviewBox {
DaxText(
text = "Secondary Color",
color = DuckDuckGoTheme.textColors.secondary,
color = DuckDuckGoTheme.colors.text.secondary,
)
}
}
Expand All @@ -203,7 +206,7 @@ private fun DaxTextColorSecondaryInvertedPreview() {
PreviewBoxInverted {
DaxText(
text = "Secondary Inverted",
color = DuckDuckGoTheme.textColors.secondaryInverted,
color = DuckDuckGoTheme.colors.text.secondaryInverted,
)
}
}
Expand All @@ -214,7 +217,7 @@ private fun DaxTextColorTertiaryPreview() {
PreviewBox {
DaxText(
text = "Tertiary Color",
color = DuckDuckGoTheme.textColors.tertiary,
color = DuckDuckGoTheme.colors.text.tertiary,
)
}
}
Expand All @@ -225,7 +228,7 @@ private fun DaxTextColorDisabledPreview() {
PreviewBox {
DaxText(
text = "Disabled Color",
color = DuckDuckGoTheme.textColors.disabled,
color = DuckDuckGoTheme.colors.text.disabled,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.sp
import com.duckduckgo.common.ui.compose.text.DaxText
import com.duckduckgo.common.ui.compose.theme.DuckDuckGoTheme
import com.duckduckgo.common.ui.compose.theme.asTextStyle
import com.duckduckgo.common.ui.compose.tools.PreviewBox
import com.duckduckgo.mobile.android.R

Expand Down Expand Up @@ -174,11 +173,11 @@ internal fun DaxSecureTextField(
// override is needed as TextField uses MaterialTheme.typography internally for animating the label text style
MaterialTheme(
typography = Typography(
bodySmall = DuckDuckGoTheme.typography.caption.asTextStyle.copy(
bodySmall = DuckDuckGoTheme.typography.caption.copy(
fontFamily = FontFamily.Default,
color = DuckDuckGoTheme.colors.text.secondary,
),
bodyLarge = DuckDuckGoTheme.typography.body1.asTextStyle.copy(
bodyLarge = DuckDuckGoTheme.typography.body1.copy(
fontFamily = FontFamily.Default,
color = DuckDuckGoTheme.colors.text.secondary,
),
Expand Down Expand Up @@ -221,8 +220,8 @@ internal fun DaxSecureTextField(
),
enabled = inputMode == DaxTextFieldInputMode.Editable || inputMode == DaxTextFieldInputMode.ReadOnly,
readOnly = inputMode == DaxTextFieldInputMode.ReadOnly || inputMode == DaxTextFieldInputMode.Disabled,
textStyle = DuckDuckGoTheme.typography.body1.asTextStyle.copy(
color = DuckDuckGoTheme.textColors.primary,
textStyle = DuckDuckGoTheme.typography.body1.copy(
color = DuckDuckGoTheme.colors.text.primary,
),
cursorBrush = SolidColor(daxTextFieldColors.cursorColor),
keyboardOptions = keyboardOptions,
Expand Down Expand Up @@ -260,7 +259,7 @@ internal fun DaxSecureTextField(
DaxText(
text = error,
style = DuckDuckGoTheme.typography.caption,
color = DuckDuckGoTheme.textColors.destructive,
color = DuckDuckGoTheme.colors.text.destructive,
)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import androidx.compose.ui.tooling.preview.PreviewLightDark
import com.duckduckgo.common.ui.compose.text.DaxText
import com.duckduckgo.common.ui.compose.theme.DuckDuckGoTheme
import com.duckduckgo.common.ui.compose.theme.Transparent
import com.duckduckgo.common.ui.compose.theme.asTextStyle
import com.duckduckgo.common.ui.compose.tools.PreviewBox
import com.duckduckgo.mobile.android.R

Expand Down Expand Up @@ -96,13 +95,13 @@ fun DaxTextField(
// override is needed as TextField uses MaterialTheme.typography internally for animating the label text style
MaterialTheme(
typography = Typography(
bodySmall = DuckDuckGoTheme.typography.caption.asTextStyle.copy(
bodySmall = DuckDuckGoTheme.typography.caption.copy(
fontFamily = FontFamily.Default,
color = DuckDuckGoTheme.textColors.secondary,
color = DuckDuckGoTheme.colors.text.secondary,
),
bodyLarge = DuckDuckGoTheme.typography.body1.asTextStyle.copy(
bodyLarge = DuckDuckGoTheme.typography.body1.copy(
fontFamily = FontFamily.Default,
color = DuckDuckGoTheme.textColors.secondary,
color = DuckDuckGoTheme.colors.text.secondary,
),
),
) {
Expand Down Expand Up @@ -142,7 +141,7 @@ fun DaxTextField(
null
},
labelPosition = TextFieldLabelPosition.Attached(),
textStyle = DuckDuckGoTheme.typography.body1.asTextStyle,
textStyle = DuckDuckGoTheme.typography.body1,
trailingIcon = trailingIcon?.let {
{
DaxTextFieldTrailingIconScope.it()
Expand All @@ -155,7 +154,7 @@ fun DaxTextField(
DaxText(
text = error,
style = DuckDuckGoTheme.typography.caption,
color = DuckDuckGoTheme.textColors.destructive,
color = DuckDuckGoTheme.colors.text.destructive,
)
}
} else {
Expand Down Expand Up @@ -246,7 +245,7 @@ object DaxTextFieldTrailingIconScope {
Icon(
painter = painter,
contentDescription = contentDescription,
tint = DuckDuckGoTheme.iconColors.primary,
tint = DuckDuckGoTheme.colors.icons.primary,
)
}
}
Expand Down Expand Up @@ -301,52 +300,52 @@ enum class DaxTextFieldInputMode {

@Composable
internal fun daxTextFieldColors(): TextFieldColors = OutlinedTextFieldDefaults.colors(
focusedTextColor = DuckDuckGoTheme.textColors.primary,
unfocusedTextColor = DuckDuckGoTheme.textColors.primary,
disabledTextColor = DuckDuckGoTheme.textColors.primary,
errorTextColor = DuckDuckGoTheme.textColors.primary,
focusedTextColor = DuckDuckGoTheme.colors.text.primary,
unfocusedTextColor = DuckDuckGoTheme.colors.text.primary,
disabledTextColor = DuckDuckGoTheme.colors.text.primary,
errorTextColor = DuckDuckGoTheme.colors.text.primary,
focusedContainerColor = Transparent,
unfocusedContainerColor = Transparent,
disabledContainerColor = Transparent,
errorContainerColor = Transparent,
focusedBorderColor = DuckDuckGoTheme.colors.brand.accentBlue,
unfocusedBorderColor = DuckDuckGoTheme.colors.textField.borders,
disabledBorderColor = DuckDuckGoTheme.colors.textField.borders,
errorBorderColor = DuckDuckGoTheme.textColors.destructive,
errorBorderColor = DuckDuckGoTheme.colors.text.destructive,
focusedLabelColor = DuckDuckGoTheme.colors.brand.accentBlue,
unfocusedLabelColor = DuckDuckGoTheme.textColors.secondary,
disabledLabelColor = DuckDuckGoTheme.textColors.secondary,
errorLabelColor = DuckDuckGoTheme.textColors.destructive,
focusedTrailingIconColor = DuckDuckGoTheme.iconColors.primary,
unfocusedTrailingIconColor = DuckDuckGoTheme.iconColors.primary,
disabledTrailingIconColor = DuckDuckGoTheme.iconColors.primary,
errorTrailingIconColor = DuckDuckGoTheme.textColors.destructive,
focusedSupportingTextColor = DuckDuckGoTheme.textColors.destructive,
unfocusedSupportingTextColor = DuckDuckGoTheme.textColors.destructive,
disabledSupportingTextColor = DuckDuckGoTheme.textColors.destructive,
errorSupportingTextColor = DuckDuckGoTheme.textColors.destructive,
unfocusedLabelColor = DuckDuckGoTheme.colors.text.secondary,
disabledLabelColor = DuckDuckGoTheme.colors.text.secondary,
errorLabelColor = DuckDuckGoTheme.colors.text.destructive,
focusedTrailingIconColor = DuckDuckGoTheme.colors.icons.primary,
unfocusedTrailingIconColor = DuckDuckGoTheme.colors.icons.primary,
disabledTrailingIconColor = DuckDuckGoTheme.colors.icons.primary,
errorTrailingIconColor = DuckDuckGoTheme.colors.text.destructive,
focusedSupportingTextColor = DuckDuckGoTheme.colors.text.destructive,
unfocusedSupportingTextColor = DuckDuckGoTheme.colors.text.destructive,
disabledSupportingTextColor = DuckDuckGoTheme.colors.text.destructive,
errorSupportingTextColor = DuckDuckGoTheme.colors.text.destructive,
cursorColor = DuckDuckGoTheme.colors.brand.accentBlue,
errorCursorColor = DuckDuckGoTheme.textColors.primary,
errorCursorColor = DuckDuckGoTheme.colors.text.primary,
selectionColors = TextSelectionColors(
handleColor = DuckDuckGoTheme.colors.brand.accentBlue,
backgroundColor = DuckDuckGoTheme.colors.brand.accentBlue.copy(alpha = DaxTextFieldDefaults.ALPHA_DISABLED),
),
focusedLeadingIconColor = DuckDuckGoTheme.iconColors.primary,
unfocusedLeadingIconColor = DuckDuckGoTheme.iconColors.primary,
disabledLeadingIconColor = DuckDuckGoTheme.iconColors.primary,
errorLeadingIconColor = DuckDuckGoTheme.textColors.destructive,
focusedPrefixColor = DuckDuckGoTheme.textColors.secondary,
unfocusedPrefixColor = DuckDuckGoTheme.textColors.secondary,
disabledPrefixColor = DuckDuckGoTheme.textColors.secondary,
errorPrefixColor = DuckDuckGoTheme.textColors.secondary,
focusedSuffixColor = DuckDuckGoTheme.textColors.secondary,
unfocusedSuffixColor = DuckDuckGoTheme.textColors.secondary,
disabledSuffixColor = DuckDuckGoTheme.textColors.secondary,
errorSuffixColor = DuckDuckGoTheme.textColors.secondary,
focusedPlaceholderColor = DuckDuckGoTheme.textColors.secondary,
unfocusedPlaceholderColor = DuckDuckGoTheme.textColors.secondary,
disabledPlaceholderColor = DuckDuckGoTheme.textColors.secondary,
errorPlaceholderColor = DuckDuckGoTheme.textColors.secondary,
focusedLeadingIconColor = DuckDuckGoTheme.colors.icons.primary,
unfocusedLeadingIconColor = DuckDuckGoTheme.colors.icons.primary,
disabledLeadingIconColor = DuckDuckGoTheme.colors.icons.primary,
errorLeadingIconColor = DuckDuckGoTheme.colors.text.destructive,
focusedPrefixColor = DuckDuckGoTheme.colors.text.secondary,
unfocusedPrefixColor = DuckDuckGoTheme.colors.text.secondary,
disabledPrefixColor = DuckDuckGoTheme.colors.text.secondary,
errorPrefixColor = DuckDuckGoTheme.colors.text.secondary,
focusedSuffixColor = DuckDuckGoTheme.colors.text.secondary,
unfocusedSuffixColor = DuckDuckGoTheme.colors.text.secondary,
disabledSuffixColor = DuckDuckGoTheme.colors.text.secondary,
errorSuffixColor = DuckDuckGoTheme.colors.text.secondary,
focusedPlaceholderColor = DuckDuckGoTheme.colors.text.secondary,
unfocusedPlaceholderColor = DuckDuckGoTheme.colors.text.secondary,
disabledPlaceholderColor = DuckDuckGoTheme.colors.text.secondary,
errorPlaceholderColor = DuckDuckGoTheme.colors.text.secondary,
)

@PreviewLightDark
Expand Down
Loading
Loading