瀏覽代碼

button: colors and design

Falko Schindler 4 年之前
父節點
當前提交
a44a9711ef
共有 2 個文件被更改,包括 18 次插入7 次删除
  1. 2 1
      main.py
  2. 16 6
      nicegui/elements/button.py

+ 2 - 1
main.py

@@ -9,7 +9,8 @@ with ui.row():
         ui.label('Interactive elements', 'h5')
         with ui.row():
             with ui.column():
-                ui.button('Click me!', icon='touch_app', on_click=lambda: output.set_text('Click'))
+                ui.button('Click me!', icon='touch_app', design='outline rounded',
+                          on_click=lambda: output.set_text('Click'))
                 ui.checkbox('Check me!', on_change=lambda e: output.set_text('Checked' if e.value else 'Unchecked'))
                 ui.switch('Switch me!', on_change=lambda e: output.set_text('Switched' if e.value else 'Unswitched'))
                 ui.slider(0, 100, on_change=lambda e: output.set_text(e.value))

+ 16 - 6
nicegui/elements/button.py

@@ -5,14 +5,24 @@ from ..utils import handle_exceptions, provide_arguments
 
 class Button(Element):
 
-    def __init__(self, text: str, icon: str = None, icon_right: str = None, on_click: Callable = None):
+    def __init__(self,
+                 text: str = '',
+                 icon: str = None,
+                 icon_right: str = None,
+                 color: str = 'primary',
+                 text_color: str = None,
+                 design: str = '',
+                 on_click: Callable = None):
 
-        view = jp.QButton(label=text, color='primary')
+        view = jp.QButton(
+            label=text,
+            icon=icon,
+            icon_right=icon_right,
+            color=color,
+            text_color=text_color,
+            **{key: True for key in design.split()}
+        )
 
-        if icon is not None:
-            view.icon = icon
-        if icon_right is not None:
-            view.icon_right = icon_right
         if on_click is not None:
             view.on('click', handle_exceptions(provide_arguments(on_click)))