Support vars for select and radio (#107)
This commit is contained in:
parent
a9afe819db
commit
622a8ef3c2
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user