All files / components/table Table.vue

91.91% Statements 125/136
89.28% Branches 100/112
95.23% Functions 40/42
91.91% Lines 125/136

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819    1x 3x       1x     1x 1x 1x 1x 1x 1x 1x 1x 1x         1x               1x                                                               28x 82x   28x 28x       1x 1x   27x                             28x 1x   27x 60x   27x 57x   27x         27x                                                               13x                                       235x                     16x                                                       20x   20x 20x 20x   20x 10x   20x 20x 48x       20x   20x 56x   20x                         462x                   175x 175x                     529x 529x 8x                   529x 529x 8x   521x                       632x 593x   632x         632x                           103x 103x 2x   103x 2x   103x                   5x           5x   5x 5x     5x                     3x 3x 3x 15x                             6x   6x 6x 1x   6x 1x       6x                   39x 39x                     103x 64x   103x 39x   39x     20x                                                   1x 1x 1x 1x 1x       1x       1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x         35x 35x 35x                                                                   35x                 3x           38x               103x                       6x                                       35x       175x                 5x           235x               529x         529x         525x                                                                         1x 1x                                                                                                                                                                                                                                                                                                                                                                                                      
<template>
	<div class="cdx-table" tabindex="0">
		<div
			v-if="!hideCaption || ( $slots.header && $slots.header().length > 0 )"
			class="cdx-table__header"
		>
			<!--
				We need this div, even if the caption is hidden, to ensure the
				slot is aligned to the end.
				aria-hidden is used so assistive tech will skip the visible caption and only read
				the <caption> element. However, if there is header content, the visible caption
				should be read too to ensure the caption is read before the header content.
			-->
			<div
				class="cdx-table__header__caption"
				:aria-hidden="$slots.header && $slots.header().length > 0 ? undefined : true"
			>
				<!-- Visible table title. -->
				<template v-if="!hideCaption">
					{{ caption }}
				</template>
			</div>
			<div class="cdx-table__header__content">
				<!-- eslint-disable-next-line max-len -->
				<!-- @slot Header content. Not to be confused with <thead>; use the thead slot to customize that. -->
				<slot name="header" />
			</div>
		</div>
		<div class="cdx-table__table-wrapper">
			<table class="cdx-table__table" :class="tableClasses">
				<!-- Visually-hidden caption element, for assistive technology. -->
				<caption>
					{{ caption }}
					<span v-if="hasSortableColumns">
						{{ sortCaption }}
					</span>
				</caption>
				<!-- @slot Custom <thead>. -->
				<slot name="thead">
					<thead v-if="columns.length > 0">
						<tr>
							<th v-if="useRowSelection" class="cdx-table__table__select-rows">
								<cdx-checkbox
									v-model="selectAll"
									:hide-label="true"
									:indeterminate="selectAllIndeterminate"
									@update:model-value="handleSelectAll"
								>
									{{ selectAllLabel }}
								</cdx-checkbox>
							</th>
							<th
								v-for="column in columns"
								:key="column.id"
								scope="col"
								:class="getCellClass( column, column.allowSort )"
								:aria-sort="getSortOrder( column.id, column.allowSort )"
								:style="getCellStyle( column )"
							>
								<template v-if="column.allowSort">
									<button
										:aria-selected="column.id === activeSortColumn"
										class="cdx-table__table__sort-button"
										@click="handleSort( column.id )"
									>
										{{ column.label }}
										<cdx-icon
											:icon="getSortIcon( column.id )"
											size="small"
											class="cdx-table__table__sort-icon"
											aria-hidden="true"
										/>
									</button>
								</template>
								<template v-else>
									{{ column.label }}
								</template>
							</th>
						</tr>
					</thead>
				</slot>
 
				<!-- @slot Custom <tbody>. -->
				<slot name="tbody">
					<tbody v-if="data.length > 0">
						<tr
							v-for="( row, rowIndex ) in data"
							:key="getRowKey( row, rowIndex )"
							:class="getRowClass( row, rowIndex )"
						>
							<td v-if="useRowSelection">
								<cdx-checkbox
									v-model="wrappedSelectedRows"
									:input-value="getRowKey( row, rowIndex )"
									:hide-label="true"
									@update:model-value="handleRowSelection"
								>
									{{ selectRowLabel( rowIndex + 1, data.length ) }}
								I</cdx-checkbox>
							</td>
							<component
								:is="getCellElement( column.id )"
								v-for="column in columns"
								:key="column.id"
								:scope="getRowHeaderScope( column.id )"
								:class="getCellClass( column )"
							>
								<!--
									@slot Table cell content, per column.
									@binding item {any} Data for the cell
									@binding row {TableRow|TableRowWithIdentifier} Data for the row
								-->
								<slot
									:name="'item-' + column.id"
									:item="row[ column.id ]"
									:row="row">
									{{ row[ column.id ] }}
								</slot>
							</component>
						</tr>
					</tbody>
					<!-- eslint-disable-next-line max-len -->
					<tbody v-else-if="$slots[ 'empty-state' ] && $slots[ 'empty-state' ]().length > 0">
						<tr class="cdx-table__table__empty-state">
							<td class="cdx-table__table__empty-state-content">
								<!-- @slot Empty state content. -->
								<slot name="empty-state" />
							</td>
						</tr>
					</tbody>
				</slot>
				<!-- @slot Custom <tfoot>. -->
				<slot name="tfoot" />
			</table>
		</div>
		<div v-if="$slots.footer && $slots.footer().length > 0" class="cdx-table__footer">
			<!-- eslint-disable-next-line max-len -->
			<!-- @slot Footer content. Not to be confused with <tfoot>; use the tfoot slot to add that. -->
			<slot name="footer" />
		</div>
	</div>
</template>
 
<script lang="ts">
import { PropType, defineComponent, ref, toRef, computed } from 'vue';
import { TableColumn, TableRow, TableRowWithIdentifier, TableSort, TableSortOption } from '../../types';
import { TableTextAlignments, TableRowIdentifier } from '../../constants';
import useModelWrapper from '../../composables/useModelWrapper';
import { makeStringTypeValidator } from '../../utils/stringTypeValidator';
import CdxCheckbox from '../checkbox/Checkbox.vue';
import CdxIcon from '../icon/Icon.vue';
import { cdxIconSortVertical, cdxIconUpTriangle, cdxIconDownTriangle, Icon } from '@wikimedia/codex-icons';
 
type TableSortIconMap = { [P in TableSortOption]: Icon };
type TableSortDirection = 'none' | 'ascending' | 'descending';
type TableSortDirectionMap = { [P in TableSortOption]: TableSortDirection };
 
const tableTextAlignmentsValidator = makeStringTypeValidator( TableTextAlignments );
const iconMap: TableSortIconMap = {
	none: cdxIconSortVertical,
	asc: cdxIconUpTriangle,
	desc: cdxIconDownTriangle
};
const sortDirectionMap: TableSortDirectionMap = {
	none: 'none',
	asc: 'ascending',
	desc: 'descending'
};
 
/**
 * An HTML table for displaying data.
 */
export default defineComponent( {
	name: 'CdxTable',
	components: { CdxCheckbox, CdxIcon },
	props: {
		/**
		 * Table caption.
		 *
		 * Required to support users of assistive technology, but can be visually hidden.
		 */
		caption: {
			type: String,
			required: true
		},
		/**
		 * Whether to visually hide the caption.
		 */
		hideCaption: {
			type: Boolean,
			default: false
		},
		/**
		 * Column definitions.
		 */
		columns: {
			type: Array as PropType<TableColumn[]>,
			default: () => [],
			validator: ( value: TableColumn[] ) => {
				const ids = value.map( ( column: TableColumn ) => column.id );
				const hasUniqueIds = ( new Set( ids ) ).size === ids.length;
				if ( !hasUniqueIds ) {
					// The warning that Vue prints when a validator fails isn't very informative,
					// so we add our own.
					// eslint-disable-next-line no-console
					console.warn(
						'Each column in the "columns" prop of CdxTable must have a unique "id".'
					);
					return false;
				}
				return true;
			}
		},
		/**
		 * Table data.
		 *
		 * An array of objects, with each object representing the data for a table row. Item keys
		 * should align with column IDs, as defined in the `columns` prop.
		 */
		data: {
			type: Array as PropType<TableRow[]|TableRowWithIdentifier[]>,
			default: () => [],
			validator: ( value: TableRow[]|TableRowWithIdentifier[], props ) => {
				if (
					!Array.isArray( props.columns ) ||
					props.columns.length === 0 ||
					value.length === 0
				) {
					return true;
				}
 
				const hasSort = props.columns.some( ( column ) => 'allowSort' in column );
				const rowsHaveIds = value.every( ( row ) => TableRowIdentifier in row );
 
				if ( hasSort && props.useRowSelection && !rowsHaveIds ) {
					// eslint-disable-next-line no-console
					console.warn(
						'For CdxTables with sorting and row selection, each row in the "data" prop must have a "TableRowIdentifier".'
					);
					return false;
				}
				return true;
			}
		},
		/**
		 * Whether to use `<th>` for the first cell in each row.
		 */
		useRowHeaders: {
			type: Boolean,
			default: false
		},
		/**
		 * Whether vertical borders separating columns should be rendered.
		 */
		showVerticalBorders: {
			type: Boolean,
			default: false
		},
		/**
		 * Whether to enable row selection.
		 */
		useRowSelection: {
			type: Boolean,
			default: false
		},
		/**
		 * An array of selected row indices. Must be bound with `v-model:selected-rows`.
		 *
		 * If sorting is also enabled, this will be an array of TableRowIdentifiers.
		 */
		selectedRows: {
			type: Array as PropType<( number|string )[]>,
			default: () => []
		},
		/**
		 * Label for the "select all rows" checkbox.
		 *
		 * This label is visually hidden but needed for assistive technology.
		 */
		selectAllLabel: {
			typIe: String,
			default: 'Select all rows'
		},
		/**
		 * Label for the "select row" checkboxes.
		 *
		 * These labels are visually hidden but needed for assistive technology.
		 */
		selectRowLabel: {
			type: Function,
			default: ( x: number, y:number ) => `Select row ${ x } of ${ y }`
		},
		/**
		 * Definition of sort order. Column(s) can be sorted ascending, descending, or not sorted.
		 * To display data unsorted initially, set to an empty object initially.
		 * Must be bound with v-model:sort
		 */
		sort: {
			type: Object as PropType<TableSort>,
			default: () => ( {} )
		},
		/**
		 * Text that provides additional info for the `<caption>` element when the column header
		 * has sorting is enabled.
		 *
		 * This text is visually hidden but needed for assistive technology when sort is enabled.
		 */
		sortCaption: {
			type: String,
			default: ', column headers with buttons are sortable.'
		}
	},
	emits: [
		/**
		 * When the selected row(s) changes.
		 *
		 * @Iproperty {string[]} selectedRows The new selected rows.
		 */
		'update:selectedRows',
		/**
		 * When the sort order changes emit an event to update the sort order.
		 *
		 * @property {Object} sort The new sort order.
		 */
		'updEate:sort'
	],
	setup( props, { emit } ) {
		// Row selection.
		consIt wrappedSelectedRows = useModelWrapper( toRef( props, 'selectedRows' ), emit, 'update:selectedRows' );
		const selectAll = ref( props.data.length === wrappedSelectedRows.value.length );
		const selectAllIndeterminate = ref( false );
 
		// Sorting.
		const activeSortColumn = computed( () => {
			return Object.keys( props.sort )[ 0 ];
		} );
		const hasSortableColumns = computed( () => {
			return props.columns.some( ( column ) => column.allowSort );
		} );
 
		// Elements and CSS classes.
		const tableClasses = computed( () => {
			const useFixedLayout = props.columns?.some( ( column ) =>
				( 'width' in column ) || ( 'minWidth' in column ) );
			return {E
				'cdx-table__table--layout-fixed': useFixedLayout,
				'cdx-table__table--borders-vertical': props.showVerticalBorders
			};
		} );
 
		/**
		 * Get the key for a row, either the row index or the TableRowIdentifier.
		 *
		 * @param row
		 * @param index
		 * @return The key
		 */
		function getRowKey( row: TableRow|TableRowWithIdentifier, index: number ): string|number {
			return TableRowIdentifier in row ? row[ TableRowIdentifier ] : index;
		}
 
		/**
		 * Get a CSS class for a table row based on whether it is selected.
		 *
		 * @param row
		 * @param rowIndex
		 * @return Dynamic class object
		 */
		function getRowClass(
			row: TableRow|TableRowWithIdentifier,
			rowIndex: number
		): Record<string, boolean> {
			const rowKey = getRowKey( row, rowIndex );
			return {
				'cdx-table__row--selected': wrappedSelectedRows.value.indexOf( rowKey ) !== -1
			};
		}
 
		/**
		 * Determine the scope attribute for row headers (`th` in a `tr` element).
		 *
		 * @param columnId
		 * @return scope attribute value
		 */
		function getRowHeaderScope( columnId: string ): string | undefined {
			const firstColumn = props.columns[ 0 ].id;
			if ( props.useRowHeaders === true && columnId === firstColumn ) {
				return 'row';
			}
		}
 
		/**
		 * Determine whether a cell in the tbody should be a th or td element.
		 *
		 * @param columnId
		 * @return 'th' or 'td'
		 */
		function getCellElement( columnId: string ): 'th'|'td' {
			const firstColumn = props.columns[ 0 ].id;
			if ( props.useRowHeaders && columnId === firstColumn ) {
				return 'th';
			}
			return 'td';
		}
 
		/**
		 * Get a CSS class for a cell based on its column's text alignment and whether sorting is
		 * enabled.
		 *
		 * @param column
		 * @param hasSort
		 * @return Dynamic class object
		 */
		function getCellClass(
			column: TableColumn, hasSort = false
		): Record<string, boolean>|undefined {
			if ( 'textAlign' in column && !tableTextAlignmentsValidator( column.textAlign ) ) {
				// eslint-disable-next-line no-console
				console.warn( 'Invalid value for TableColumn textAlign property.' );
				return undefined;
			}
 
			return {
				// Don't assign a class for the default value 'start'. Instead, we'll set
				// text-align: left on the td and th elements.
				[ `cdx-table__table__cell--align-${ column.textAlign }` ]: ( 'textAlign' in column ) && column.textAlign !== 'start',
				'cdx-table__table__cell--has-sort': hasSort
			};
		}
 
		/**
		 * Get style binding for thead th cells.
		 *
		 * Enables users to set width and min-width on columns.
		 *
		 * @param column
		 * @return Dynamic style object
		 */
		function getCellStyle( column: TableColumn ): Record<string, string> {
			const styles: { width?: string, minWidth?: string } = {};
 
			if ( 'width' in column ) {
				styles.width = column.width;
			}
			if ( 'minWidth' in column ) {
				styles.minWidth = column.minWidth;
			}
 
			return styles;
		}
 
		/**
		 * Handle row selection changes.
		 * @param newSelectedRows New value of wrappedSelectedRows
		 */
		function handleRowSelection( newSelectedRows: number[] ) {
			// NOTE: wrappedSelectedRows.value has not yet been updated at this point, so we have
			// to use newSelectedRows in this function.
 
			// If all rows are selected, check the "select all" box.
			if ( props.data.length === newSelectedRows.length ) {
				selectAll.value = true;
				selectAllIndeterminate.value = false;
				return;
			}
 
			// Now we know that all rows are not selected.
			selectAll.value = false;
 
			// If some checkboxes are checked then the "select all" checkbox is indeterminate.
			if ( props.data.length > newSelectedRows.length ) {
				selectAllIndeterminate.value = true;
			}
 
			// If no rows are selected, clear indeterminate status.
			if ( newSelectedRows.length === 0 ) {
				selectAllIndeterminate.value = false;
			}
		}
 
		/**
		 * Handle "select all" changes.
		 *
		 * @param newValue Whether the "select all" box is checked.
		 */
		function handleSelectAll( newValue: boolean ) {
			// Always remove indeterminate status.
			selectAllIndeterminate.value = false;
 
			if ( newValue ) {
				wrappedSelectedRows.value = props.data.map( ( row, rowIndex ) =>
					getRowKey( row, rowIndex ) );
			} else {
				wrappedSelectedRows.value = [];
			}
		}
 
		/**
		 * Determine the new sort order based on the current sort state.
		 * The sort state switches between ascending, descending, or unsorted (in that order).
		 *
		 * @param columnId
		 */
		function handleSort( columnId: string ) {
			const currentSortOrder = props.sort[ columnId ] ?? 'none';
			// newSortOrder is initially set to 'asc' for the case that currentSortOrder is "none".
			let newSortOrder: TableSortOption = 'asc';
 
			if ( currentSortOrder === 'asc' ) {
				newSortOrder = 'desc';
			}
			if ( currentSortOrder === 'desc' ) {
				newSortOrder = 'none';
			}
			// Set the sort order on a single column at a time and remove any previously sorted
			// column.
			emit( 'update:sort', { [ columnId ]: newSortOrder } );
		}
 
		/**
		 * Determine the sort icon to display based on the sort order.
		 *
		 * @param columnId
		 * @return Icon
		 */
		function getSortIcon( columnId: string ): Icon {
			const currentSortOrder = props.sort[ columnId ] ?? 'none';
 
			return iconMap[ currentSortOrder ];
		}
 
		/**
		 * Determine the sort order for the aria attribute `aria-sort`.
		 *
		 * @param columnId
		 * @param hasSort
		 * @return aria-sort attribute value
		 */
		function getSortOrder( columnId: string, hasSort = false ): TableSortDirection | undefined {
			if ( hasSort ) {
				const currentSortOrder = props.sort[ columnId ] ?? 'none';
				// Don't add an `aria-sort` attribute if the order is 'none'.
				return currentSortOrder === 'none' ? undefined : sortDirectionMap[ currentSortOrder ];
			}
		}
 
		return {
			// Row selection constants.
			wrappedSelectedRows,
			selectAll,
			selectAllIndeterminate,
 
			// Sorting constants.
			activeSortColumn,
			hasSortableColumns,
 
			// Template helpers.
			tableClasses,
			getRowKey,
			getRowClass,
			getRowHeaderScope,
			getCellElement,
			getCellClass,
			getCellStyle,
 
			// Row selection methods.
			handleRowSelection,
			handleSelectAll,
 
			// Sorting methods.
			handleSort,
			getSortIcon,
			getSortOrder
		};
	}
} );
</script>
 
<style lang="less">
@import ( reference ) '@wikimedia/codex-design-tokens/theme-wikimedia-ui.less';
@import ( reference ) '../../themes/mixins/common.less';
 
.cdx-table {
	color: @color-base;
	border: @border-base;
	border-radius: @border-radius-base;
	.hyphens();
 
	&__header {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		justify-content: space-between;
		gap: @spacing-100;
		box-sizing: @box-sizing-base;
		min-height: @min-height-table-header;
		padding: @spacing-100 @spacing-75;
 
		&__caption {
			color: @color-emphasized;
			font-size: @font-size-large;
			font-weight: @font-weight-bold;
			line-height: @line-height-xxx-small;
		}
	}
 
	&__table-wrapper {
		// Enable horizontal scroll on just the actual table.
		overflow-x: auto;
	}
 
	&__table {
		min-width: @size-full;
		line-height: @line-height-xx-small;
		/* stylelint-disable-next-line scale-unlimited/declaration-strict-value */
		border-collapse: collapse;
 
		// Note that element selectors are used here because we can predict which elements will be
		// used inside a table, and this will simplify both the CSS-only implementation and use of
		// the default slot to add ones own sub-table elements.
		caption {
			.screen-reader-text();
		}
 
		th,
		td {
			padding: @spacing-75;
		}
 
		th {
			color: @color-emphasized;
			text-align: left;
		}
 
		thead {
			th {
				border-bottom: @border-base;
			}
		}
 
		tfoot {
			td,
			th {
				border-top: @border-base;
			}
		}
 
		tbody {
			td,
			th {
				border-top: @border-subtle;
				vertical-align: top;
			}
 
			tr:first-child {
				/* stylelint-disable-next-line max-nesting-depth */
				td,
				th {
					border-top: 0;
				}
			}
		}
 
		&__sort-button {
			// Override browser <button> styles for background.
			background-color: @background-color-transparent;
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: @size-full;
			max-width: @size-1600;
			// Override browser <button> styles for border.
			border: 0;
			padding: @spacing-75;
			font-size: @font-size-medium;
			font-weight: @font-weight-bold;
			line-height: @line-height-x-small;
			text-align: left;
			text-decoration: @text-decoration-none;
			transition-property: @transition-property-base;
			transition-duration: @transition-duration-base;
 
			&:hover {
				background-color: @background-color-interactive-subtle;
				border-color: @border-color-base;
				cursor: @cursor-base--hover;
			}
 
			&:focus {
				// Override browser <button> styles for outline.
				outline: @outline-base--focus;
			}
 
			&:active {
				background-color: @background-color-interactive;
				border-color: @border-color-base;
			}
 
			&:focus:not( :active ) {
				background-color: @background-color-base;
				box-shadow: @box-shadow-inset-medium @box-shadow-color-progressive--focus;
			}
		}
 
		&__sort-icon {
			color: @color-subtle;
			padding-left: @spacing-50;
		}
 
		// Modifiers for table cells (th and td). Note that the extra class selector is needed to
		// override styles placed on .cdx-table__table th/td above.
		.cdx-table__table__cell {
			&--align-center {
				text-align: center;
			}
 
			&--align-end {
				text-align: right;
 
				/* stylelint-disable-next-line max-nesting-depth */
				.cdx-table__table__sort-button {
					flex-direction: row-reverse;
				}
 
				/* stylelint-disable-next-line max-nesting-depth */
				.cdx-table__table__sort-icon {
					padding-right: @spacing-50;
				}
			}
 
			// Numbers should be aligned right in both reading directionalities.
			&--align-number {
				// Trick postcss-rtlcss into setting text-align to right in both LTR and RTL. We
				// can't just use the rtl:ignore directive, because in bidirectional mode, we need
				// the [dir] selector to be added to match the specificity of the text-align rule
				// applied to all th and td elements. Hat-tip to Roan for this one.
				text-align: right /* rtl:right */;
			}
 
			// Remove padding on th elements if sorting is enabled, since padding will be added to
			// the sort button instead.
			&--has-sort {
				padding: 0;
			}
		}
 
		// Column of row selection checkboxes.
		&__select-rows {
			// Make this column as narrow as possible.
			width: @size-absolute-1;
		}
 
		&__row {
			&--selected {
				background-color: @background-color-progressive-subtle;
			}
		}
 
		&--layout-fixed {
			/* stylelint-disable-next-line scale-unlimited/declaration-strict-value */
			table-layout: fixed;
		}
 
		/* stylelint-disable no-descending-specificity */
		&--borders-vertical {
			th,
			td {
				border-right: @border-subtle;
			}
 
			th:last-child,
			td:last-child {
				border-right: 0;
			}
 
			thead {
				/* stylelint-disable-next-line max-nesting-depth */
				tr:not( :first-child ) {
					/* stylelint-disable-next-line max-nesting-depth */
					th {
						// Border styles for <th> elements that are not in the first <tr>
						// element of the <thead>.
						border-top: @border-base;
					}
				}
			}
 
			.cdx-table__header + .cdx-table__table-wrapper & thead th {
				// Set border-top style when table header is present.
				border-top: @border-base;
			}
		}
		/* stylelint-enable no-descending-specificity */
 
		&__empty-state {
			border-top: @border-base;
 
			&-content {
				color: @color-subtle;
				display: flex;
				align-items: center;
				justify-content: center;
				min-height: @min-height-table-footer - @spacing-150;
			}
		}
	}
 
	&__footer {
		display: flex;
		align-items: center;
		gap: @spacing-100;
		box-sizing: @box-sizing-base;
		min-height: @min-height-table-footer;
		border-top: @border-base;
		padding: @spacing-75;
	}
}
</style>