|
@@ -5,6 +5,8 @@ from typing import Iterable, Literal, Optional, Union
|
|
from reflex.components.component import Component, ComponentNamespace
|
|
from reflex.components.component import Component, ComponentNamespace
|
|
from reflex.components.core.foreach import Foreach
|
|
from reflex.components.core.foreach import Foreach
|
|
from reflex.components.el.elements.typography import Li
|
|
from reflex.components.el.elements.typography import Li
|
|
|
|
+from reflex.components.lucide.icon import Icon
|
|
|
|
+from reflex.components.radix.themes.typography.text import Text
|
|
from reflex.style import Style
|
|
from reflex.style import Style
|
|
from reflex.vars import Var
|
|
from reflex.vars import Var
|
|
|
|
|
|
@@ -39,12 +41,16 @@ LiteralListStyleTypeOrdered = Literal[
|
|
class BaseList(Flex, LayoutComponent):
|
|
class BaseList(Flex, LayoutComponent):
|
|
"""Base class for ordered and unordered lists."""
|
|
"""Base class for ordered and unordered lists."""
|
|
|
|
|
|
|
|
+ # The style of the list. Default to "none".
|
|
|
|
+ list_style_type: Var[
|
|
|
|
+ Union[LiteralListStyleTypeUnordered, LiteralListStyleTypeOrdered]
|
|
|
|
+ ]
|
|
|
|
+
|
|
@classmethod
|
|
@classmethod
|
|
def create(
|
|
def create(
|
|
cls,
|
|
cls,
|
|
*children,
|
|
*children,
|
|
items: Optional[Union[Var[Iterable], Iterable]] = None,
|
|
items: Optional[Union[Var[Iterable], Iterable]] = None,
|
|
- list_style_type: str = "",
|
|
|
|
**props,
|
|
**props,
|
|
):
|
|
):
|
|
"""Create a list component.
|
|
"""Create a list component.
|
|
@@ -52,21 +58,23 @@ class BaseList(Flex, LayoutComponent):
|
|
Args:
|
|
Args:
|
|
*children: The children of the component.
|
|
*children: The children of the component.
|
|
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.
|
|
|
|
**props: The properties of the component.
|
|
**props: The properties of the component.
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
The list component.
|
|
The list component.
|
|
|
|
+
|
|
"""
|
|
"""
|
|
|
|
+ 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)]
|
|
else:
|
|
else:
|
|
children = [ListItem.create(item) for item in items]
|
|
children = [ListItem.create(item) for item in items]
|
|
- props["list_style_type"] = list_style_type
|
|
|
|
|
|
+ # props["list_style_type"] = list_style_type
|
|
props["direction"] = "column"
|
|
props["direction"] = "column"
|
|
style = props.setdefault("style", {})
|
|
style = props.setdefault("style", {})
|
|
style["list_style_position"] = "outside"
|
|
style["list_style_position"] = "outside"
|
|
|
|
+ style["list_style_type"] = list_style_type
|
|
if "gap" in props:
|
|
if "gap" in props:
|
|
style["gap"] = props["gap"]
|
|
style["gap"] = props["gap"]
|
|
return super().create(*children, **props)
|
|
return super().create(*children, **props)
|
|
@@ -102,6 +110,7 @@ class UnorderedList(BaseList):
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
The list component.
|
|
The list component.
|
|
|
|
+
|
|
"""
|
|
"""
|
|
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
|
|
@@ -129,6 +138,7 @@ class OrderedList(BaseList):
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
The list component.
|
|
The list component.
|
|
|
|
+
|
|
"""
|
|
"""
|
|
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
|
|
@@ -138,7 +148,24 @@ class OrderedList(BaseList):
|
|
class ListItem(Li):
|
|
class ListItem(Li):
|
|
"""Display an item of an ordered or unordered list."""
|
|
"""Display an item of an ordered or unordered list."""
|
|
|
|
|
|
- ...
|
|
|
|
|
|
+ @classmethod
|
|
|
|
+ def create(cls, *children, **props):
|
|
|
|
+ """Create a list item component.
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ *children: The children of the component.
|
|
|
|
+ **props: The properties of the component.
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ The list item component.
|
|
|
|
+
|
|
|
|
+ """
|
|
|
|
+ for child in children:
|
|
|
|
+ if isinstance(child, Text):
|
|
|
|
+ child.as_ = "span"
|
|
|
|
+ elif isinstance(child, Icon) and "display" not in child.style:
|
|
|
|
+ child.style["display"] = "inline"
|
|
|
|
+ return super().create(*children, **props)
|
|
|
|
|
|
|
|
|
|
class List(ComponentNamespace):
|
|
class List(ComponentNamespace):
|