Small fixes in component API (#501)

This commit is contained in:
Thomas Brandého 2023-02-11 00:11:12 +01:00 committed by GitHub
parent 8265a85434
commit 315987c701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 8 deletions

View File

@ -33,15 +33,15 @@ class Alert(ChakraComponent):
The alert component. The alert component.
""" """
if len(children) == 0: if len(children) == 0:
contents = [] children = []
if icon: if icon:
contents.append(AlertIcon.create()) children.append(AlertIcon.create())
contents.append(AlertTitle.create(title)) children.append(AlertTitle.create(title))
if desc: if desc:
contents.append(AlertDescription.create(desc)) children.append(AlertDescription.create(desc))
return super().create(*children, **props) return super().create(*children, **props)

View File

@ -1,5 +1,6 @@
"""Container to stack elements with spacing.""" """Container to stack elements with spacing."""
from pynecone.components.component import Component
from pynecone.components.libs.chakra import ChakraComponent from pynecone.components.libs.chakra import ChakraComponent
from pynecone.var import Var from pynecone.var import Var
@ -33,6 +34,25 @@ class CircularProgress(ChakraComponent):
# The desired valueText to use in place of the value. # The desired valueText to use in place of the value.
value_text: Var[str] value_text: Var[str]
@classmethod
def create(cls, *children, label=None, **props) -> Component:
"""Create a circular progress component.
Args:
children: the children of the component.
label: A label to add in the circular progress. Defaults to None.
props: the props of the component.
Returns:
The circular progress component.
"""
if len(children) == 0:
children = []
if label:
children.append(CircularProgressLabel.create(label))
return super().create(*children, **props)
class CircularProgressLabel(ChakraComponent): class CircularProgressLabel(ChakraComponent):
"""Label of CircularProcess.""" """Label of CircularProcess."""

View File

@ -70,22 +70,26 @@ class Menu(ChakraComponent):
return super().get_triggers() | {"on_close", "on_open"} return super().get_triggers() | {"on_close", "on_open"}
@classmethod @classmethod
def create(cls, *children, items=None, **props) -> Component: def create(cls, *children, button=None, items=None, **props) -> Component:
"""Create a menu component. """Create a menu component.
Args: Args:
children: The children of the component. children: The children of the component.
items (list): The item of the menu. button: the button that open the menu.
items (list): The items of the menu.
props: The properties of the component. props: The properties of the component.
Returns: Returns:
The menu component. The menu component.
""" """
if len(children) == 0: if len(children) == 0:
button = MenuButton.create(*props.pop("button")) children = []
if button:
children.append(MenuButton.create(button))
if not items: if not items:
items = [] items = []
children = [button, MenuList.create(*items)] children.append(MenuList.create(*items))
return super().create(*children, **props) return super().create(*children, **props)