Horizontal tables

This commit is contained in:
Angelos Chalaris 2018-01-03 13:20:12 +02:00
parent a54a409c1d
commit f6af201afc
4 changed files with 324 additions and 75 deletions

128
dist/mini-default.css vendored
View file

@ -1714,8 +1714,6 @@ table {
flex-flow: row wrap;
padding: var(--universal-padding);
padding-top: 0;
overflow: auto;
max-height: 400px;
}
table caption {
@ -1727,16 +1725,12 @@ table caption {
table thead, table tbody {
display: flex;
max-width: 100%;
flex-flow: row wrap;
flex: 0 0 100%;
border: 0.0625rem solid var(--table-border-color);
}
table thead {
z-index: 999;
position: sticky;
top: 0;
border-radius: var(--universal-border-radius) var(--universal-border-radius) 0 0;
border-bottom: 0.0625rem solid #666;
}
@ -1749,16 +1743,11 @@ table tbody {
table tr {
display: flex;
flex-flow: row wrap;
flex: 0 0 100%;
padding: 0;
}
table th, table td {
padding: calc(2 * var(--universal-margin));
flex: 1 0 0%;
overflow: hidden;
text-overflow: ellipsis;
padding: calc(2 * var(--universal-padding));
}
table th {
@ -1772,18 +1761,110 @@ table td {
border-top: 0.0625rem solid var(--table-border-color);
}
table tbody tr:first-child td {
table:not(.horizontal) {
overflow: auto;
max-height: 400px;
}
table:not(.horizontal) thead, table:not(.horizontal) tbody {
max-width: 100%;
flex: 0 0 100%;
}
table:not(.horizontal) tr {
flex-flow: row wrap;
flex: 0 0 100%;
}
table:not(.horizontal) th, table:not(.horizontal) td {
flex: 1 0 0%;
overflow: hidden;
text-overflow: ellipsis;
}
table:not(.horizontal) thead {
position: sticky;
top: 0;
}
table:not(.horizontal) tbody tr:first-child td {
border-top: 0;
}
table.horizontal {
border: 0;
}
table.horizontal thead, table.horizontal tbody {
border: 0;
flex-flow: row nowrap;
}
table.horizontal tbody {
overflow: auto;
justify-content: space-between;
flex: 1 0 0;
margin-left: calc( 4 * var(--universal-margin));
padding-bottom: calc(var(--universal-padding) / 4);
}
table.horizontal tr {
flex-direction: column;
flex: 1 0 auto;
}
table.horizontal th, table.horizontal td {
width: 100%;
border: 0;
border-bottom: 0.0625rem solid var(--table-border-color);
}
table.horizontal th:not(:first-child), table.horizontal td:not(:first-child) {
border-top: 0;
}
table.horizontal th {
text-align: right;
border-left: 0.0625rem solid var(--table-border-color);
border-right: 0.0625rem solid #666;
}
table.horizontal thead tr:first-child {
padding-left: 0;
}
table.horizontal th:first-child, table.horizontal td:first-child {
border-top: 0.0625rem solid var(--table-border-color);
}
table.horizontal tbody tr:last-child td {
border-right: 1px solid #aaa;
}
table.horizontal tbody tr:last-child td:first-child {
border-top-right-radius: 0.25rem;
}
table.horizontal tbody tr:last-child td:last-child {
border-bottom-right-radius: 0.25rem;
}
table.horizontal thead tr:first-child th:first-child {
border-top-left-radius: 0.25rem;
}
table.horizontal thead tr:first-child th:last-child {
border-bottom-left-radius: 0.25rem;
}
@media screen and (max-width: 767px) {
table {
table, table.horizontal {
border-collapse: collapse;
border: 0;
width: 100%;
display: table;
}
table thead, table th {
table thead, table th, table.horizontal thead, table.horizontal th {
border: 0;
height: 1px;
width: 1px;
@ -1795,10 +1876,10 @@ table tbody tr:first-child td {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
}
table tbody {
table tbody, table.horizontal tbody {
display: table-row-group;
}
table tr {
table tr, table.horizontal tr {
display: block;
border: 0.0625rem solid var(--table-border-color);
border-radius: var(--universal-border-radius);
@ -1807,14 +1888,23 @@ table tbody tr:first-child td {
margin: var(--universal-margin);
margin-bottom: calc(2 * var(--universal-margin));
}
table td {
table th, table td, table.horizontal th, table.horizontal td {
width: auto;
}
table td, table.horizontal td {
display: block;
border: 0;
text-align: right;
}
table td:before {
table td:before, table.horizontal td:before {
content: attr(data-label);
float: left;
font-weight: 600;
}
table th:first-child, table td:first-child, table.horizontal th:first-child, table.horizontal td:first-child {
border-top: 0;
}
table tbody tr:last-child td, table.horizontal tbody tr:last-child td {
border-right: 0;
}
}

File diff suppressed because one or more lines are too long

View file

@ -259,3 +259,7 @@
- Started working on `table` module. Tables are now scrollable by default.
- Coded desktop view for `table`, no `@media` queries in there yet, but there will be more sooner rather than later.
- Added mobile view for tables, fully functional, no problems, still missing `.horizontal` and `.striped` (also `.hoverable` ?) and variablization.
## 20180103
- Added `.horizontal` `table` elements, optimized for minimal size. Some variables are missing and unset but overall both normal and `.horizontal` tables should work properly now on desktop as well as on mobile.

View file

@ -25,10 +25,14 @@ $table-mobile-card-label: 'data-label' !default;
$table-mobile-label-font-weight: 600 !default;
$table-border-color: #aaa !default;
$table-border-separator-color: #666 !default;
$_include-horizontal-table: true !default;
$table-horizontal-name: 'horizontal' !default;
// CSS variable name definitions [exercise caution if modifying these]
$table-border-color-var: '--table-border-color' !default;
$table-border-separator-color-var: '--table-border-separator-color' !default;
// == Uncomment below code if this module is used on its own ==
//
// $universal-margin: 0.5rem !default; // Universal margin for the most elements
@ -52,6 +56,7 @@ $table-border-color-var: '--table-border-color' !default;
/* Table module CSS variable definitions. */
:root {
#{$table-border-color-var}: $table-border-color;
#{$table-border-separator-color-var}: $table-border-separator-color;
}
// Desktop view.
table {
@ -63,8 +68,10 @@ table {
flex-flow: row wrap;
padding: var(#{$universal-padding-var});
padding-top: 0;
@if not($_include-horizontal-table) {
overflow: auto;
max-height: $table-max-height;
}
caption {
font-size: $table-caption-font-size;
margin: calc(2 * var(#{$universal-margin-var})) 0;
@ -73,17 +80,21 @@ table {
}
thead, tbody {
display: flex;
max-width: 100%;
flex-flow: row wrap;
flex: 0 0 100%;
border: $__1px solid var(#{$table-border-color-var});
@if not($_include-horizontal-table) {
max-width: 100%;
flex: 0 0 100%;
}
}
thead {
z-index: 999; // Fixes the visibility of the element.
border-radius: var(#{$universal-border-radius-var}) var(#{$universal-border-radius-var}) 0 0;
border-bottom: $__1px solid var(#{$table-border-separator-color-var}); // var This
@if not($_include-horizontal-table) {
position: sticky;
top: 0;
border-radius: var(#{$universal-border-radius-var}) var(#{$universal-border-radius-var}) 0 0;
border-bottom: 0.0625rem solid #666; // var This
}
}
tbody {
border-top: 0;
@ -92,16 +103,20 @@ table {
}
tr {
display: flex;
padding: 0; // Apply always to overwrite default.
@if not($_include-horizontal-table) {
flex-flow: row wrap;
flex: 0 0 100%;
padding: 0; // Apply always to overwrite default.
}
}
th, td {
padding: calc(2 * var(#{$universal-margin-var})); // Apply always to overwrite default.
padding: calc(2 * var(#{$universal-padding-var})); // Apply always to overwrite default.
@if not($_include-horizontal-table) {
flex: 1 0 0%;
overflow: hidden;
text-overflow: ellipsis;
}
}
th {
text-align: left;
background: #e6e6e6; // use vars
@ -111,12 +126,153 @@ table {
background: #fafafa; // use variables, this is a test (body)
border-top: $__1px solid var(#{$table-border-color-var});
}
@if not($_include-horizontal-table) {
tbody tr:first-child td {
border-top: 0;
}
}
}
// Styling for horizntal tables
@if $_include-horizontal-table {
table:not(.#{$table-horizontal-name}) {
overflow: auto;
max-height: $table-max-height;
thead, tbody {
max-width: 100%;
flex: 0 0 100%;
}
tr {
flex-flow: row wrap;
flex: 0 0 100%;
}
th, td {
flex: 1 0 0%;
overflow: hidden;
text-overflow: ellipsis;
}
thead {
position: sticky;
top: 0;
}
tbody tr:first-child td {
border-top: 0;
}
}
table.#{$table-horizontal-name} {
border: 0;
thead, tbody {
border: 0;
flex-flow: row nowrap;
}
tbody {
overflow: auto;
justify-content: space-between;
flex: 1 0 0;
margin-left: calc( 4 * var(#{$universal-margin-var}));
padding-bottom: calc(var(#{$universal-padding-var}) / 4);
}
tr {
flex-direction: column;
flex: 1 0 auto;
}
th, td {
width: 100%;
border: 0;
border-bottom: $__1px solid var(#{$table-border-color-var});
&:not(:first-child){
border-top: 0;
}
}
th {
text-align: right;
border-left: $__1px solid var(#{$table-border-color-var});
border-right: $__1px solid var(#{$table-border-separator-color-var});
}
thead {
tr:first-child {
padding-left: 0;
}
}
th:first-child, td:first-child {
border-top: $__1px solid var(#{$table-border-color-var});
}
tbody tr:last-child td {
border-right: 1px solid #aaa;
&:first-child{
border-top-right-radius: 0.25rem;
}
&:last-child{
border-bottom-right-radius: 0.25rem;
}
}
thead tr:first-child th {
&:first-child{
border-top-left-radius: 0.25rem;
}
&:last-child{
border-bottom-left-radius: 0.25rem;
}
}
}
}
// Mobile
@media screen and (max-width: #{$table-mobile-breakpoint - 1px}){
@if $_include-horizontal-table {
table, table.#{$table-horizontal-name} {
border-collapse: collapse;
border: 0;
width: 100%;
display: table;
// Accessibility (element is not visible, but screen readers read it normally)
thead, th {
border: 0;
height: 1px;
width: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
clip: rect(0 0 0 0);
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
}
tbody {
display: table-row-group;
}
tr {
display: block;
border: $__1px solid var(#{$table-border-color-var});
border-radius: var(#{$universal-border-radius-var});
@if $universal-box-shadow != none {
box-shadow: var(#{$universal-box-shadow-var});
}
background: #fafafa; // use variables, this is a test (body)
padding: var(#{$universal-padding-var});
margin: var(#{$universal-margin-var});
margin-bottom: calc(2 * var(#{$universal-margin-var}));
}
th, td {
width: auto;
}
td {
display: block;
border: 0;
text-align: right;
}
td:before {
content: attr(#{$table-mobile-card-label});
float: left;
font-weight: $table-mobile-label-font-weight;
}
th:first-child, td:first-child {
border-top: 0;
}
tbody tr:last-child td {
border-right: 0;
}
}
}
@else {
table {
border-collapse: collapse;
border: 0;
@ -161,6 +317,5 @@ table {
font-weight: $table-mobile-label-font-weight;
}
}
}
}
// Missing horizontal tables and striped tables