mirror of
https://github.com/picocss/pico.git
synced 2025-04-25 02:36:15 -04:00
150 lines
4.5 KiB
SCSS
150 lines
4.5 KiB
SCSS
@use "sass:map";
|
||
@use "../settings" as *;
|
||
|
||
// Variables for striped rows
|
||
$color-dark: var(#{$css-var-prefix}table-row-stripped-background-color);
|
||
$color-light: var(#{$css-var-prefix}background-color);
|
||
|
||
// Adjust this number to control how many <tr hidden> rows are expected.
|
||
$hidden-levels: $hidden-table-levels;
|
||
|
||
// Do not change, or remove the following line
|
||
// needed this outside of the mixin to compile, idk why
|
||
// sass --version = 1.83.4 compiled with dart2js 3.6.1
|
||
$selector: "& ~ tr";
|
||
|
||
// This is the work around because the compiler changes
|
||
// :nth-child(odd of :not(:hidden)) to :nth-child(oddof:not(:hidden))
|
||
// which makes the stripes fail.
|
||
// Mixin to handle the hidden row with striped backgrounds patterns
|
||
// Thanks Shaggy: https://stackoverflow.com/questions/3773890/zebra-striping-a-table-with-hidden-rows-using-css3/36892714#36892714
|
||
@mixin hidden-row-patterns($levels: 2, $dark-color: $color-dark, $light-color: $color-light) {
|
||
$current-color-odd: $light-color;
|
||
$current-color-even: $dark-color;
|
||
// Generate nested s electors for each level
|
||
$selector: "& ~ tr";
|
||
|
||
&[hidden] {
|
||
display: none;
|
||
|
||
@for $i from 1 through $levels {
|
||
@if $i > 1 {
|
||
// Swap colors for next iteration
|
||
$temp: $current-color-odd;
|
||
$current-color-odd: $current-color-even;
|
||
$current-color-even: $temp;
|
||
|
||
// Add another level of nesting to the selector
|
||
$selector: "#{$selector}[hidden] ~ tr";
|
||
}
|
||
#{$selector} {
|
||
&:nth-child(odd) {
|
||
> th,
|
||
> td {
|
||
background: $current-color-odd;
|
||
}
|
||
}
|
||
|
||
&:nth-child(even) {
|
||
> th,
|
||
> td {
|
||
background: $current-color-even;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
@if map.get($modules, "content/table") {
|
||
/**
|
||
* Table
|
||
*/
|
||
|
||
// Reboot based on :
|
||
// - normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css
|
||
// - sanitize.css v13.0.0 | CC0 1.0 Universal | github.com/csstools/sanitize.css
|
||
// ––––––––––––––––––––
|
||
|
||
// 1. Collapse border spacing in all browsers (opinionated)
|
||
// 2. Remove text indentation from table contents in Chrome, Edge, and Safari
|
||
#{$parent-selector} :where(table) {
|
||
width: 100%;
|
||
border-collapse: collapse; // 1
|
||
border-spacing: 0;
|
||
text-indent: 0; // 2
|
||
}
|
||
|
||
// Pico
|
||
// ––––––––––––––––––––
|
||
|
||
// Cells
|
||
#{$parent-selector} table th,
|
||
#{$parent-selector} table td {
|
||
padding: calc(var(#{$css-var-prefix}spacing) / 2) var(#{$css-var-prefix}spacing);
|
||
border-bottom: var(#{$css-var-prefix}border-width)
|
||
solid
|
||
var(#{$css-var-prefix}table-border-color);
|
||
background-color: var(#{$css-var-prefix}background-color);
|
||
color: var(#{$css-var-prefix}color);
|
||
font-weight: var(#{$css-var-prefix}font-weight);
|
||
text-align: left;
|
||
text-align: start;
|
||
}
|
||
|
||
#{$parent-selector} table > caption {
|
||
margin-block: calc(var(#{$css-var-prefix}block-spacing-vertical) * 0.5);
|
||
padding: calc(var(#{$css-var-prefix}spacing) / 2) var(#{$css-var-prefix}spacing);
|
||
background-color: var(#{$css-var-prefix}table-row-stripped-background-color);
|
||
color: var(#{$css-var-prefix}h3-color);
|
||
font-weight: var(#{$css-var-prefix}font-weight);
|
||
font-size: 1.25rem;
|
||
text-align: center;
|
||
}
|
||
|
||
// Footer
|
||
#{$parent-selector} table > tfoot {
|
||
th,
|
||
td {
|
||
border-top: var(#{$css-var-prefix}border-width)
|
||
solid
|
||
var(#{$css-var-prefix}table-border-color);
|
||
border-bottom: 0;
|
||
}
|
||
}
|
||
|
||
#{$parent-selector} table > caption {
|
||
margin-block: calc(var(#{$css-var-prefix}block-spacing-vertical) * 0.5);
|
||
background-color: var(#{$css-var-prefix}table-row-stripped-background-color);
|
||
color: var(#{$css-var-prefix}h3-color);
|
||
font-weight: var(#{$css-var-prefix}font-weight);
|
||
font-size: 1.25rem;
|
||
text-align: center;
|
||
}
|
||
|
||
// Striped
|
||
@if enable-classes {
|
||
#{$parent-selector} table {
|
||
&.striped {
|
||
> tbody > tr {
|
||
&:nth-child(odd) {
|
||
> th,
|
||
> td {
|
||
background: $color-dark;
|
||
}
|
||
}
|
||
|
||
&:nth-child(even) {
|
||
> th,
|
||
> td {
|
||
background: $color-light;
|
||
}
|
||
}
|
||
|
||
// Apply the hidden row patterns
|
||
@include hidden-row-patterns($hidden-levels);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|