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

[Compound] Platform components (Lists) #990

Merged
merged 21 commits into from Aug 21, 2023

Conversation

jmartinesp
Copy link
Contributor

@jmartinesp jmartinesp commented Jul 27, 2023

Changes

Creates ListItem, ListSectionHeader and ListSupportingText composables. These new components will replace our current list items in a new PR, since this one is already large enough.

Why

Closes element-hq/compound#169

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2023

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/QFcJi1

@jmartinesp jmartinesp force-pushed the chore/jme/compound-platform-components-listitem branch 6 times, most recently from 5bc8a91 to 1372a89 Compare July 31, 2023 13:52
@jmartinesp jmartinesp force-pushed the chore/jme/compound-platform-components-listitem branch 2 times, most recently from 455f865 to 3b65803 Compare August 18, 2023 12:59
@codecov
Copy link

codecov bot commented Aug 18, 2023

Codecov Report

Patch coverage: 64.60% and project coverage change: +0.05% 🎉

Comparison is base (6a4a4eb) 57.00% compared to head (1c714ab) 57.05%.
Report is 30 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #990      +/-   ##
===========================================
+ Coverage    57.00%   57.05%   +0.05%     
===========================================
  Files         1017     1019       +2     
  Lines        25822    26000     +178     
  Branches      5182     5262      +80     
===========================================
+ Hits         14720    14835     +115     
- Misses        8829     8862      +33     
- Partials      2273     2303      +30     
Files Changed Coverage Δ
...oid/libraries/designsystem/preview/PreviewGroup.kt 0.00% <ø> (ø)
...ibraries/designsystem/theme/components/ListItem.kt 62.93% <62.93%> (ø)
...aries/designsystem/theme/components/ListSection.kt 67.74% <67.74%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jmartinesp jmartinesp marked this pull request as ready for review August 18, 2023 13:41
@jmartinesp jmartinesp requested a review from a team as a code owner August 18, 2023 13:41
@jmartinesp jmartinesp requested review from julioromano and removed request for a team August 18, 2023 13:41
@jmartinesp jmartinesp force-pushed the chore/jme/compound-platform-components-listitem branch from 14fa08a to 0706c98 Compare August 18, 2023 13:54
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

LGTM, 2 minor remarks.

}
val leadingContentColor = when {
isPrimaryAction -> ElementTheme.colors.iconPrimary
isDestructive -> ElementTheme.colors.iconCriticalPrimary
Copy link
Member

Choose a reason for hiding this comment

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

Maybe test isDestructive first?

After thinking about it, I understand that parameters isPrimaryAction and isDestructive are probably exclusive (i.e. they cannot be both equal to true), but maybe enforce this by introducing an enum instead? If I am wrong, maybe add a preview with both parameter to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I implemented a style parameter to handle this in an enum way. Thanks!

isPrimaryAction: Boolean = false,
isDestructive: Boolean = false,
enabled: Boolean = true,
onClick: () -> Unit = { },
Copy link
Member

Choose a reason for hiding this comment

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

There is always a pb with having a default empty lambda, which is when the lambda stays empty, the click effect is still visible (since we invoke modifier.clickable(enabled = enabled, onClick = onClick) below). I think we may have ListItem with no click action, but if not, maybe remove the default parameter value. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, if onClick is optional it must be nullable defaulting to null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 53ebf11.

- Switch `isPrimary` and `isDestructive` for a `style` sealed interface.
- Made `onClick` nullable so there can be non-clickable list items.
- Added `isCompact` parameter for customising the padding values.
- Removed unnecessary parameters.
Copy link
Contributor

@julioromano julioromano left a comment

Choose a reason for hiding this comment

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

Some API improvements suggestions

isPrimaryAction: Boolean = false,
isDestructive: Boolean = false,
enabled: Boolean = true,
onClick: () -> Unit = { },
Copy link
Contributor

Choose a reason for hiding this comment

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

+1, if onClick is optional it must be nullable defaulting to null.

fun ListItem(
headlineContent: @Composable () -> Unit,
modifier: Modifier = Modifier,
overlineContent: @Composable (() -> Unit)? = null,
Copy link
Contributor

Choose a reason for hiding this comment

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

overlineContent seems unused, there's not even a preview of it and it's not in the figma. Perhaps we should think of removing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 53ebf11

* @param enabled Whether the list item is enabled. When disabled, will change the color of the headline content and the leading content to use disabled tokens.
* @param onClick The callback to be called when the list item is clicked.
*
* **Note:** [isPrimaryAction], [isDestructive] and [enabled] should only be used in single line [ListItem] components,
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no notion of "single line ListItem" as of yet. So this doc line leaves a lot to the dev's interpretation.

Perhaps we should remove isPrimaryAction and isDestructive from here, create another composable which only has a single line of content and also an enum param which is something like "StandardAction, PrimaryAction, DesctructiveAction".
This new composable could still be called ListItem (because the param list will be a lot different) or it could be called SingleLineListItem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this sounds better than what was implemented on 53ebf11.

I still need to create a couple of PRs to replace usages of ListItems through the app and add Lists to dialogs. Do you mind if I add this change in one of this other PRs, or even a dedicated one for it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a problem, but we can also leave it as is if it's not a problem to use "destructive" or "primary" style when there is also a supporting content.


val setUpModifier = modifier
.then(if (isCompact) Modifier else Modifier.padding(vertical = 4.dp))
.clickable(enabled = onClick != null, onClick = onClick ?: {})
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also take into account the enabled parameter? I do not know if we want to have a disabled ListItem still clickable. Maybe...

.clickable(enabled = enabled && onClick != null, onClick = onClick ?: {})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right. It depends on the implementation, but here enabled is up to us to apply, so it should be taken into account.

@jmartinesp
Copy link
Contributor Author

I'll actually remove the isCompact parameter since it's not working as expected. Even when applied, the minHeight for the ListItem will always be 56.dp, while the Figma designs expects it to be 48.dp, which is not possible AFAICT.

@sonarcloud
Copy link

sonarcloud bot commented Aug 21, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@jmartinesp jmartinesp merged commit 0f77b45 into develop Aug 21, 2023
15 checks passed
@jmartinesp jmartinesp deleted the chore/jme/compound-platform-components-listitem branch August 21, 2023 08:34
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.

Implement ListItem and sections on Android
4 participants