From 315987c701325bf999a3ebeb579587fabc82e606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brand=C3=A9ho?= Date: Sat, 11 Feb 2023 00:11:12 +0100 Subject: [PATCH] Small fixes in component API (#501) --- pynecone/components/feedback/alert.py | 8 ++++---- .../components/feedback/circularprogress.py | 20 +++++++++++++++++++ pynecone/components/overlay/menu.py | 12 +++++++---- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/pynecone/components/feedback/alert.py b/pynecone/components/feedback/alert.py index d5935eeb5..aeaa594ac 100644 --- a/pynecone/components/feedback/alert.py +++ b/pynecone/components/feedback/alert.py @@ -33,15 +33,15 @@ class Alert(ChakraComponent): The alert component. """ if len(children) == 0: - contents = [] + children = [] if icon: - contents.append(AlertIcon.create()) + children.append(AlertIcon.create()) - contents.append(AlertTitle.create(title)) + children.append(AlertTitle.create(title)) if desc: - contents.append(AlertDescription.create(desc)) + children.append(AlertDescription.create(desc)) return super().create(*children, **props) diff --git a/pynecone/components/feedback/circularprogress.py b/pynecone/components/feedback/circularprogress.py index 60934441a..5aab55003 100644 --- a/pynecone/components/feedback/circularprogress.py +++ b/pynecone/components/feedback/circularprogress.py @@ -1,5 +1,6 @@ """Container to stack elements with spacing.""" +from pynecone.components.component import Component from pynecone.components.libs.chakra import ChakraComponent from pynecone.var import Var @@ -33,6 +34,25 @@ class CircularProgress(ChakraComponent): # The desired valueText to use in place of the value. 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): """Label of CircularProcess.""" diff --git a/pynecone/components/overlay/menu.py b/pynecone/components/overlay/menu.py index 5ef5bde22..50018f8e1 100644 --- a/pynecone/components/overlay/menu.py +++ b/pynecone/components/overlay/menu.py @@ -70,22 +70,26 @@ class Menu(ChakraComponent): return super().get_triggers() | {"on_close", "on_open"} @classmethod - def create(cls, *children, items=None, **props) -> Component: + def create(cls, *children, button=None, items=None, **props) -> Component: """Create a menu component. Args: 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. Returns: The menu component. """ if len(children) == 0: - button = MenuButton.create(*props.pop("button")) + children = [] + + if button: + children.append(MenuButton.create(button)) if not items: items = [] - children = [button, MenuList.create(*items)] + children.append(MenuList.create(*items)) return super().create(*children, **props)