Explorar o código

Support multiple styles for components (#370)

Dong-hyeon Shin %!s(int64=2) %!d(string=hai) anos
pai
achega
5427dd0f5b
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  1. 6 1
      pynecone/components/component.py

+ 6 - 1
pynecone/components/component.py

@@ -130,9 +130,14 @@ class Component(Base, ABC):
             del kwargs[key]
 
         # Add style props to the component.
+        style = kwargs.get("style", {})
+        if isinstance(style, List):
+            # Merge styles, the later ones overriding keys in the earlier ones.
+            style = {k: v for style_dict in style for k, v in style_dict.items()}
+
         kwargs["style"] = Style(
             {
-                **kwargs.get("style", {}),
+                **style,
                 **{attr: value for attr, value in kwargs.items() if attr not in fields},
             }
         )