This commit is contained in:
Elijah 2024-10-17 16:15:04 +00:00
parent 9bf53eb43a
commit 5862672794
4 changed files with 78 additions and 18 deletions

View File

@ -17,7 +17,7 @@ rx.text(
from __future__ import annotations from __future__ import annotations
from typing import Dict, List, Literal, get_args, Optional from typing import Dict, List, Literal, Optional, get_args
from reflex.components.component import BaseComponent from reflex.components.component import BaseComponent
from reflex.components.core.cond import Cond, color_mode_cond, cond from reflex.components.core.cond import Cond, color_mode_cond, cond

View File

@ -1,6 +1,6 @@
"""Interactive components provided by @radix-ui/themes.""" """Interactive components provided by @radix-ui/themes."""
from typing import List, Literal, Union from typing import List, Literal
import reflex as rx import reflex as rx
from reflex.components.component import Component, ComponentNamespace from reflex.components.component import Component, ComponentNamespace

View File

@ -44,27 +44,30 @@ class BaseList(Component):
# The style of the list. Default to "none". # The style of the list. Default to "none".
list_style_type: Var[ list_style_type: Var[
Union[LiteralListStyleTypeUnordered, LiteralListStyleTypeOrdered] Union[LiteralListStyleTypeUnordered, LiteralListStyleTypeOrdered]
] ] = Var.create("none")
# A list of items to add to the list.
items: Var[Optional[Var[Iterable]]] = None
@classmethod @classmethod
def create( def create(
cls, cls,
*children, *children,
items: Optional[Var[Iterable]] = None,
**props, **props,
): ):
"""Create a list component. """Create a list component.
Args: Args:
*children: The children of the component. *children: The children of the component.
items: A list of items to add to the list.
**props: The properties of the component. **props: The properties of the component.
Returns: Returns:
The list component. The list component.
""" """
items = props.pop("items", None)
list_style_type = props.pop("list_style_type", "none") list_style_type = props.pop("list_style_type", "none")
if not children and items is not None: if not children and items is not None:
if isinstance(items, Var): if isinstance(items, Var):
children = [Foreach.create(items, ListItem.create)] children = [Foreach.create(items, ListItem.create)]
@ -87,6 +90,9 @@ class BaseList(Component):
"direction": "column", "direction": "column",
} }
def _exclude_props(self) -> list[str]:
return ["items"]
class UnorderedList(BaseList, Ul): class UnorderedList(BaseList, Ul):
"""Display an unordered list.""" """Display an unordered list."""
@ -101,7 +107,7 @@ class UnorderedList(BaseList, Ul):
list_style_type: LiteralListStyleTypeUnordered = "disc", list_style_type: LiteralListStyleTypeUnordered = "disc",
**props, **props,
): ):
"""Create a unordered list component. """Create an unordered list component.
Args: Args:
*children: The children of the component. *children: The children of the component.
@ -124,26 +130,28 @@ class OrderedList(BaseList, Ol):
tag = "ol" tag = "ol"
# The style of the list.
list_style_type: Var[LiteralListStyleTypeOrdered] = "decimal"
@classmethod @classmethod
def create( def create(
cls, cls,
*children, *children,
items: Optional[Var[Iterable]] = None,
list_style_type: LiteralListStyleTypeOrdered = "decimal",
**props, **props,
): ):
"""Create an ordered list component. """Create an ordered list component.
Args: Args:
*children: The children of the component. *children: The children of the component.
items: A list of items to add to the list.
list_style_type: The style of the list.
**props: The properties of the component. **props: The properties of the component.
Returns: Returns:
The list component. The list component.
""" """
items = props.pop("items", None)
list_style_type = props.pop("list_style_type", "decimal")
props["margin_left"] = props.get("margin_left", "1.5rem") props["margin_left"] = props.get("margin_left", "1.5rem")
return super().create( return super().create(
*children, items=items, list_style_type=list_style_type, **props *children, items=items, list_style_type=list_style_type, **props

View File

@ -35,7 +35,6 @@ class BaseList(Component):
def create( # type: ignore def create( # type: ignore
cls, cls,
*children, *children,
items: Optional[Union[Iterable, Var[Iterable]]] = None,
list_style_type: Optional[ list_style_type: Optional[
Union[ Union[
Literal[ Literal[
@ -78,6 +77,12 @@ class BaseList(Component):
], ],
] ]
] = None, ] = None,
items: Optional[
Union[
Union[Iterable, Var[Iterable]],
Var[Optional[Union[Iterable, Var[Iterable]]]],
]
] = None,
style: Optional[Style] = None, style: Optional[Style] = None,
key: Optional[Any] = None, key: Optional[Any] = None,
id: Optional[Any] = None, id: Optional[Any] = None,
@ -105,8 +110,8 @@ class BaseList(Component):
Args: Args:
*children: The children of the component. *children: The children of the component.
items: A list of items to add to the list.
list_style_type: The style of the list. Default to "none". list_style_type: The style of the list. Default to "none".
items: A list of items to add to the list.
style: The style of the component. style: The style of the component.
key: A unique key for the component. key: A unique key for the component.
id: The id for the component. id: The id for the component.
@ -178,7 +183,7 @@ class UnorderedList(BaseList, Ul):
on_unmount: Optional[EventType[[]]] = None, on_unmount: Optional[EventType[[]]] = None,
**props, **props,
) -> "UnorderedList": ) -> "UnorderedList":
"""Create a unordered list component. """Create an unordered list component.
Args: Args:
*children: The children of the component. *children: The children of the component.
@ -220,8 +225,50 @@ class OrderedList(BaseList, Ol):
def create( # type: ignore def create( # type: ignore
cls, cls,
*children, *children,
items: Optional[Union[Iterable, Var[Iterable]]] = None, list_style_type: Optional[
list_style_type: Optional[LiteralListStyleTypeOrdered] = "decimal", Union[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
],
Var[
Literal[
"armenian",
"decimal",
"decimal-leading-zero",
"georgian",
"hiragana",
"katakana",
"lower-alpha",
"lower-greek",
"lower-latin",
"lower-roman",
"none",
"upper-alpha",
"upper-latin",
"upper-roman",
]
],
]
] = None,
items: Optional[
Union[
Union[Iterable, Var[Iterable]],
Var[Optional[Union[Iterable, Var[Iterable]]]],
]
] = None,
reversed: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, reversed: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
start: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, start: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
type: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, type: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None,
@ -276,8 +323,8 @@ class OrderedList(BaseList, Ol):
Args: Args:
*children: The children of the component. *children: The children of the component.
list_style_type: The style of the list. Default to "none".
items: A list of items to add to the list. items: A list of items to add to the list.
list_style_type: The style of the list.
reversed: Reverses the order of the list. reversed: Reverses the order of the list.
start: Specifies the start value of the first list item in an ordered list. start: Specifies the start value of the first list item in an ordered list.
type: Specifies the kind of marker to use in the list (letters or numbers). type: Specifies the kind of marker to use in the list (letters or numbers).
@ -406,7 +453,6 @@ class List(ComponentNamespace):
@staticmethod @staticmethod
def __call__( def __call__(
*children, *children,
items: Optional[Union[Iterable, Var[Iterable]]] = None,
list_style_type: Optional[ list_style_type: Optional[
Union[ Union[
Literal[ Literal[
@ -449,6 +495,12 @@ class List(ComponentNamespace):
], ],
] ]
] = None, ] = None,
items: Optional[
Union[
Union[Iterable, Var[Iterable]],
Var[Optional[Union[Iterable, Var[Iterable]]]],
]
] = None,
style: Optional[Style] = None, style: Optional[Style] = None,
key: Optional[Any] = None, key: Optional[Any] = None,
id: Optional[Any] = None, id: Optional[Any] = None,
@ -476,8 +528,8 @@ class List(ComponentNamespace):
Args: Args:
*children: The children of the component. *children: The children of the component.
items: A list of items to add to the list.
list_style_type: The style of the list. Default to "none". list_style_type: The style of the list. Default to "none".
items: A list of items to add to the list.
style: The style of the component. style: The style of the component.
key: A unique key for the component. key: A unique key for the component.
id: The id for the component. id: The id for the component.