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
[Compound] Platform components (Lists) #990
Conversation
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
5bc8a91
to
1372a89
Compare
455f865
to
3b65803
Compare
Codecov ReportPatch coverage:
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
☔ View full report in Codecov by Sentry. |
…ak screenshots naming
14fa08a
to
0706c98
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 = { }, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 53ebf11.
There was a problem hiding this 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 = { }, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?: {}) |
There was a problem hiding this comment.
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 ?: {})
There was a problem hiding this comment.
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.
I'll actually remove the |
Kudos, SonarCloud Quality Gate passed! |
Changes
Creates
ListItem
,ListSectionHeader
andListSupportingText
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