Skip to content

Commit

Permalink
[GTM-648]Add Missing Table props (#4322)
Browse files Browse the repository at this point in the history
* Add Missing Table props

* add more props
  • Loading branch information
ElijahAhianyo authored Nov 8, 2024
1 parent 227d09a commit 855a20f
Show file tree
Hide file tree
Showing 6 changed files with 566 additions and 94 deletions.
26 changes: 26 additions & 0 deletions reflex/components/radix/themes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, Dict, Literal

from reflex.components import Component
from reflex.components.core.breakpoints import Responsive
from reflex.components.tags import Tag
from reflex.config import get_config
from reflex.utils.imports import ImportDict, ImportVar
Expand Down Expand Up @@ -74,6 +75,31 @@ class CommonMarginProps(Component):
ml: Var[LiteralSpacing]


class CommonPaddingProps(Component):
"""Many radix-themes elements accept shorthand padding props."""

# Padding: "0" - "9"
p: Var[Responsive[LiteralSpacing]]

# Padding horizontal: "0" - "9"
px: Var[Responsive[LiteralSpacing]]

# Padding vertical: "0" - "9"
py: Var[Responsive[LiteralSpacing]]

# Padding top: "0" - "9"
pt: Var[Responsive[LiteralSpacing]]

# Padding right: "0" - "9"
pr: Var[Responsive[LiteralSpacing]]

# Padding bottom: "0" - "9"
pb: Var[Responsive[LiteralSpacing]]

# Padding left: "0" - "9"
pl: Var[Responsive[LiteralSpacing]]


class RadixLoadingProp(Component):
"""Base class for components that can be in a loading state."""

Expand Down
173 changes: 173 additions & 0 deletions reflex/components/radix/themes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Dict, Literal, Optional, Union, overload

from reflex.components import Component
from reflex.components.core.breakpoints import Breakpoints
from reflex.event import BASE_STATE, EventType
from reflex.style import Style
from reflex.utils.imports import ImportDict
Expand Down Expand Up @@ -144,6 +145,178 @@ class CommonMarginProps(Component):
"""
...

class CommonPaddingProps(Component):
@overload
@classmethod
def create( # type: ignore
cls,
*children,
p: Optional[
Union[
Breakpoints[
str, Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
Var[
Union[
Breakpoints[
str,
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
]
],
]
] = None,
px: Optional[
Union[
Breakpoints[
str, Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
Var[
Union[
Breakpoints[
str,
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
]
],
]
] = None,
py: Optional[
Union[
Breakpoints[
str, Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
Var[
Union[
Breakpoints[
str,
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
]
],
]
] = None,
pt: Optional[
Union[
Breakpoints[
str, Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
Var[
Union[
Breakpoints[
str,
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
]
],
]
] = None,
pr: Optional[
Union[
Breakpoints[
str, Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
Var[
Union[
Breakpoints[
str,
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
]
],
]
] = None,
pb: Optional[
Union[
Breakpoints[
str, Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
Var[
Union[
Breakpoints[
str,
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
]
],
]
] = None,
pl: Optional[
Union[
Breakpoints[
str, Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
Var[
Union[
Breakpoints[
str,
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
],
Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
]
],
]
] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
class_name: Optional[Any] = None,
autofocus: Optional[bool] = None,
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
on_blur: Optional[EventType[[], BASE_STATE]] = None,
on_click: Optional[EventType[[], BASE_STATE]] = None,
on_context_menu: Optional[EventType[[], BASE_STATE]] = None,
on_double_click: Optional[EventType[[], BASE_STATE]] = None,
on_focus: Optional[EventType[[], BASE_STATE]] = None,
on_mount: Optional[EventType[[], BASE_STATE]] = None,
on_mouse_down: Optional[EventType[[], BASE_STATE]] = None,
on_mouse_enter: Optional[EventType[[], BASE_STATE]] = None,
on_mouse_leave: Optional[EventType[[], BASE_STATE]] = None,
on_mouse_move: Optional[EventType[[], BASE_STATE]] = None,
on_mouse_out: Optional[EventType[[], BASE_STATE]] = None,
on_mouse_over: Optional[EventType[[], BASE_STATE]] = None,
on_mouse_up: Optional[EventType[[], BASE_STATE]] = None,
on_scroll: Optional[EventType[[], BASE_STATE]] = None,
on_unmount: Optional[EventType[[], BASE_STATE]] = None,
**props,
) -> "CommonPaddingProps":
"""Create the component.
Args:
*children: The children of the component.
p: Padding: "0" - "9"
px: Padding horizontal: "0" - "9"
py: Padding vertical: "0" - "9"
pt: Padding top: "0" - "9"
pr: Padding right: "0" - "9"
pb: Padding bottom: "0" - "9"
pl: Padding left: "0" - "9"
style: The style of the component.
key: A unique key for the component.
id: The id for the component.
class_name: The class name for the component.
autofocus: Whether the component should take the focus once the page is loaded
custom_attrs: custom attribute
**props: The props of the component.
Returns:
The component.
"""
...

class RadixLoadingProp(Component):
@overload
@classmethod
Expand Down
24 changes: 21 additions & 3 deletions reflex/components/radix/themes/components/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from reflex.components.el import elements
from reflex.vars.base import Var

from ..base import RadixThemesComponent
from ..base import CommonPaddingProps, RadixThemesComponent


class TableRoot(elements.Table, RadixThemesComponent):
Expand Down Expand Up @@ -51,6 +51,12 @@ class TableColumnHeaderCell(elements.Th, RadixThemesComponent):
# The justification of the column
justify: Var[Literal["start", "center", "end"]]

# The minimum width of the cell
min_width: Var[Responsive[str]]

# The maximum width of the cell
max_width: Var[Responsive[str]]

_invalid_children: List[str] = [
"TableBody",
"TableHeader",
Expand All @@ -76,14 +82,20 @@ class TableBody(elements.Tbody, RadixThemesComponent):
_valid_parents: List[str] = ["TableRoot"]


class TableCell(elements.Td, RadixThemesComponent):
class TableCell(elements.Td, CommonPaddingProps, RadixThemesComponent):
"""A cell containing data."""

tag = "Table.Cell"

# The justification of the column
justify: Var[Literal["start", "center", "end"]]

# The minimum width of the cell
min_width: Var[Responsive[str]]

# The maximum width of the cell
max_width: Var[Responsive[str]]

_invalid_children: List[str] = [
"TableBody",
"TableHeader",
Expand All @@ -93,14 +105,20 @@ class TableCell(elements.Td, RadixThemesComponent):
]


class TableRowHeaderCell(elements.Th, RadixThemesComponent):
class TableRowHeaderCell(elements.Th, CommonPaddingProps, RadixThemesComponent):
"""A table cell that is semantically treated as a row header."""

tag = "Table.RowHeaderCell"

# The justification of the column
justify: Var[Literal["start", "center", "end"]]

# The minimum width of the cell
min_width: Var[Responsive[str]]

# The maximum width of the cell
max_width: Var[Responsive[str]]

_invalid_children: List[str] = [
"TableBody",
"TableHeader",
Expand Down
Loading

0 comments on commit 855a20f

Please sign in to comment.