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

Add tableLayout prop to EuiTable, EuiBasicTable and EuiInMemoryTable #2697

Merged
merged 13 commits into from
Dec 20, 2019

Conversation

andreadelrio
Copy link
Contributor

Summary

This PR adds the tableLayout prop to EuiTable which in turns makes it available in EuiBasicTable and EuiInMemoryTable. The default value is fixed with the option to change it to auto.

I thought it'd be good to add a small example to the docs to show the new prop in action.

table-auto

Fixes #461

Checklist

- [ ] Check against all themes for compatability in both light and dark modes
- [ ] Checked in mobile

  • Checked in IE11 and Firefox
  • Props have proper autodocs
  • Added documentation examples
  • Added or updated jest tests
    - [ ] Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Design wise it mostly looks good, though it seems that truncation doesn't work in auto-layout. Maybe that's ok or expected. But perhaps you could do a quick look into a possible fix?

Screen Shot 2019-12-18 at 16 09 15 PM

} & CommonProps &
TableHTMLAttributes<HTMLTableElement>;

const tableLayoutToClassMap: { [tableLayout: string]: string | null } = {
fixed: 'euiTable--fixed',
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're not actually using this class in the CSS, but the default .euiTable class gets the fixed layout and you're just overriding this with the auto class, you should just set this to null.

Suggested change
fixed: 'euiTable--fixed',
fixed: null,

@@ -5,20 +5,32 @@ import { CommonProps } from '../common';
export type Props = {
compressed?: boolean;
responsive?: boolean;
tableLayout?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

All new props in TS need a comment explaining what it is. This helps consumers via their IDE's auto-complete. Probably just duplicate what was written in the props_info file.

&.euiTable--auto {
table-layout: auto;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, extra space here

src/components/basic_table/basic_table.tsx Outdated Show resolved Hide resolved
return (
<div>
<EuiSwitch
label="Show auto layout"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
label="Show auto layout"
label="Auto layout"

<div>
<p>
<EuiCode>EuiBasicTable</EuiCode> has a fixed layout by default. You can
change it to auto using the <EuiCode>tableLayout</EuiCode> prop.
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this description isn't enough to warrant an entire example in the docs? Consider beefing up this explanation or removing the example and just relying on props comments to explain the prop.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree that a props comment is likely enough and this concept doesn't need a full example. Only alternative (which should be handled in a separate PR) would be to do something similar to EuiDataGrid where we devote a full section to styling concerns and add an example with lots of toggles.

Copy link
Contributor

Choose a reason for hiding this comment

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

That was going to be my third suggestion, but figured it out of scope of this PR. So probably best to just remove this example for now.

@@ -95,6 +95,14 @@ export const propsInfo = {
required: false,
type: { name: '(criteria: #Criteria) => void' },
},
tableLayout: {
description: 'Configures table layout',
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably want to explain that it's configuring the CSS table-layout property.

@andreadelrio
Copy link
Contributor Author

Design wise it mostly looks good, though it seems that truncation doesn't work in auto-layout. Maybe that's ok or expected. But perhaps you could do a quick look into a possible fix?

Screen Shot 2019-12-18 at 16 09 15 PM

@cchaos With this I find myself in a loop: to truncate text we would need to set the cell width which would defeat the purpose of setting layout to auto in the first place? Is there any other way to look at it?

I think that when the consumer wants some columns wider than others while still being able to use truncateText they should set the width themselves. So we'd have these three scenarios

Auto layout (truncateText stops working)
image

Fixed layout (truncateText works)
image

Fixed layout with First name at 20% width (truncateText works)
image

If we stick with this, I would add a note in the docs that auto layout overrides truncateText.

@cchaos
Copy link
Contributor

cchaos commented Dec 19, 2019

If we stick with this, I would add a note in the docs that auto layout overrides truncateText.

I would do that, though it doesn't technically "override" truncateText, but it does inhibit it from calculating the other columns properly. This would then also warrant keeping the docs example so you can also add in this width to your example.

@andreadelrio
Copy link
Contributor Author

If we stick with this, I would add a note in the docs that auto layout overrides truncateText.

I would do that, though it doesn't technically "override" truncateText, but it does inhibit it from calculating the other columns properly. This would then also warrant keeping the docs example so you can also add in this width to your example.

@cchaos I've updated the example to look like this. Let me know what you think

table-auto_new

@thompsongl
Copy link
Contributor

PR to simplify TypeScript type definitions and extensions: andreadelrio#5

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

Code changes LGTM!

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Looks good, just had a couple more suggestions for the doc example

@@ -95,6 +95,15 @@ export const propsInfo = {
required: false,
type: { name: '(criteria: #Criteria) => void' },
},
tableLayout: {
description:
'Sets the table-layout CSS property. Note that auto tableLayout prevents truncateText from working regularly.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'Sets the table-layout CSS property. Note that auto tableLayout prevents truncateText from working regularly.',
'Sets the table-layout CSS property. Note that auto tableLayout prevents truncateText from working properly.',

const html = renderToHtml(Table);

export const section = {
title: 'A BasicTable with auto layout',
Copy link
Contributor

Choose a reason for hiding this comment

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

This section is no longer about just auto layout but layout in general

Suggested change
title: 'A BasicTable with auto layout',
title: 'Table layout',

src-docs/src/views/tables/tables_example.js Outdated Show resolved Hide resolved
src-docs/src/views/tables/auto/auto.js Show resolved Hide resolved
src-docs/src/views/tables/auto/auto.js Outdated Show resolved Hide resolved
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Looks great! I think this PR satisfies the issue but pushes towards a better solution (using widths) in the docs.

@andreadelrio andreadelrio merged commit e1a7c10 into elastic:master Dec 20, 2019
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.

Allow to set a different table-layout
4 participants