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

width attribute for EuiTable cell components #2452

Merged
merged 4 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ exports[`EuiInMemoryTable behavior pagination 1`] = `
data-test-subj="tableHeaderCell_name_0"
role="columnheader"
scope="col"
style={
Object {
"width": undefined,
}
}
>
<div
className="euiTableCellContent"
Expand Down Expand Up @@ -192,6 +197,11 @@ exports[`EuiInMemoryTable behavior pagination 1`] = `
>
<td
className="euiTableRowCell"
style={
Object {
"width": undefined,
}
}
>
<div
className="euiTableRowCell__mobileHeader euiTableRowCell--hideForDesktop"
Expand Down Expand Up @@ -230,6 +240,11 @@ exports[`EuiInMemoryTable behavior pagination 1`] = `
>
<td
className="euiTableRowCell"
style={
Object {
"width": undefined,
}
}
>
<div
className="euiTableRowCell__mobileHeader euiTableRowCell--hideForDesktop"
Expand Down
68 changes: 68 additions & 0 deletions src/components/table/__snapshots__/table_footer_cell.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,71 @@ exports[`EuiTableFooterCell is rendered 1`] = `
</div>
</td>
`;

exports[`EuiTableFooterCell width and style accepts style attribute 1`] = `
<td
class="euiTableFooterCell"
style="width:20%"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</td>
`;

exports[`EuiTableFooterCell width and style accepts width attribute 1`] = `
<td
class="euiTableFooterCell"
style="width:10%"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</td>
`;

exports[`EuiTableFooterCell width and style accepts width attribute as number 1`] = `
<td
class="euiTableFooterCell"
style="width:100px"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</td>
`;

exports[`EuiTableFooterCell width and style resolves style and width attribute 1`] = `
<td
class="euiTableFooterCell"
style="width:10%"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</td>
`;
76 changes: 76 additions & 0 deletions src/components/table/__snapshots__/table_header_cell.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,79 @@ exports[`renders EuiTableHeaderCell 1`] = `
</div>
</th>
`;

exports[`width and style accepts style attribute 1`] = `
<th
class="euiTableHeaderCell"
role="columnheader"
scope="col"
style="width:20%"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</th>
`;

exports[`width and style accepts width attribute 1`] = `
<th
class="euiTableHeaderCell"
role="columnheader"
scope="col"
style="width:10%"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</th>
`;

exports[`width and style accepts width attribute as number 1`] = `
<th
class="euiTableHeaderCell"
role="columnheader"
scope="col"
style="width:100px"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</th>
`;

exports[`width and style resolves style and width attribute 1`] = `
<th
class="euiTableHeaderCell"
role="columnheader"
scope="col"
style="width:10%"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</th>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,59 @@ exports[`EuiTableHeaderCellCheckbox is rendered 1`] = `
/>
</th>
`;

exports[`EuiTableHeaderCellCheckbox width and style accepts style attribute 1`] = `
<th
class="euiTableHeaderCellCheckbox"
scope="col"
style="width:20%"
>
<div
class="euiTableCellContent"
>
Test
</div>
</th>
`;

exports[`EuiTableHeaderCellCheckbox width and style accepts width attribute 1`] = `
<th
class="euiTableHeaderCellCheckbox"
scope="col"
style="width:10%"
>
<div
class="euiTableCellContent"
>
Test
</div>
</th>
`;

exports[`EuiTableHeaderCellCheckbox width and style accepts width attribute as number 1`] = `
<th
class="euiTableHeaderCellCheckbox"
scope="col"
style="width:100px"
>
<div
class="euiTableCellContent"
>
Test
</div>
</th>
`;

exports[`EuiTableHeaderCellCheckbox width and style resolves style and width attribute 1`] = `
<th
class="euiTableHeaderCellCheckbox"
scope="col"
style="width:10%"
>
<div
class="euiTableCellContent"
>
Test
</div>
</th>
`;
68 changes: 68 additions & 0 deletions src/components/table/__snapshots__/table_row_cell.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,71 @@ exports[`truncateText is rendered when specified 1`] = `
</div>
</td>
`;

exports[`width and style accepts style attribute 1`] = `
<td
class="euiTableRowCell"
style="width:20%"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</td>
`;

exports[`width and style accepts width attribute 1`] = `
<td
class="euiTableRowCell"
style="width:10%"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</td>
`;

exports[`width and style accepts width attribute as number 1`] = `
<td
class="euiTableRowCell"
style="width:100px"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</td>
`;

exports[`width and style resolves style and width attribute 1`] = `
<td
class="euiTableRowCell"
style="width:10%"
>
<div
class="euiTableCellContent"
>
<span
class="euiTableCellContent__text"
>
Test
</span>
</div>
</td>
`;
36 changes: 36 additions & 0 deletions src/components/table/table_footer_cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,40 @@ describe('EuiTableFooterCell', () => {
expect(render(component)).toMatchSnapshot();
});
});

describe('width and style', () => {
test('accepts style attribute', () => {
const component = (
<EuiTableFooterCell style={{ width: '20%' }}>Test</EuiTableFooterCell>
);

expect(render(component)).toMatchSnapshot();
});

test('accepts width attribute', () => {
const component = (
<EuiTableFooterCell width="10%">Test</EuiTableFooterCell>
);

expect(render(component)).toMatchSnapshot();
});

test('accepts width attribute as number', () => {
const component = (
<EuiTableFooterCell width={100}>Test</EuiTableFooterCell>
);

expect(render(component)).toMatchSnapshot();
});

test('resolves style and width attribute', () => {
const component = (
<EuiTableFooterCell width="10%" style={{ width: '20%' }}>
Test
</EuiTableFooterCell>
);

expect(render(component)).toMatchSnapshot();
});
});
});
9 changes: 7 additions & 2 deletions src/components/table/table_footer_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,31 @@ import {
CENTER_ALIGNMENT,
} from '../../services';

import { resolveWidthAsStyle } from './utils';

type Props = CommonProps &
TdHTMLAttributes<HTMLTableCellElement> & {
align?: HorizontalAlignment;
width?: string | number;
};

export const EuiTableFooterCell: FunctionComponent<Props> = ({
children,
align = LEFT_ALIGNMENT,
colSpan,
className,
width,
style,
...rest
}) => {
const classes = classNames('euiTableFooterCell', className);
const contentClasses = classNames('euiTableCellContent', className, {
'euiTableCellContent--alignRight': align === RIGHT_ALIGNMENT,
'euiTableCellContent--alignCenter': align === CENTER_ALIGNMENT,
});
const styleObj = resolveWidthAsStyle(style, width);

return (
<td className={classes} colSpan={colSpan} {...rest}>
<td className={classes} style={styleObj} {...rest}>
<div className={contentClasses}>
<span className="euiTableCellContent__text">{children}</span>
</div>
Expand Down
Loading