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

Exposes <TableCell> so users have more control over table markups #74

Merged
merged 7 commits into from
Jul 5, 2022

Conversation

brunobasto
Copy link
Contributor

@brunobasto brunobasto commented Jul 5, 2022

Description

Right now users don't have much control over the markup of the <td> on a table. This PR allows them to build tables with more granular control. Like this:

<TableRow>
    <TableCell sx={ { backgroundColor: 'gray' } }>
        simon
    </TableCell>
</TableRow>

Note that we can now specify styles for the <td> or <th> which we couldn't do before. One use case is on the Dashboard: I want the first column to have a specific width since it only contains a thumbnail.

Before

before_table

After

after_table

Checklist

  • This PR has good automated test coverage
  • The storybook for the component has been updated

Steps to Test

  1. Pull down PR.
  2. npm run dev.
  3. Open Storybook.
  4. Go to the Table component
  5. Verify there's a custom <td> with its own background

@netlify
Copy link

netlify bot commented Jul 5, 2022

Deploy Preview for vip-design-system-components ready!

Name Link
🔨 Latest commit e5e8784
🔍 Latest deploy log https://app.netlify.com/sites/vip-design-system-components/deploys/62c49da46c3a17000967cd2a
😎 Deploy Preview https://deploy-preview-74--vip-design-system-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@brunobasto brunobasto changed the title Exposes <TableCell> so users have more control over the markup Exposes <TableCell> so users have more control over tables markup Jul 5, 2022
@brunobasto brunobasto changed the title Exposes <TableCell> so users have more control over tables markup Exposes <TableCell> so users have more control over table markups Jul 5, 2022
const TableCell = ( { head, isRowHead, children, ...rest } ) => {
let scope = null;

if ( head ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@brunobasto unrelated to this PR but I find the "head/isRowHead" a little bit confusing. Even by looking at the code I always wonder what they are used for.

I'm sure renaming them might not be the case now but I was wondering if we could add some extra example in the stories to clarify the use of the parameters

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 agree it's confusing. I'll play with the storybook and add some examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, essentially, head and isRowHead control two things:

  1. Whether to render the columns as <td> or <th>. If either is true, the column will render as <th>
  2. The scope of the column header:

The scope attribute specifies whether a header cell is a header for a column, row, or group of columns or rows.

Note: The scope attribute has no visual effect in ordinary web browsers, but can be used by screen readers.

https://www.w3schools.com/tags/att_th_scope.asp

I searched in vip-ui and couldn't find any usages of rowHead or isRowHead, so, for the sake of simplicity in the API, I removed isRowHead and, since we pass forward the props, if someone ever needs to control the scope for accessibility purposes, they can do:

<TableCell head scope="row">...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the prop I removed was unused (so it shouldn't impact the Dashboard) and the PR is already approved, I'll be bold and move forward with merging this, but we can add it back quickly if we need to.

@@ -56,7 +56,7 @@ const Time = ( { time, relativeTime = false, timeOnly = false, className = null,
};

Time.propTypes = {
time: PropTypes.oneOfType( [ PropTypes.string, PropTypes.date ] ),
time: PropTypes.oneOfType( [ PropTypes.string, PropTypes.instanceOf( Date ) ] ),
Copy link
Contributor

Choose a reason for hiding this comment

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

@brunobasto didn't see it mentioned in the PR, is it a leftover or not? (I believe the new code is correct so I don't consider this an issue, just wondering)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, forgot to mention on the PR description, but mentioned on the commit message:

(5603609)

Fix invalid PropType error:

`Warning: Invalid argument supplied to oneOfType. Expected an array of check functions, but received undefined at index 1.`

Noticed this error when running tests.

Copy link
Contributor

@andrea-sdl andrea-sdl left a comment

Choose a reason for hiding this comment

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

LGTM, tested and it works 🚢

Only a couple of improvements which are optional left as comments

brunobasto and others added 2 commits July 5, 2022 16:38
…ise an A11Y violation in the storybook

Co-authored-by: Andrea Grassi <andrea-sdl@users.noreply.github.com>
Users can control the scope directly when using <TableCell />
@brunobasto brunobasto merged commit acd3e12 into trunk Jul 5, 2022
@brunobasto brunobasto deleted the fix/table-cell branch July 5, 2022 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants