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 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.core.cond import Cond, color_mode_cond, cond

View File

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

View File

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

View File

@ -35,7 +35,6 @@ class BaseList(Component):
def create( # type: ignore
cls,
*children,
items: Optional[Union[Iterable, Var[Iterable]]] = None,
list_style_type: Optional[
Union[
Literal[
@ -78,6 +77,12 @@ class BaseList(Component):
],
]
] = None,
items: Optional[
Union[
Union[Iterable, Var[Iterable]],
Var[Optional[Union[Iterable, Var[Iterable]]]],
]
] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
@ -105,8 +110,8 @@ class BaseList(Component):
Args:
*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".
items: A list of items to add to the list.
style: The style of the component.
key: A unique key for the component.
id: The id for the component.
@ -178,7 +183,7 @@ class UnorderedList(BaseList, Ul):
on_unmount: Optional[EventType[[]]] = None,
**props,
) -> "UnorderedList":
"""Create a unordered list component.
"""Create an unordered list component.
Args:
*children: The children of the component.
@ -220,8 +225,50 @@ class OrderedList(BaseList, Ol):
def create( # type: ignore
cls,
*children,
items: Optional[Union[Iterable, Var[Iterable]]] = None,
list_style_type: Optional[LiteralListStyleTypeOrdered] = "decimal",
list_style_type: Optional[
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,
start: 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:
*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.
list_style_type: The style of the list.
reversed: Reverses the order of the 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).
@ -406,7 +453,6 @@ class List(ComponentNamespace):
@staticmethod
def __call__(
*children,
items: Optional[Union[Iterable, Var[Iterable]]] = None,
list_style_type: Optional[
Union[
Literal[
@ -449,6 +495,12 @@ class List(ComponentNamespace):
],
]
] = None,
items: Optional[
Union[
Union[Iterable, Var[Iterable]],
Var[Optional[Union[Iterable, Var[Iterable]]]],
]
] = None,
style: Optional[Style] = None,
key: Optional[Any] = None,
id: Optional[Any] = None,
@ -476,8 +528,8 @@ class List(ComponentNamespace):
Args:
*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".
items: A list of items to add to the list.
style: The style of the component.
key: A unique key for the component.
id: The id for the component.