Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion scss/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@import "mixins/lists";
@import "mixins/list-group";
@import "mixins/forms";
@import "mixins/table-row";
@import "mixins/table-variants";

// Skins
@import "mixins/background-variant";
Expand Down
11 changes: 11 additions & 0 deletions scss/_reboot.scss
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ th {
text-align: -webkit-match-parent; // 2
}

thead,
tbody,
tfoot,
tr,
td,
th {
border-color: inherit;
border-style: solid;
border-width: 0;
}


// Forms
//
Expand Down
161 changes: 64 additions & 97 deletions scss/_tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,45 @@
//

.table {
--bs-table-bg: #{$table-bg};
--bs-table-accent-bg: transparent;
--bs-table-striped-color: #{$table-striped-color};
--bs-table-striped-bg: #{$table-striped-bg};
--bs-table-active-color: #{$table-active-color};
--bs-table-active-bg: #{$table-active-bg};
--bs-table-hover-color: #{$table-hover-color};
--bs-table-hover-bg: #{$table-hover-bg};

width: 100%;
margin-bottom: $spacer;
color: $table-color;
vertical-align: $table-cell-vertical-align;
background-color: $table-bg; // Reset for nesting within parents with `background-color`.

th,
td {
border-color: $table-border-color;

// Target th & td
// We need the child combinator to prevent styles leaking to nested tables which doesn't have a `.table` class.
// We use the universal selectors here to simplify the selector (else we would need 6 different selectors).
// Another advantage is that this generates less code and makes the selector less specific making it easier to override.
// stylelint-disable-next-line selector-max-universal
> :not(caption) > * > * {
padding: $table-cell-padding;
border-bottom: $table-border-width solid $table-border-color;
background-color: var(--bs-table-bg);
background-image: linear-gradient(var(--bs-table-accent-bg), var(--bs-table-accent-bg));
border-bottom-width: $table-border-width;
}

tbody {
> tbody {
vertical-align: inherit;
}

thead th {
> thead {
vertical-align: bottom;
border-bottom-color: $table-head-border-color;
}

tbody + tbody {
border-top: (2 * $table-border-width) solid $table-border-color;
// Highlight border color between thead, tbody and tfoot.
// stylelint-disable-next-line selector-max-universal
> :not(:last-child) > :last-child > * {
border-bottom-color: $table-group-seperator-color;
}
}

Expand All @@ -34,16 +50,18 @@
// Change placement of captions with a class
//

.caption-top { caption-side: top; }
.caption-top {
caption-side: top;
}


//
// Condensed table w/ half padding
//

.table-sm {
th,
td {
// stylelint-disable-next-line selector-max-universal
> :not(caption) > * > * {
padding: $table-cell-padding-sm;
}
}
Expand All @@ -52,29 +70,28 @@
// Border versions
//
// Add or remove borders all around the table and between all the columns.
//
// When borders are added on all sides of the cells, the corners can render odd when
// these borders do not have the same color or if they are semi-transparent.
// Therefor we add top and border bottoms to the `tr`s and left and right borders
// to the `td`s or `th`s

.table-bordered {
border: $table-border-width solid $table-border-color;
// stylelint-disable-next-line selector-max-universal
> :not(caption) > * {
border-width: $table-border-width 0;

th,
td {
border: $table-border-width solid $table-border-color;
}

thead {
th,
td {
border-bottom-width: 2 * $table-border-width;
// stylelint-disable-next-line selector-max-universal
> * {
border-width: 0 $table-border-width;
}
}
}

.table-borderless {
th,
td,
thead th,
tbody + tbody {
border: 0;
// stylelint-disable-next-line selector-max-universal
> :not(caption) > * > * {
border-bottom-width: 0;
}
}

Expand All @@ -83,92 +100,42 @@
// Default zebra-stripe styles (alternating gray and transparent backgrounds)

.table-striped {
tbody tr:nth-of-type(#{$table-striped-order}) {
background-color: $table-accent-bg;
> tbody > tr:nth-of-type(#{$table-striped-order}) {
--bs-table-accent-bg: var(--bs-table-striped-bg);
color: var(--bs-table-striped-color);
}
}

// Active table
//
// The `.table-active` class can be added to highlight rows or cells

.table-active {
--bs-table-accent-bg: var(--bs-table-active-bg);
color: var(--bs-table-active-color);
}

// Hover effect
//
// Placed here since it has to come after the potential zebra striping

.table-hover {
tbody tr {
&:hover {
color: $table-hover-color;
background-color: $table-hover-bg;
}
> tbody > tr:hover {
--bs-table-accent-bg: var(--bs-table-hover-bg);
color: var(--bs-table-hover-color);
}
}


// Table backgrounds
// Table variants
//
// Exact selectors below required to override `.table-striped` and prevent
// inheritance to nested tables.
// Table variants set the table cell backgrounds, border colors
// and the colors of the striped, hovered & active tables

@each $color, $value in $theme-colors {
@include table-row-variant($color, color-level($value, $table-bg-level), color-level($value, $table-border-level));
@each $color, $value in $table-variants {
@include table-variant($color, $value);
}

@include table-row-variant(active, $table-active-bg);


// Dark styles
//
// Same table markup, but inverted color scheme: dark background and light text.

// stylelint-disable-next-line no-duplicate-selectors
.table {
.thead-dark {
th {
color: $table-dark-color;
background-color: $table-dark-bg;
border-color: $table-dark-border-color;
}
}

.thead-light {
th {
color: $table-head-color;
background-color: $table-head-bg;
border-color: $table-border-color;
}
}
}

.table-dark {
color: $table-dark-color;
background-color: $table-dark-bg;

th,
td,
thead th {
border-color: $table-dark-border-color;
}

&.table-bordered {
border: 0;
}

&.table-striped {
tbody tr:nth-of-type(#{$table-striped-order}) {
background-color: $table-dark-accent-bg;
}
}

&.table-hover {
tbody tr {
&:hover {
color: $table-dark-hover-color;
background-color: $table-dark-hover-bg;
}
}
}
}


// Responsive tables
//
// Generate series of `.table-responsive-*` classes for configuring the screen
Expand Down
44 changes: 28 additions & 16 deletions scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -465,38 +465,50 @@ $mark-bg: #fcf8e3 !default;
//
// Customizes the `.table` component with basic values, each used across all table variations.

// scss-docs-start table-variables
$table-cell-padding: .5rem !default;
$table-cell-padding-sm: .25rem !default;

$table-cell-vertical-align: top !default;

$table-color: $body-color !default;
$table-bg: null !default;
$table-accent-bg: rgba($black, .05) !default;
$table-bg: transparent !default;

$table-striped-color: $table-color !default;
$table-striped-bg-factor: .05 !default;
$table-striped-bg: rgba($black, $table-striped-bg-factor) !default;

$table-active-color: $table-color !default;
$table-active-bg-factor: .1 !default;
$table-active-bg: rgba($black, $table-active-bg-factor) !default;

$table-hover-color: $table-color !default;
$table-hover-bg: rgba($black, .075) !default;
$table-active-bg: $table-hover-bg !default;
$table-hover-bg-factor: .075 !default;
$table-hover-bg: rgba($black, $table-hover-bg-factor) !default;

$table-border-factor: .1 !default;
$table-border-width: $border-width !default;
$table-border-color: $border-color !default;

$table-head-bg: $gray-200 !default;
$table-head-color: $gray-700 !default;
$table-head-border-color: $gray-700 !default;

$table-dark-color: $white !default;
$table-dark-bg: $gray-800 !default;
$table-dark-accent-bg: rgba($white, .05) !default;
$table-dark-hover-color: $table-dark-color !default;
$table-dark-hover-bg: rgba($white, .075) !default;
$table-dark-border-color: lighten($table-dark-bg, 7.5%) !default;

$table-striped-order: odd !default;

$table-group-seperator-color: currentColor !default;

$table-caption-color: $text-muted !default;

$table-bg-level: -9 !default;
$table-border-level: -6 !default;

$table-variants: (
"primary": color-level($primary, $table-bg-level),
"secondary": color-level($secondary, $table-bg-level),
"success": color-level($success, $table-bg-level),
"info": color-level($info, $table-bg-level),
"warning": color-level($warning, $table-bg-level),
"danger": color-level($danger, $table-bg-level),
"light": $light,
"dark": $dark,
) !default;
// scss-docs-end table-variables


// Buttons + Forms
Expand Down
39 changes: 0 additions & 39 deletions scss/mixins/_table-row.scss

This file was deleted.

21 changes: 21 additions & 0 deletions scss/mixins/_table-variants.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// scss-docs-start table-variant
@mixin table-variant($state, $background) {
.table-#{$state} {
$color: color-contrast(opaque($body-bg, $background));
$hover-bg: mix($color, $background, percentage($table-hover-bg-factor));
$striped-bg: mix($color, $background, percentage($table-striped-bg-factor));
$active-bg: mix($color, $background, percentage($table-active-bg-factor));

--bs-table-bg: #{$background};
--bs-table-striped-bg: #{$striped-bg};
--bs-table-striped-color: #{color-contrast($striped-bg)};
--bs-table-active-bg: #{$active-bg};
--bs-table-active-color: #{color-contrast($active-bg)};
--bs-table-hover-bg: #{$hover-bg};
--bs-table-hover-color: #{color-contrast($hover-bg)};

color: $color;
border-color: mix($color, $background, percentage($table-border-factor));
}
}
// scss-docs-end table-variant
Loading