-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
DataViews: Support defining field headers/names as React elements. #64642
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
5b2a41a
to
44f2e57
Compare
Size Change: +29 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
Flaky tests detected in 44f2e57. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10470876482
|
Is it possible to pass the icon to the underlying If not then let's reduce the spacing on the |
|
* The header of the field. Defaults to the label. | ||
* It allows the usage of a React Element to render the field labels. | ||
*/ | ||
header?: string | ReactElement; |
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.
Can we make this a ReactElement and remove the string type? Otherwise, why would you use the header as string if there's already the label
field.
Unless you want to enable they being different, which I don't think is the intentionality here.
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.
It's just because in the NormalizedField
type we fallback to the label to avoid having to do the fallback everywhere. But in Field
it can indeed be just ReactElement
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.
To enforce the ReactElement type, when we normalize the field, can't we provide a function that returns the field.label if field.header is not present?
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.
To enforce the ReactElement type, when we normalize the field, can't we provide a function that returns the field.label if field.header is not present?
Feels more complex to me, especially since string and React element can both be considered "React Element" I wonder if there's a dedicated type for that.
9df5407
to
2de9530
Compare
…ordPress#64642) Co-authored-by: youknowriad <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: jameskoster <[email protected]>
Related #55083
What?
While trying to implement dataviews in a third-party project, we had a use-case where we wanted to add an icon and some colors to the table headers.
I think this use-case is common enough that it deserves to be supported in the DataViews component.
How?
In a few places (like filters), we rely on a the label being a string (for instance to render a filter summary), so I think it makes more sense to have two properties here instead of one.
Testing Instructions
I've added an example to the storybook like shown in the image bellow.
Screenshots or screencast