Add var support pc.list (#636)

This commit is contained in:
Xiaojing Chen 2023-03-11 05:09:59 +08:00 committed by GitHub
parent 3bf7d1f722
commit e926460bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
"""List components."""
from pynecone.components import Component
from pynecone.components.layout.foreach import Foreach
from pynecone.components.libs.chakra import ChakraComponent
from pynecone.var import Var
@ -32,9 +33,10 @@ class List(ChakraComponent):
The list component.
"""
if len(children) == 0:
children = []
for item in items or []:
children.append(ListItem.create(item))
if isinstance(items, Var):
children = [Foreach.create(items, ListItem.create)]
else:
children = [ListItem.create(item) for item in items or []]
return super().create(*children, **props)