瀏覽代碼

split "options" into individual props

Falko Schindler 3 月之前
父節點
當前提交
76d152a1d9
共有 2 個文件被更改,包括 62 次插入36 次删除
  1. 24 2
      nicegui/elements/notification.js
  2. 38 34
      nicegui/elements/notification.py

+ 24 - 2
nicegui/elements/notification.js

@@ -16,13 +16,35 @@ export default {
     convertedOptions() {
       convertDynamicProperties(this.options, true);
       const options = {
-        ...this.options,
+        message: this.message,
+        position: this.position,
+        multiLine: this.multiLine,
+        spinner: this.spinner,
+        closeBtn: this.closeBtn,
+        timeout: this.timeout,
+        group: this.group,
+        attrs: this.attrs,
+        type: this.type,
+        color: this.color,
+        icon: this.icon,
+        kwargs: this.kwargs,
         onDismiss: () => this.$emit("dismiss"),
       };
       return options;
     },
   },
   props: {
-    options: Object,
+    message: String,
+    position: String,
+    multiLine: Boolean,
+    spinner: Boolean,
+    closeBtn: Object,
+    timeout: Number,
+    group: Boolean,
+    attrs: Object,
+    type: String,
+    color: String,
+    icon: String,
+    kwargs: Object,
   },
 };

+ 38 - 34
nicegui/elements/notification.py

@@ -67,25 +67,29 @@ class Notification(Element, component='notification.js'):
         with context.client.layout:
             super().__init__()
         if options:
-            self._props['options'] = options
+            self._props.update(options)
         else:
-            self._props['options'] = {
-                'message': str(message),
-                'position': position,
-                'multiLine': multi_line,
-                'spinner': spinner,
-                'closeBtn': close_button,
-                'timeout': (timeout or 0) * 1000,
-                'group': False,
-                'attrs': {'data-id': f'nicegui-dialog-{self.id}'},
-            }
+            if message != '':
+                self._props['message'] = str(message)
+            if position != 'bottom':
+                self._props['position'] = position
+            if multi_line:
+                self._props['multiLine'] = multi_line
+            if spinner:
+                self._props['spinner'] = spinner
+            if close_button:
+                self._props['closeBtn'] = close_button
+            if timeout != 5.0:
+                self._props['timeout'] = (timeout or 0) * 1000
+            self._props['group'] = False
+            self._props['attrs'] = {'data-id': f'nicegui-dialog-{self.id}'}
             if type is not None:
-                self._props['options']['type'] = type
+                self._props['type'] = type
             if color is not None:
-                self._props['options']['color'] = color
+                self._props['color'] = color
             if icon is not None:
-                self._props['options']['icon'] = icon
-            self._props['options'].update(kwargs)
+                self._props['icon'] = icon
+            self._props['kwargs'] = kwargs
 
         if on_dismiss:
             self.on_dismiss(on_dismiss)
@@ -102,90 +106,90 @@ class Notification(Element, component='notification.js'):
     @property
     def message(self) -> str:
         """Message text."""
-        return self._props['options']['message']
+        return self._props['message']
 
     @message.setter
     def message(self, value: Any) -> None:
-        self._props['options']['message'] = str(value)
+        self._props['message'] = str(value)
         self.update()
 
     @property
     def position(self) -> NotificationPosition:
         """Position on the screen."""
-        return self._props['options']['position']
+        return self._props['position']
 
     @position.setter
     def position(self, value: NotificationPosition) -> None:
-        self._props['options']['position'] = value
+        self._props['position'] = value
         self.update()
 
     @property
     def type(self) -> NotificationType:
         """Type of the notification."""
-        return self._props['options'].get('type')
+        return self._props.get('type')
 
     @type.setter
     def type(self, value: NotificationType) -> None:
         if value is None:
-            self._props['options'].pop('type', None)
+            self._props.pop('type', None)
         else:
-            self._props['options']['type'] = value
+            self._props['type'] = value
         self.update()
 
     @property
     def color(self) -> Optional[str]:
         """Color of the notification."""
-        return self._props['options'].get('color')
+        return self._props.get('color')
 
     @color.setter
     def color(self, value: Optional[str]) -> None:
         if value is None:
-            self._props['options'].pop('color', None)
+            self._props.pop('color', None)
         else:
-            self._props['options']['color'] = value
+            self._props['color'] = value
         self.update()
 
     @property
     def multi_line(self) -> bool:
         """Whether the notification is multi-line."""
-        return self._props['options']['multiLine']
+        return self._props['multiLine']
 
     @multi_line.setter
     def multi_line(self, value: bool) -> None:
-        self._props['options']['multiLine'] = value
+        self._props['multiLine'] = value
         self.update()
 
     @property
     def icon(self) -> Optional[str]:
         """Icon of the notification."""
-        return self._props['options'].get('icon')
+        return self._props.get('icon')
 
     @icon.setter
     def icon(self, value: Optional[str]) -> None:
         if value is None:
-            self._props['options'].pop('icon', None)
+            self._props.pop('icon', None)
         else:
-            self._props['options']['icon'] = value
+            self._props['icon'] = value
         self.update()
 
     @property
     def spinner(self) -> bool:
         """Whether the notification is a spinner."""
-        return self._props['options']['spinner']
+        return self._props['spinner']
 
     @spinner.setter
     def spinner(self, value: bool) -> None:
-        self._props['options']['spinner'] = value
+        self._props['spinner'] = value
         self.update()
 
     @property
     def close_button(self) -> Union[bool, str]:
         """Whether the notification has a close button."""
-        return self._props['options']['closeBtn']
+        return self._props['closeBtn']
 
     @close_button.setter
     def close_button(self, value: Union[bool, str]) -> None:
-        self._props['options']['closeBtn'] = value
+        self._props['closeBtn'] = value
         self.update()
 
     def on_dismiss(self, callback: Handler[UiEventArguments]) -> Self: