fix chakra list, allow Tag.tag to be None in validation

This commit is contained in:
Benedikt Bartscher 2024-03-05 21:53:44 +01:00
parent 16a7c1ff51
commit 6d96a94d82
No known key found for this signature in database
2 changed files with 15 additions and 6 deletions

View File

@ -1,17 +1,14 @@
"""List components.""" """List components."""
from __future__ import annotations from __future__ import annotations
from typing import Generic, Optional, TypeVar from typing import Optional
from reflex.components.chakra import ChakraComponent from reflex.components.chakra import ChakraComponent
from reflex.components.component import Component from reflex.components.component import Component
from reflex.components.core.foreach import Foreach from reflex.components.core.foreach import Foreach
from reflex.vars import Var from reflex.vars import Var
T = TypeVar("T") class List(ChakraComponent):
# TODO: Generic is just a hacky workaround to stop pydantic from complaining
class List(ChakraComponent, Generic[T]):
"""Display a list of items.""" """Display a list of items."""
tag: str = "List" tag: str = "List"
@ -25,6 +22,18 @@ class List(ChakraComponent, Generic[T]):
# Shorthand prop for listStyleType # Shorthand prop for listStyleType
style_type: Optional[Var[str]] = None style_type: Optional[Var[str]] = None
@classmethod
def __class_getitem__(cls, item):
"""This method is just a hacky workaround to stop pydantic v2 from complaining.
Args:
item: The type of the list items.
Returns:
The list component.
"""
return cls
@classmethod @classmethod
def create( def create(
cls, *children, items: list | Var[list] | None = None, **props cls, *children, items: list | Var[list] | None = None, **props

View File

@ -14,7 +14,7 @@ class Tag(Base):
"""A React tag.""" """A React tag."""
# The name of the tag. # The name of the tag.
name: str = "" name: str | None = ""
# The props of the tag. # The props of the tag.
props: Dict[str, Any] = {} props: Dict[str, Any] = {}