# All files Table.tsx

100% Statements 124/124
100% Branches 2/2
100% Functions 1/1
100% Lines 124/124

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
    1251x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    9x
    9x
    9x
    9x
    9x
    9x
    9x
    9x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    17x
    1x
     "use client";
    import { forwardRef, useMemo, type TableHTMLAttributes } from "react";
    import {
      TableConfigProvider,
      type TableConfigContext,
      type TableConfiguration,
    } from "./TableConfigurationProvider.js";
    import { table } from "./tableStyles.js";

    declare module "react" {
      interface CSSProperties {
        "--rmd-table-background-color"?: string;
        "--rmd-table-border-size"?: string | number;
        "--rmd-table-border-color"?: string;
        "--rmd-table-header-background-color"?: string;
        "--rmd-table-cell-color"?: string;
        "--rmd-table-cell-height"?: string | number;
        "--rmd-table-cell-horizontal-padding"?: string | number;
        "--rmd-table-cell-vertical-padding"?: string | number;
        "--rmd-table-header-cell-height"?: string | number;
        "--rmd-table-hover-color"?: string;
        "--rmd-table-selected-color"?: string;
        "--rmd-table-sticky-cell"?: string | number;
        "--rmd-table-sticky-header"?: string | number;
        "--rmd-table-sticky-footer"?: string | number;
        "--rmd-table-sticky-background-color"?: string;
      }
    }

    export interface TableProps
      extends TableHTMLAttributes<HTMLTableElement>,
        TableConfiguration {}

    /**
     * **Client Component**
     *
     * @example
     * Responsive Example
     * ```tsx
     * import {
     *   Table,
     *   TableBody,
     *   TableCell,
     *   TableContainer,
     *   TableHeader,
     *   TableRow,
     * } from "@react-md/core";
     * import type { ReactElement } from "react";
     *
     * function Example(): ReactElement {
     *   return (
     *     <TableContainer>
     *       <Table>
     *         <TableHeader>
     *           <TableRow>
     *             <TableCell>Header 1</TableCell>
     *             <TableCell>Header 2</TableCell>
     *             <TableCell>Header 3</TableCell>
     *           </TableRow>
     *         </TableHeader>
     *         <TableBody>
     *           <TableRow>
     *             <TableCell>Row 1 Cell 1</TableCell>
     *             <TableCell>Row 1 Cell 2</TableCell>
     *             <TableCell>Row 1 Cell 3</TableCell>
     *           </TableRow>
     *           <TableRow>
     *             <TableCell>Row 2 Cell 1</TableCell>
     *             <TableCell>Row 2 Cell 2</TableCell>
     *             <TableCell>Row 2 Cell 3</TableCell>
     *           </TableRow>
     *           <TableRow>
     *             <TableCell>Row 3 Cell 1</TableCell>
     *             <TableCell>Row 3 Cell 2</TableCell>
     *             <TableCell>Row 3 Cell 3</TableCell>
     *           </TableRow>
     *         </TableBody>
     *       </Table>
     *     </TableContainer>
     *   );
     * }
     * ```
     */
    export const Table = forwardRef<HTMLTableElement, TableProps>(
      function Table(props, ref) {
        const {
          className,
          children,
          dense = false,
          hAlign = "left",
          vAlign = "middle",
          lineWrap = false,
          fullWidth = false,
          disableHover = false,
          disableBorders = false,
          ...remaining
        } = props;

        const configuration = useMemo<TableConfigContext>(
          () => ({
            dense,
            header: false,
            hAlign,
            vAlign,
            lineWrap,
            disableHover,
            disableBorders,
          }),
          [dense, hAlign, vAlign, lineWrap, disableHover, disableBorders]
        );

        return (
          <TableConfigProvider value={configuration}>
            <table
              {...remaining}
              ref={ref}
              className={table({ dense, fullWidth, className })}
            >
              {children}
            </table>
          </TableConfigProvider>
        );
      }
    );