Skip to content

Commit

Permalink
[UI Framework] [K7] Add KuiTable component. (elastic#13249)
Browse files Browse the repository at this point in the history
* Add KuiTable component with compressed prop.
  • Loading branch information
cjcenizal committed Aug 16, 2017
1 parent 5ffa7ca commit 52f345b
Show file tree
Hide file tree
Showing 29 changed files with 1,015 additions and 9 deletions.
79 changes: 78 additions & 1 deletion ui_framework/dist/ui_framework.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ time, mark, audio, video {
border: 0;
font: inherit;
/* 1 */
font-size: 16px;
font-family: inherit;
/* 1 */
vertical-align: baseline; }

em {
font-style: italic; }

strong {
font-weight: 500; }

/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
Expand All @@ -54,6 +59,7 @@ footer, header, hgroup, menu, nav, section {
html {
font-family: "Roboto", Helvetica, Arial, sans-serif;
font-weight: 400;
font-size: 16px;
color: #3F3F3F;
height: 100%;
-webkit-font-smoothing: antialiased; }
Expand Down Expand Up @@ -926,6 +932,77 @@ table {
right: 16px;
left: auto; }

/**
* 1. Prevent cells from expanding based on content size. This substitutes for table-layout: fixed.
*/
/**
* NOTE: table-layout: fixed causes a bug in IE11 and Edge (see #9929). It also prevents us from
* specifying a column width, e.g. the checkbox column.
*/
.kuiTable {
font-size: 14px;
font-size: 0.875rem;
line-height: 18px;
width: 100%;
border: none;
border-collapse: collapse;
background-color: #FFF; }

.kuiTable--compressed .kuiTableHeaderCell,
.kuiTable--compressed .kuiTableRowCell__content {
padding: 8px; }

.kuiTableHeaderCell {
text-align: left;
max-width: 20px;
/* 1 */
padding: 12px;
color: #000; }

.kuiTableHeaderCell__content {
display: inline-block; }

.kuiTableHeaderCell--alignRight {
text-align: right; }

.kuiTableRow:hover {
background-color: rgba(0, 121, 165, 0.05); }

.kuiTableRow.kuiTableRow-isSelected {
background-color: rgba(255, 255, 0, 0.05); }

.kuiTableRowCell {
text-align: left;
max-width: 20px;
/* 1 */
color: #3F3F3F;
border-top: 1px solid #D9D9D9;
border-bottom: 1px solid #D9D9D9; }

/**
* 1. Vertically align all children.
* 2. Truncate text with an ellipsis. The padding on this div allows the ellipsis to show. If
* the padding was on the cell, the ellipsis would be cropped.
*/
.kuiTableRowCell__content {
white-space: nowrap;
/* 2 */
overflow: hidden;
/* 2 */
text-overflow: ellipsis;
/* 2 */
padding: 12px;
/* 2 */ }
.kuiTableRowCell__content > * {
vertical-align: middle;
/* 1 */ }

.kuiTableRowCell--alignRight .kuiTableRowCell__content {
text-align: right; }

.kuiTableRowCell--wrapText .kuiTableRowCell__content {
white-space: normal; }

.kuiTitle {
font-size: 24px;
font-size: 1.5rem;
Expand Down
8 changes: 7 additions & 1 deletion ui_framework/doc_site/src/services/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import PageExample
import PopoverExample
from '../../views/popover/popover_example';

import TableExample
from '../../views/table/table_example';

import TypographyExample
from '../../views/typography/typography_example';


// Component route names should match the component name exactly.
const components = [{
name: 'Accessibility',
Expand Down Expand Up @@ -64,6 +66,10 @@ const components = [{
name: 'Popover',
component: PopoverExample,
hasReact: true,
}, {
name: 'Table',
component: TableExample,
hasReact: true,
}, {
name: 'Typography',
component: TypographyExample,
Expand Down
134 changes: 134 additions & 0 deletions ui_framework/doc_site/src/views/table/compressed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import React, {
Component,
} from 'react';

import {
KuiIcon,
KuiTable,
KuiTableRow,
KuiTableRowCell,
KuiTableHeaderCell,
KuiTableBody,
KuiTableHeader,
} from '../../../../components';

import {
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
} from '../../../../services';

export class Compressed extends Component {
constructor(props) {
super(props);
this.state = {
rowIndexToSelectedMap: {
2: true,
},
};

this.rows = [{
children: [
<span>A very long line which will not wrap on narrower screens and instead will become truncated and replaced by an ellipsis</span>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>1</span>,
],
}, {
children: [
<span>A very long line which will wrap on narrower screens and <em>not</em> become truncated and replaced by an ellipsis</span>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>1</span>,
],
wrapText: true,
}, {
children: [
<a className="kuiLink" href="#">Boomerang</a>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>10</span>,
],
isSelected: true,
}, {
children: [
<a className="kuiLink" href="#">Celebration</a>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>100</span>,
],
}, {
children: [
<a className="kuiLink" href="#">Dog</a>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>1000</span>,
],
}];

this.columns = [{
label: 'Title',
alignment: LEFT_ALIGNMENT,
}, {
label: 'Type',
alignment: LEFT_ALIGNMENT,
width: '60px',
}, {
label: 'Date created',
alignment: LEFT_ALIGNMENT,
}, {
label: 'Orders of magnitude',
alignment: RIGHT_ALIGNMENT,
}];
}

renderHeaderCells() {
return this.columns.map((column, columnIndex) => (
<KuiTableHeaderCell
key={columnIndex}
align={this.columns[columnIndex].alignment}
width={column.width}
>
{column.label}
</KuiTableHeaderCell>
));
}

renderTableRows() {
return this.rows.map((row, rowIndex) => {
const cells = row.children.map((cell, cellIndex) => {
return (
<KuiTableRowCell
key={cellIndex}
align={this.columns[cellIndex].alignment}
wrapText={row.wrapText}
>
{cell}
</KuiTableRowCell>
);
});

return (
<KuiTableRow
isSelected={this.state.rowIndexToSelectedMap[rowIndex]}
key={rowIndex}
>
{cells}
</KuiTableRow>
);
});
}

render() {
return (
<KuiTable compressed>
<KuiTableHeader>
{this.renderHeaderCells()}
</KuiTableHeader>

<KuiTableBody>
{this.renderTableRows()}
</KuiTableBody>
</KuiTable>
);
}
}
134 changes: 134 additions & 0 deletions ui_framework/doc_site/src/views/table/table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import React, {
Component,
} from 'react';

import {
KuiIcon,
KuiTable,
KuiTableRow,
KuiTableRowCell,
KuiTableHeaderCell,
KuiTableBody,
KuiTableHeader,
} from '../../../../components';

import {
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
} from '../../../../services';

export class Table extends Component {
constructor(props) {
super(props);
this.state = {
rowIndexToSelectedMap: {
2: true,
},
};

this.rows = [{
children: [
<span>A very long line which will not wrap on narrower screens and instead will become truncated and replaced by an ellipsis</span>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>1</span>,
],
}, {
children: [
<span>A very long line which will wrap on narrower screens and <em>not</em> become truncated and replaced by an ellipsis</span>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>1</span>,
],
wrapText: true,
}, {
children: [
<a className="kuiLink" href="#">Boomerang</a>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>10</span>,
],
isSelected: true,
}, {
children: [
<a className="kuiLink" href="#">Celebration</a>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>100</span>,
],
}, {
children: [
<a className="kuiLink" href="#">Dog</a>,
<KuiIcon type="user" size="medium" />,
<span>Tue Dec 06 2016 12:56:15 GMT-0800 (PST)</span>,
<span>1000</span>,
],
}];

this.columns = [{
label: 'Title',
alignment: LEFT_ALIGNMENT,
}, {
label: 'Type',
alignment: LEFT_ALIGNMENT,
width: '60px',
}, {
label: 'Date created',
alignment: LEFT_ALIGNMENT,
}, {
label: 'Orders of magnitude',
alignment: RIGHT_ALIGNMENT,
}];
}

renderHeaderCells() {
return this.columns.map((column, columnIndex) => (
<KuiTableHeaderCell
key={columnIndex}
align={this.columns[columnIndex].alignment}
width={column.width}
>
{column.label}
</KuiTableHeaderCell>
));
}

renderTableRows() {
return this.rows.map((row, rowIndex) => {
const cells = row.children.map((cell, cellIndex) => {
return (
<KuiTableRowCell
key={cellIndex}
align={this.columns[cellIndex].alignment}
wrapText={row.wrapText}
>
{cell}
</KuiTableRowCell>
);
});

return (
<KuiTableRow
isSelected={this.state.rowIndexToSelectedMap[rowIndex]}
key={rowIndex}
>
{cells}
</KuiTableRow>
);
});
}

render() {
return (
<KuiTable>
<KuiTableHeader>
{this.renderHeaderCells()}
</KuiTableHeader>

<KuiTableBody>
{this.renderTableRows()}
</KuiTableBody>
</KuiTable>
);
}
}
Loading

0 comments on commit 52f345b

Please sign in to comment.