Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create button component #213

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from

Conversation

florentmaitre
Copy link
Member

Note: Please transform - [ ] into - (NA) in the description when things are not applicable

Related issues

Description

Motivation & Context

Types of change

  • Bug fix (non-breaking which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would change existing functionality)

Previews

Checklist

Contribution

Accessibility

  • My change follows accessibility good practices

Design

  • My change respects the design guidelines of Orange Unified Design System

Development

  • My change follows the developer guide
  • I have added unit tests to cover my changes (optional)

Documentation

  • My change introduces changes to the documentation and/or I have updated the documentation accordingly

Checklist (for Core Team only)

  • Manually test (dark mode, RTL, landscape display, tablet)
  • Documentation has been updated if relevant
  • Design review
  • A11y review
  • Internal files have been updated if relevant (THIRD_PARTY, NOTICE)
  • changelog.md has been updated respecting keep a changelog rules and referencing the issue

Copy link

github-actions bot commented Nov 28, 2024

@florentmaitre florentmaitre marked this pull request as ready for review November 29, 2024 17:12
@OptIn(ExperimentalMaterial3Api::class)
private fun OudsButton(
nullableIcon: OudsButton.Icon?,
nullableText: String?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As seen together, replace nullableIcon and nullableText respectively by icon and text and remove previewState default value to avoid similar signatures issue.

.widthIn(min = buttonTokens.sizeMinWidth.dp)
.heightIn(min = buttonTokens.sizeMinHeight.dp, max = maxHeight)
.border(hierarchy = hierarchy, state = state, shape = shape),
enabled = state != OudsButton.State.Disabled && state != OudsButton.State.Loading && state != OudsButton.State.Skeleton,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about writing this like that:

 state !in listOf(OudsButton.State.Disabled, OudsButton.State.Loading, OudsButton.State.Skeleton)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added remember to avoid instanciating the list on each recomposition.

OudsButton.State.Loading,
OudsButton.State.Focused -> OudsColorKeyToken.Content.OnAction.Negative
OudsButton.State.Disabled -> OudsColorKeyToken.Content.OnAction.Disabled
OudsButton.State.Skeleton -> OudsColorKeyToken.Gradient.Skeleton.StartEnd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always use OudsColorKeyToken.Gradient.Skeleton.StartEnd for Skeleton state, maybe we can factorize it as a skeleton color for OudsButton?

OudsButton.State.Pressed -> colorContentDefaultPressed
OudsButton.State.Loading -> colorContentDefaultLoading
OudsButton.State.Disabled -> colorContentDefaultDisabled
OudsButton.State.Skeleton -> OudsColorKeyToken.Gradient.Skeleton.StartEnd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By changing the text color of the button when it is in skeleton state, Talkback will probably read the text. Is this what we want in term of a11y?

*/
@Composable
fun OudsButton(
icon: OudsButton.Icon,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We maybe need a contentDescription parameter for this kind of button (icon only) to handle a11y or something else.

import androidx.compose.ui.graphics.Color

@Composable
internal fun Color.enabled(enabled: Boolean) = if (enabled) this else copy(alpha = 0.38f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not wrong, this alpha value is not defined anywhere in tokens.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value comes from Material. You are right, we should remove it.

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

internal object OudsIconDefaults {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we have OudsIconDefaults in a separate file, same thing for OudsIconButtonDefaults but this is not the case for OudsButtonDefault. What do you think about creating an OudsButtonDefaults for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, this is not consistent. What about moving the defaults into the original file? This is was is done in Material.

OudsButton.State.Pressed -> OudsColorKeyToken.Action.Negative.Pressed
OudsButton.State.Loading -> OudsColorKeyToken.Action.Negative.Loading
OudsButton.State.Disabled -> OudsColorKeyToken.Action.Disabled
OudsButton.State.Skeleton -> OudsColorKeyToken.Gradient.Skeleton.StartEnd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that semantic tokens are not up-to-date because the negative button in dark mode is not similar to the one on Figma. I took a look and OudsColorKeyToken.Action.Negative.Enabled value is similar in light and dark (scarlet600).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, hopefully this will be fixed by next Tokenator update.

color = borderColor,
shape = shape,
insetWidth = OudsBorderKeyToken.Width.Focus.Inset.value,
insetColor = OudsColorKeyToken.Border.Focus.Inset.value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result in Hierarchy.Default and State.Hovered is not correct, a border is missing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't fix it right now because a token is missing, this token will probably be added in next Tokenator update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well in fact this is a button token, so I can add it manually.

Comment on lines 108 to 109
* @param width The width of the border inset in dp. Use [Dp.Hairline] for a hairline border inset.
* @param color The color to paint the border inset with.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param width The width of the border inset in dp. Use [Dp.Hairline] for a hairline border inset.
* @param color The color to paint the border inset with.
* @param insetWidth The width of the border inset in dp. Use [Dp.Hairline] for a hairline border inset.
* @param insetColor The color to paint the border inset with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create component - Button
2 participants