浏览代码

buttons in `actions()` support color

wangweimin 3 年之前
父节点
当前提交
5ae977d2cc
共有 2 个文件被更改,包括 8 次插入4 次删除
  1. 1 1
      docs/spec.rst
  2. 7 3
      pywebio/input.py

+ 1 - 1
docs/spec.rst

@@ -138,7 +138,7 @@ Unique attributes of different input types:
 
 * actions
 
-  * buttons: ``{label:, value:, [type: 'submit'/'reset'/'cancel'], [disabled:]}`` .
+  * buttons: ``{label:, value:, [type: 'submit'/'reset'/'cancel'], [disabled:], [color:]}`` .
 
 
 * file:

+ 7 - 3
pywebio/input.py

@@ -464,7 +464,8 @@ def actions(label='', buttons=None, name=None, help_text=None):
                 "label":(str) button label,
                 "value":(object) button value,
                 "type":(str, optional) button type,
-                "disabled":(bool, optional) whether the button is disabled
+                "disabled":(bool, optional) whether the button is disabled,
+                "color":(str, optional) button color
              }
 
           When ``type='reset'/'cancel'`` or ``disabled=True``, ``value`` can be omitted
@@ -485,6 +486,9 @@ def actions(label='', buttons=None, name=None, help_text=None):
           Note: After clicking the ``type=reset`` button, the form will not be submitted,
           and the ``actions()`` call will not return
 
+        The ``color`` of button can be one of: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`,
+        `dark`.
+
     :param - label, name, help_text: Those arguments have the same meaning as for `input()`
     :return: If the user clicks the ``type=submit`` button to submit the form,
         return the value of the button clicked by the user.
@@ -525,8 +529,8 @@ def actions(label='', buttons=None, name=None, help_text=None):
             actions('actions', [
                 {'label': 'Save', 'value': 'save'},
                 {'label': 'Save and add next', 'value': 'save_and_continue'},
-                {'label': 'Reset', 'type': 'reset'},
-                {'label': 'Cancel', 'type': 'cancel'},
+                {'label': 'Reset', 'type': 'reset', 'color': 'warning'},
+                {'label': 'Cancel', 'type': 'cancel', 'color': 'danger'},
             ], name='action', help_text='actions'),
         ])
         put_code('info = ' + json.dumps(info, indent=4))