picocss/scss/content/_table.scss

151 lines
4.5 KiB
SCSS
Raw Normal View History

2024-12-31 05:18:39 +00:00
@use "sass:map";
@use "../settings" as *;
2025-01-17 03:50:25 -05:00
// 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;
}
}
}
}
}
}
2024-12-31 05:18:39 +00:00
@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
2025-01-17 03:50:25 -05:00
#{$parent-selector} table th,
#{$parent-selector} table td {
2024-12-31 05:18:39 +00:00
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;
}
2025-01-17 03:50:25 -05:00
#{$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;
}
2024-12-31 05:18:39 +00:00
// Footer
2025-01-17 03:50:25 -05:00
#{$parent-selector} table > tfoot {
2024-12-31 05:18:39 +00:00
th,
td {
border-top: var(#{$css-var-prefix}border-width)
solid
var(#{$css-var-prefix}table-border-color);
border-bottom: 0;
}
}
2025-01-17 03:50:25 -05:00
#{$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;
}
2024-12-31 05:18:39 +00:00
// Striped
@if enable-classes {
#{$parent-selector} table {
&.striped {
2025-01-17 03:50:25 -05:00
> 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);
2024-12-31 05:18:39 +00:00
}
}
}
}
}