|
| 1 | +from dataclasses import dataclass |
| 2 | +from typing import List, Literal, TypedDict, Optional, Dict, Union |
| 3 | +from chartlets import Component |
| 4 | + |
| 5 | + |
| 6 | +class TableCellProps(TypedDict, total=False): |
| 7 | + """Represents common properties of a table cell.""" |
| 8 | + |
| 9 | + id: str | int | float |
| 10 | + """The unique identifier for the cell.""" |
| 11 | + |
| 12 | + size: Literal['medium', 'small'] | str | None |
| 13 | + """The size of the cell.""" |
| 14 | + |
| 15 | + align: Literal["inherit", "left", "center", "right", "justify"] | None |
| 16 | + """The alignment of the cell content.""" |
| 17 | + |
| 18 | + |
| 19 | +class TableColumn(TableCellProps): |
| 20 | + """Defines a column in the table.""" |
| 21 | + |
| 22 | + label: str |
| 23 | + """The display label for the column header.""" |
| 24 | + |
| 25 | + |
| 26 | +class TableRowData(TableCellProps): |
| 27 | + """Defines a row in the table.""" |
| 28 | + |
| 29 | + data: dict[str, Union[str, int, float, bool, None]] |
| 30 | + """The data for the row, as a dictionary where keys are the column ids.""" |
| 31 | + |
| 32 | + |
| 33 | +@dataclass(frozen=True) |
| 34 | +class Table(Component): |
| 35 | + """A basic Table with configurable rows and columns.""" |
| 36 | + |
| 37 | + columns: list[TableColumn] | None = None |
| 38 | + """The columns to display in the table.""" |
| 39 | + |
| 40 | + rows: list[TableRowData] | None = None |
| 41 | + """The rows of data to display in the table.""" |
| 42 | + |
| 43 | + hover: bool | None = None |
| 44 | + """A boolean indicating whether to highlight a row when hovered over""" |
0 commit comments