Support vars for select and radio (#107)

This commit is contained in:
Nikhil Rao 2022-12-15 00:22:13 -08:00 committed by GitHub
parent a9afe819db
commit 622a8ef3c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -1,9 +1,11 @@
"""A radio component."""
from typing import Any, Set
from typing import Any, List, Set
from pynecone import utils
from pynecone.components.component import Component
from pynecone.components.layout.foreach import Foreach
from pynecone.components.libs.chakra import ChakraComponent
from pynecone.components.typography.text import Text
from pynecone.var import Var
@ -39,6 +41,12 @@ class RadioGroup(ChakraComponent):
"""
if len(children) == 1 and isinstance(children[0], list):
children = [Radio.create(child) for child in children[0]]
if (
len(children) == 1
and isinstance(children[0], Var)
and utils._issubclass(children[0].type_, List)
):
children = [Foreach.create(children[0], lambda item: Radio.create(item))]
return super().create(*children, **props)

View File

@ -1,11 +1,11 @@
"""A select component."""
from typing import Any, Set
from typing import Any, List, Set
from pynecone import utils
from pynecone.components.component import EVENT_ARG, Component
from pynecone.components.layout.foreach import Foreach
from pynecone.components.libs.chakra import ChakraComponent
from pynecone.components.tags import Tag
from pynecone.components.typography.text import Text
from pynecone.var import Var
@ -79,6 +79,12 @@ class Select(ChakraComponent):
"""
if len(children) == 1 and isinstance(children[0], list):
children = [Option.create(child) for child in children[0]]
if (
len(children) == 1
and isinstance(children[0], Var)
and utils._issubclass(children[0].type_, List)
):
children = [Foreach.create(children[0], lambda item: Option.create(item))]
return super().create(*children, **props)