Add var support pc.list (#636)
This commit is contained in:
parent
3bf7d1f722
commit
e926460bf7
@ -1,6 +1,7 @@
|
|||||||
"""List components."""
|
"""List components."""
|
||||||
|
|
||||||
from pynecone.components import Component
|
from pynecone.components import Component
|
||||||
|
from pynecone.components.layout.foreach import Foreach
|
||||||
from pynecone.components.libs.chakra import ChakraComponent
|
from pynecone.components.libs.chakra import ChakraComponent
|
||||||
from pynecone.var import Var
|
from pynecone.var import Var
|
||||||
|
|
||||||
@ -32,9 +33,10 @@ class List(ChakraComponent):
|
|||||||
The list component.
|
The list component.
|
||||||
"""
|
"""
|
||||||
if len(children) == 0:
|
if len(children) == 0:
|
||||||
children = []
|
if isinstance(items, Var):
|
||||||
for item in items or []:
|
children = [Foreach.create(items, ListItem.create)]
|
||||||
children.append(ListItem.create(item))
|
else:
|
||||||
|
children = [ListItem.create(item) for item in items or []]
|
||||||
return super().create(*children, **props)
|
return super().create(*children, **props)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user