Skip to content

Commit

Permalink
split "options" into individual props
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Feb 10, 2025
1 parent 509faa9 commit 76d152a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 36 deletions.
26 changes: 24 additions & 2 deletions nicegui/elements/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
72 changes: 38 additions & 34 deletions nicegui/elements/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,29 @@ def __init__(self,
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)
Expand All @@ -102,90 +106,90 @@ async def handle_dismiss() -> None:
@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:
Expand Down

0 comments on commit 76d152a

Please sign in to comment.