diff --git a/packages/orange-compact/scss/ouds-web.scss b/packages/orange-compact/scss/ouds-web.scss index 142340eefc..ac4b885dff 100644 --- a/packages/orange-compact/scss/ouds-web.scss +++ b/packages/orange-compact/scss/ouds-web.scss @@ -19,7 +19,7 @@ @import "@ouds/web-common/scss/images"; @import "@ouds/web-common/scss/containers"; @import "@ouds/web-common/scss/grid"; -@import "@ouds/web-common/scss/tables"; +@import "@ouds/web-common/scss/table"; @import "@ouds/web-common/scss/forms"; @import "@ouds/web-common/scss/links"; // OUDS mod @import "@ouds/web-common/scss/bullet-list"; // OUDS mod diff --git a/packages/orange/scss/ouds-web.scss b/packages/orange/scss/ouds-web.scss index e7c1520c36..92cbe10b3e 100644 --- a/packages/orange/scss/ouds-web.scss +++ b/packages/orange/scss/ouds-web.scss @@ -19,7 +19,7 @@ @import "@ouds/web-common/scss/images"; @import "@ouds/web-common/scss/containers"; @import "@ouds/web-common/scss/grid"; -@import "@ouds/web-common/scss/tables"; +@import "@ouds/web-common/scss/table"; @import "@ouds/web-common/scss/forms"; @import "@ouds/web-common/scss/links"; // OUDS mod @import "@ouds/web-common/scss/bullet-list"; // OUDS mod diff --git a/packages/sosh/scss/ouds-web.scss b/packages/sosh/scss/ouds-web.scss index 4d2b322fc0..c59f318311 100644 --- a/packages/sosh/scss/ouds-web.scss +++ b/packages/sosh/scss/ouds-web.scss @@ -19,7 +19,7 @@ @import "@ouds/web-common/scss/images"; @import "@ouds/web-common/scss/containers"; @import "@ouds/web-common/scss/grid"; -@import "@ouds/web-common/scss/tables"; +@import "@ouds/web-common/scss/table"; @import "@ouds/web-common/scss/forms"; @import "@ouds/web-common/scss/links"; // OUDS mod @import "@ouds/web-common/scss/bullet-list"; // OUDS mod diff --git a/scss/_mixins.scss b/scss/_mixins.scss index aaf11695f0..42d9327b1c 100644 --- a/scss/_mixins.scss +++ b/scss/_mixins.scss @@ -30,7 +30,6 @@ @import "mixins/pagination"; @import "mixins/lists"; @import "mixins/forms"; -@import "mixins/table-variants"; // Skins @import "mixins/border-radius"; diff --git a/scss/_tables.scss b/scss/_table.scss similarity index 78% rename from scss/_tables.scss rename to scss/_table.scss index 2a62be0db0..e692011c36 100644 --- a/scss/_tables.scss +++ b/scss/_table.scss @@ -1,6 +1,10 @@ // // Basic OUDS Web table // +%active { + --#{$prefix}table-color-state: var(--#{$prefix}color-content-default); + --#{$prefix}table-bg-state: var(--#{$prefix}table-active-bg); +} .table { // Reset needed for nesting tables @@ -27,7 +31,14 @@ // OUDS mod //// Only rows have border //// Set line-height everywhere - tr { + + // stylelint-disable selector-no-qualifying-type + th[scope="col"], + th[scope="colgroup"] { + border-bottom: $table-header-border-width solid var(--#{$prefix}table-border-color); + } + + tr { border-bottom: $table-border-width solid var(--#{$prefix}table-border-color); } @@ -64,9 +75,21 @@ // OUDS mod // When using checkboxes in the first column, force width to ensure correct spacing on this column - &.has-checkbox tr > :first-child { - width: $spacer * 2; - max-width: $spacer * 2; + tr > *:has(.control-item-indicator[type="checkbox"]:not([role="switch"]), .control-item-indicator[type="radio"]) { + width: 1%; + padding: 0; + vertical-align: middle; + } + + // Extend checkboxes and radios click area + tr .radio-button-standalone, + tr .checkbox-standalone { + width: stretch; + } + + // Automatically highlight rows with checked checkboxes or radios + tbody tr:has(.control-item-indicator[type="checkbox"]:not([role="switch"]):checked, .control-item-indicator[type="radio"]:checked) { + @extend %active; } // Use negative margins on icons in tables to preserve row height @@ -75,6 +98,15 @@ margin-top: $table-cell-icon-margin-top; margin-bottom: $table-cell-icon-margin-bottom; } + + .table-cell-component { + padding-block: 0; + vertical-align: middle; + + > * { + vertical-align: middle; + } + } // End mod } @@ -90,18 +122,6 @@ caption-side: bottom; // OUDS mod } - -// -// Condensed table w/ half padding -// - -.table-sm { - // stylelint-disable-next-line selector-max-universal - > :not(caption) > * > * { - padding: $table-cell-padding-y-sm $table-cell-padding-x-sm calc($table-cell-padding-y-sm + 1px); // OUDS mod - } -} - // OUDS mod: no .table-bordered // OUDS mod: no .table-borderless @@ -129,10 +149,8 @@ // Active table // // The `.table-active` class can be added to highlight rows or cells - -.table-active { - --#{$prefix}table-color-state: var(--#{$prefix}table-active-color); - --#{$prefix}table-bg-state: var(--#{$prefix}table-active-bg); +.table-active[data-bs-theme="dark"] { + @extend %active; } // Hover effect @@ -146,14 +164,13 @@ } } -// Table variants set the table cell backgrounds, border colors -// and the colors of the striped, hovered & active tables - -@each $color, $value in $table-variants { - @include table-variant($color, $value); +// Table functional colors +@each $table-state in ("info", "positive", "warning", "negative") { + .table-#{$table-state} { + --#{$prefix}table-bg: var(--#{$prefix}color-surface-status-#{$table-state}-muted); + } } - // Responsive tables // // Generate series of `.table-responsive-*` classes for configuring the screen diff --git a/scss/_variables.scss b/scss/_variables.scss index 490ebd3a74..df5cc897b5 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -788,13 +788,11 @@ $mark-bg: $ouds-color-action-highlighted-light !default; // // Customizes the `.table` component with basic values, each used across all table variations. // scss-docs-start table-variables -$table-cell-padding-y: .875rem !default; // OUDS mod -$table-cell-padding-x: $spacer * .5 !default; // OUDS mod -$table-cell-padding-y-sm: .5625rem !default; // OUDS mod -$table-cell-padding-x-sm: $table-cell-padding-x !default; // OUDS mod +$table-cell-padding-y: $core-ouds-dimension-200 !default; // OUDS mod +$table-cell-padding-x: $core-ouds-dimension-200 !default; // OUDS mod -$table-cell-icon-margin-top: -.75rem !default; // OUDS mod -$table-cell-icon-margin-bottom: -.625rem !default; // OUDS mod +$table-cell-icon-margin-top: -.7rem !default; // OUDS mod +$table-cell-icon-margin-bottom: -.5rem !default; // OUDS mod $table-cell-vertical-align: top !default; $table-line-height: 1.25 !default; // OUDS mod @@ -806,12 +804,12 @@ $table-th-font-weight: null !default; $table-striped-color: $table-color !default; $table-striped-bg-factor: .035 !default; // OUDS mod: equivalent to `$gray-200` -$table-striped-bg: rgba(var(--#{$prefix}black-rgb), var(--#{$prefix}table-striped-bg-factor)) !default; // OUDS mod: instead of `rgba(var(--#{$prefix}emphasis-color-rgb), $table-striped-bg-factor)` +$table-striped-bg: var(--#{$prefix}color-bg-secondary) !default; // OUDS mod: instead of `rgba(var(--#{$prefix}emphasis-color-rgb), $table-striped-bg-factor)` $table-variant-striped-bg-factor: .08 !default; // OUDS mod -$table-active-color: $table-color !default; +$table-active-color: var(--#{$prefix}color-content-default) !default; $table-active-bg-factor: .135 !default; // OUDS mod -$table-active-bg: rgba(var(--#{$prefix}emphasis-color-rgb), var(--#{$prefix}table-active-bg-factor)) !default; // OUDS mod: instead of `rgba(var(--#{$prefix}emphasis-color-rgb), $table-active-bg-factor)` +$table-active-bg: var(--#{$prefix}color-bg-inverse-low) !default; // OUDS mod: instead of `rgba(var(--#{$prefix}emphasis-color-rgb), $table-active-bg-factor)` $table-variant-active-bg-factor: .4 !default; // OUDS mod $table-hover-color: $table-color !default; @@ -820,33 +818,19 @@ $table-hover-bg: rgba(var(--#{$prefix}emphasis-color-rgb) $table-variant-hover-bg-factor: .2 !default; // OUDS mod $table-border-factor: .4 !default; // OUDS mod -$table-border-width: calc(var(--#{$prefix}border-width) * .5) !default; // OUDS mod +$table-header-border-width: 2px !default; // OUDS mod +$table-border-width: 1px !default; // OUDS mod $table-border-color: var(--#{$prefix}color-border-default) !default; // OUDS mod: instead of `var(--#{$prefix}border-color)` -$table-striped-order: odd !default; -$table-striped-columns-order: even !default; +$table-striped-order: even !default; // OUDS mod +$table-striped-columns-order: odd !default; // OUDS mod $table-group-separator-color: currentcolor !default; $table-caption-color: var(--#{$prefix}caption-color, var(--#{$prefix}emphasis-color)) !default; // OUDS mod: instead of `var(--#{$prefix}secondary-color)` $table-caption-padding-y: .75rem !default; // OUDS mod - -$table-bg-scale: -60% !default; // scss-docs-end table-variables -// scss-docs-start table-loop -$table-variants: ( - "primary": shift-color($primary, $table-bg-scale), - "secondary": shift-color($secondary, $table-bg-scale), - "success": shift-color($success, $table-bg-scale), - "info": shift-color($info, $table-bg-scale), - "warning": shift-color($warning, $table-bg-scale), - "danger": shift-color($danger, $table-bg-scale), - "light": $light, - "dark": $dark, -) !default; -// scss-docs-end table-loop - // Buttons + Forms // // Shared variables that are reassigned to `$input-` and `$btn-` specific variables. diff --git a/scss/mixins/_table-variants.scss b/scss/mixins/_table-variants.scss deleted file mode 100644 index 035ae7923d..0000000000 --- a/scss/mixins/_table-variants.scss +++ /dev/null @@ -1,25 +0,0 @@ -// OUDS mod: Variants have a different hover and striped management -// 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-variant-hover-bg-factor));// OUDS mod - $striped-bg: mix($color, $background, percentage($table-variant-striped-bg-factor)); // OUDS mod - $active-bg: mix($color, $background, percentage($table-variant-active-bg-factor)); // OUDS mod - $table-border-color: mix($color, $background, percentage($table-border-factor)); - - --#{$prefix}table-color: #{$color}; - --#{$prefix}table-bg: #{$background}; - --#{$prefix}table-border-color: #{$table-border-color}; - --#{$prefix}table-striped-bg: #{$striped-bg}; - --#{$prefix}table-striped-color: #{color-contrast($striped-bg)}; - --#{$prefix}table-active-bg: #{$active-bg}; - --#{$prefix}table-active-color: #{color-contrast($active-bg)}; - --#{$prefix}table-hover-bg: #{$hover-bg}; - --#{$prefix}table-hover-color: #{color-contrast($hover-bg)}; - - color: var(--#{$prefix}table-color); - border-color: var(--#{$prefix}table-border-color); - } -} -// scss-docs-end table-variant diff --git a/site/data/components-details.ts b/site/data/components-details.ts index 8b547a8c28..58e616813b 100644 --- a/site/data/components-details.ts +++ b/site/data/components-details.ts @@ -282,6 +282,27 @@ export const componentsDetails: ComponentCardData[] = [ ` }, + { + name: 'Table', + category: 'Content display', + snippet: ` +
| # | +First | +Second | +
|---|---|---|
| 1 | +Cell | +Cell | +
| # | +Heading | +Heading | +
|---|---|---|
| 1 | +Cell | +Cell | +
| 2 | +Cell | +Cell | +
| 3 | +Cell | +Cell | +
| # | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +
|---|---|---|---|---|---|---|---|---|---|
| 1 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
| 2 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
| 3 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
+
+ ...
+
+ `} />
+
+### Breakpoint specific
+
+Use `.table-responsive{-xs|-sm|-md|-lg|-xl|-2xl|3xl}` as needed to create responsive tables up to a particular breakpoint. From that breakpoint and up, the table will behave normally and not scroll horizontally.
+
+**These tables may appear broken until their responsive styles apply at specific viewport widths.**
+
+
+
+ Resize window to see differences:
+ {getData('breakpoints').map((breakpoint) => {
+ return (
+
+
+
+
+ Boosted responsive table for {breakpoint.abbr} breakpoint and under
+
+
+ #
+ Heading
+ Heading
+ Heading
+ Heading
+ Heading
+ Heading
+ Heading
+ Heading
+
+
+
+
+ 1
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+
+
+ 2
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+
+
+ 3
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+ Cell
+
+
+
+
+
+ )
+ })}
+
+ `
+
+ ...
+
+ `)} />
+
+
+## Row selection
+
+### With checkboxes
+
+For the row selection purpose with checkboxes, you should use [standalone checkboxes]([[docsref:/components/checkbox#standalone]]) with `.visually-hidden` labels describing their use.
+
+The first cell of the header should contain a checkbox to select or deselect all rows. When some rows - but not all - are selected, the header checkbox should be in an [indeterminate state]([[docsref:/components/checkbox#indeterminate]]).
+
+To visually indicate a row is selected, you'll need to apply a `data-bs-theme="dark"` attribute on the `` element (some additional styles will be applied too). This can be done by JavaScript, see the example below. If you want to manually apply the same styles to rows or even cells, you can use the class `.table-active` with `data-bs-theme="dark"` on ` ` or `` elements.
+
+Note that the width of columns containing checkboxes will automatically adjust to the largest cell, and the click area will be extended to the full width of the cell.
+
+
+ OUDS Web table with row selection
+
+
+
+
+
+ Heading
+ Heading
+ Heading
+
+
+
+
+
+
+
+ Cell
+ Cell
+ Cell
+
+
+
+
+
+ This is a much longer section of text that demonstrates what happens when text wraps within a cell in a table
+ Cell
+ Cell
+
+
+
+
+
+ Cell
+ Cell
+ Cell
+
+
+ `} />
+
+To manage checkboxes states and active styles (i.e. select/deselect all rows, update header checkbox state, and update `data-bs-theme` on selected row), here is an example of JavaScript code:
+
+
+### With radio buttons
+
+For the row selection purpose with radio buttons, you should use [standalone radio buttons]([[docsref:/components/radio-button#standalone]]) with `.visually-hidden` labels describing their use.
+
+The [same rules apply as with checkboxes](#with-checkboxes), except that there is no "all rows" selection. The JavaScript will only need to update the `data-bs-theme` on selected rows, as we have done in the example below.
+
+
+ OUDS Web table with radio buttons
+
+
+ Select
+ Heading
+ Heading
+ Heading
+
+
+
+
+
+
+
+ This is a much longer section of text that demonstrates what happens when text wraps within a cell in a table
+ Cell
+ Cell
+
+
+
+
+
+ Cell
+ Cell
+ Cell
+
+
+
+
+
+ Cell
+ Cell
+ Cell
+
+
+ `} />
+
+To manage radio buttons active state (i.e. update `data-bs-theme` on the selected row), here is an example of JavaScript code:
+
+
+## Rich content tables
+
+You can also use other components in tables, such as tags, badges, switches, images or icons.
+
+To align horizontally or vertically, you can use the following:
+- For horizontal alignment, use the `.text-center` class on `` and ` ` elements.
+- For vertical alignment, use the `.align-middle` class on the ` ` elements. Some components inside cells may require additional alignment (possibly via a utility class).
+
+
+ OUDS Web table with components and icons
+
+
+ Heading
+ Heading
+ Heading
+ Heading
+ Activated
+
+
+
+
+
+ Cell
+
+ This is a much longer section of text that demonstrates what happens when text wraps within a cell in a table
+
+
+
+ Maintenance
+
+
+
+
+
+ Warning
+
+
+
+
+
+
+
+
+
Cell
+
+ Cell
+
+
+
+ Running
+
+
+
+
+
+ OK
+
+
+
+
+
+
+
+
+ Cell
+
+ Cell
+
+
+
+ Error
+
+
+
+
+
+ Error
+
+
+
+
+
+
+
+ `} />
+
+
+### Row height and alignment
+
+To align vertically and preserve the row height, use the `.align-middle` class on the `` elements and `.table-cell-component` on `` elements containing components that could cause vertical overflow.
+
+
+ OUDS Web table with components and icons preserving the row height
+
+
+ Heading
+ Heading
+ Heading
+ Heading
+ Activated
+
+
+
+
+
+ Cell
+
+ This is a much longer section of text that demonstrates what happens when text wraps within a cell in a table
+
+
+
+ Maintenance
+
+
+
+
+
+ Warning
+
+
+
+
+
+
+
+
+
Cell
+
+ Cell
+
+
+
+ Running
+
+
+
+
+
+ OK
+
+
+
+
+
+
+
+
+ Cell
+
+ Cell
+
+
+
+ Error
+
+
+
+
+
+ Error
+
+
+
+
+
+
+
+ `} />
+
diff --git a/site/src/types/auto-import.d.ts b/site/src/types/auto-import.d.ts
index 0900b48a37..a211e9349a 100644
--- a/site/src/types/auto-import.d.ts
+++ b/site/src/types/auto-import.d.ts
@@ -16,6 +16,7 @@ export declare global {
export const ColorTable: typeof import('@shortcodes/ColorTable.astro').default
export const ComponentCard: typeof import('@shortcodes/ComponentCard.astro').default
export const DeprecatedIn: typeof import('@shortcodes/DeprecatedIn.astro').default
+ export const Details: typeof import('@shortcodes/Details.astro').default
export const EnableBtnCloseTooltip: typeof import('@shortcodes/EnableBtnCloseTooltip.astro').default
export const Example: typeof import('@shortcodes/Example.astro').default
export const JsDismiss: typeof import('@shortcodes/JsDismiss.astro').default