reflex-components-sonner 0.9.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"""Sonner toast component."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import dataclasses
|
|
6
|
+
from typing import Any, Literal
|
|
7
|
+
|
|
8
|
+
from reflex_base.components.component import Component, ComponentNamespace, field
|
|
9
|
+
from reflex_base.components.props import NoExtrasAllowedProps
|
|
10
|
+
from reflex_base.constants.base import Dirs
|
|
11
|
+
from reflex_base.event import EventSpec, run_script
|
|
12
|
+
from reflex_base.style import Style, resolved_color_mode
|
|
13
|
+
from reflex_base.utils import format
|
|
14
|
+
from reflex_base.utils.imports import ImportVar
|
|
15
|
+
from reflex_base.utils.serializers import serializer
|
|
16
|
+
from reflex_base.vars import VarData
|
|
17
|
+
from reflex_base.vars.base import LiteralVar, Var
|
|
18
|
+
from reflex_base.vars.function import FunctionVar
|
|
19
|
+
from reflex_base.vars.number import ternary_operation
|
|
20
|
+
from reflex_base.vars.object import ObjectVar
|
|
21
|
+
from reflex_components_lucide.icon import Icon
|
|
22
|
+
|
|
23
|
+
LiteralPosition = Literal[
|
|
24
|
+
"top-left",
|
|
25
|
+
"top-center",
|
|
26
|
+
"top-right",
|
|
27
|
+
"bottom-left",
|
|
28
|
+
"bottom-center",
|
|
29
|
+
"bottom-right",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
toast_ref = Var(
|
|
33
|
+
_js_expr="refs['__toast']",
|
|
34
|
+
_var_data=VarData(imports={f"$/{Dirs.STATE_PATH}": [ImportVar(tag="refs")]}),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclasses.dataclass
|
|
39
|
+
class ToastAction:
|
|
40
|
+
"""A toast action that render a button in the toast."""
|
|
41
|
+
|
|
42
|
+
label: str
|
|
43
|
+
on_click: Any
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@serializer
|
|
47
|
+
def serialize_action(action: ToastAction) -> dict:
|
|
48
|
+
"""Serialize a toast action.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
action: The toast action to serialize.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
The serialized toast action with on_click formatted to queue the given event.
|
|
55
|
+
"""
|
|
56
|
+
return {
|
|
57
|
+
"label": action.label,
|
|
58
|
+
"onClick": format.format_queue_events(action.on_click),
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _toast_callback_signature(toast: Var) -> list[Var]:
|
|
63
|
+
"""The signature for the toast callback, stripping out unserializable keys.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
toast: The toast variable.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
A function call stripping non-serializable members of the toast object.
|
|
70
|
+
"""
|
|
71
|
+
return [
|
|
72
|
+
Var(
|
|
73
|
+
_js_expr=f"(() => {{let {{action, cancel, onDismiss, onAutoClose, ...rest}} = {toast!s}; return rest}})()"
|
|
74
|
+
)
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class ToastProps(NoExtrasAllowedProps):
|
|
79
|
+
"""Props for the toast component."""
|
|
80
|
+
|
|
81
|
+
# Toast's title, renders above the description.
|
|
82
|
+
title: str | Var | None
|
|
83
|
+
|
|
84
|
+
# Toast's description, renders underneath the title.
|
|
85
|
+
description: str | Var | None
|
|
86
|
+
|
|
87
|
+
# Whether to show the close button.
|
|
88
|
+
close_button: bool | None
|
|
89
|
+
|
|
90
|
+
# Dark toast in light mode and vice versa.
|
|
91
|
+
invert: bool | None
|
|
92
|
+
|
|
93
|
+
# Control the sensitivity of the toast for screen readers
|
|
94
|
+
important: bool | None
|
|
95
|
+
|
|
96
|
+
# Time in milliseconds that should elapse before automatically closing the toast.
|
|
97
|
+
duration: int | None
|
|
98
|
+
|
|
99
|
+
# Position of the toast.
|
|
100
|
+
position: LiteralPosition | None
|
|
101
|
+
|
|
102
|
+
# If false, it'll prevent the user from dismissing the toast.
|
|
103
|
+
dismissible: bool | None
|
|
104
|
+
|
|
105
|
+
# TODO: fix serialization of icons for toast? (might not be possible yet)
|
|
106
|
+
# Icon displayed in front of toast's text, aligned vertically.
|
|
107
|
+
# icon: Icon | None = None # noqa: ERA001
|
|
108
|
+
|
|
109
|
+
# TODO: fix implementation for action / cancel buttons
|
|
110
|
+
# Renders a primary button, clicking it will close the toast.
|
|
111
|
+
action: ToastAction | None
|
|
112
|
+
|
|
113
|
+
# Renders a secondary button, clicking it will close the toast.
|
|
114
|
+
cancel: ToastAction | None
|
|
115
|
+
|
|
116
|
+
# Custom id for the toast.
|
|
117
|
+
id: str | Var | None
|
|
118
|
+
|
|
119
|
+
# Removes the default styling, which allows for easier customization.
|
|
120
|
+
unstyled: bool | None
|
|
121
|
+
|
|
122
|
+
# Custom style for the toast.
|
|
123
|
+
style: Style | None
|
|
124
|
+
|
|
125
|
+
# Class name for the toast.
|
|
126
|
+
class_name: str | None
|
|
127
|
+
|
|
128
|
+
# XXX: These still do not seem to work Custom style for the toast primary button.
|
|
129
|
+
action_button_styles: Style | None
|
|
130
|
+
|
|
131
|
+
# Custom style for the toast secondary button.
|
|
132
|
+
cancel_button_styles: Style | None
|
|
133
|
+
|
|
134
|
+
# The function gets called when either the close button is clicked, or the toast is swiped.
|
|
135
|
+
on_dismiss: Any | None
|
|
136
|
+
|
|
137
|
+
# Function that gets called when the toast disappears automatically after it's timeout (duration` prop).
|
|
138
|
+
on_auto_close: Any | None
|
|
139
|
+
|
|
140
|
+
def dict(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
|
|
141
|
+
"""Convert the object to a dictionary.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
*args: The arguments to pass to the base class.
|
|
145
|
+
**kwargs: The keyword arguments to pass to the base
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
The object as a dictionary with ToastAction fields intact.
|
|
149
|
+
"""
|
|
150
|
+
d = super().dict(*args, **kwargs)
|
|
151
|
+
# Keep these fields as ToastAction so they can be serialized specially
|
|
152
|
+
if "action" in d:
|
|
153
|
+
d["action"] = self.action
|
|
154
|
+
if isinstance(self.action, dict):
|
|
155
|
+
d["action"] = ToastAction(**self.action)
|
|
156
|
+
if "cancel" in d:
|
|
157
|
+
d["cancel"] = self.cancel
|
|
158
|
+
if isinstance(self.cancel, dict):
|
|
159
|
+
d["cancel"] = ToastAction(**self.cancel)
|
|
160
|
+
if "onDismiss" in d:
|
|
161
|
+
d["onDismiss"] = format.format_queue_events(
|
|
162
|
+
self.on_dismiss, _toast_callback_signature
|
|
163
|
+
)
|
|
164
|
+
if "onAutoClose" in d:
|
|
165
|
+
d["onAutoClose"] = format.format_queue_events(
|
|
166
|
+
self.on_auto_close, _toast_callback_signature
|
|
167
|
+
)
|
|
168
|
+
return d
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class Toaster(Component):
|
|
172
|
+
"""A Toaster Component for displaying toast notifications."""
|
|
173
|
+
|
|
174
|
+
library: str | None = "sonner@2.0.7"
|
|
175
|
+
|
|
176
|
+
tag = "Toaster"
|
|
177
|
+
|
|
178
|
+
theme: Var[str] = field(default=resolved_color_mode, doc="the theme of the toast")
|
|
179
|
+
|
|
180
|
+
rich_colors: Var[bool] = field(
|
|
181
|
+
default=LiteralVar.create(True), doc="whether to show rich colors"
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
expand: Var[bool] = field(
|
|
185
|
+
default=LiteralVar.create(True), doc="whether to expand the toast"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
visible_toasts: Var[int] = field(
|
|
189
|
+
doc="the number of toasts that are currently visible"
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
position: Var[LiteralPosition] = field(
|
|
193
|
+
default=LiteralVar.create("bottom-right"), doc="the position of the toast"
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
close_button: Var[bool] = field(
|
|
197
|
+
default=LiteralVar.create(False), doc="whether to show the close button"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
offset: Var[str] = field(doc="offset of the toast")
|
|
201
|
+
|
|
202
|
+
dir: Var[str] = field(doc="directionality of the toast (default: ltr)")
|
|
203
|
+
|
|
204
|
+
hotkey: Var[str] = field(
|
|
205
|
+
doc="Keyboard shortcut that will move focus to the toaster area."
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
invert: Var[bool] = field(doc="Dark toasts in light mode and vice versa.")
|
|
209
|
+
|
|
210
|
+
toast_options: Var[ToastProps] = field(
|
|
211
|
+
doc="These will act as default options for all toasts. See toast() for all available options."
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
gap: Var[int] = field(doc="Gap between toasts when expanded")
|
|
215
|
+
|
|
216
|
+
loading_icon: Var[Icon] = field(doc="Changes the default loading icon")
|
|
217
|
+
|
|
218
|
+
pause_when_page_is_hidden: Var[bool] = field(
|
|
219
|
+
doc="Pauses toast timers when the page is hidden, e.g., when the tab is backgrounded, the browser is minimized, or the OS is locked."
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
def add_hooks(self) -> list[Var | str]:
|
|
223
|
+
"""Add hooks for the toaster component.
|
|
224
|
+
|
|
225
|
+
Returns:
|
|
226
|
+
The hooks for the toaster component.
|
|
227
|
+
"""
|
|
228
|
+
if self.library is None:
|
|
229
|
+
return []
|
|
230
|
+
hook = Var(
|
|
231
|
+
_js_expr=f"{toast_ref} = toast",
|
|
232
|
+
_var_data=VarData(
|
|
233
|
+
imports={
|
|
234
|
+
"$/utils/state": [ImportVar(tag="refs")],
|
|
235
|
+
self.library: [ImportVar(tag="toast", install=False)],
|
|
236
|
+
}
|
|
237
|
+
),
|
|
238
|
+
)
|
|
239
|
+
return [hook]
|
|
240
|
+
|
|
241
|
+
@staticmethod
|
|
242
|
+
def send_toast(
|
|
243
|
+
message: str | Var[str] = "",
|
|
244
|
+
level: str | None = None,
|
|
245
|
+
fallback_to_alert: bool = False,
|
|
246
|
+
**props,
|
|
247
|
+
) -> EventSpec:
|
|
248
|
+
"""Send a toast message.
|
|
249
|
+
|
|
250
|
+
Args:
|
|
251
|
+
message: The message to display.
|
|
252
|
+
level: The level of the toast.
|
|
253
|
+
fallback_to_alert: Whether to fallback to an alert if the toaster is not created.
|
|
254
|
+
**props: The options for the toast.
|
|
255
|
+
|
|
256
|
+
Returns:
|
|
257
|
+
The toast event.
|
|
258
|
+
|
|
259
|
+
Raises:
|
|
260
|
+
ValueError: If the Toaster component is not created.
|
|
261
|
+
"""
|
|
262
|
+
toast_command = (
|
|
263
|
+
ObjectVar.__getattr__(toast_ref.to(dict), level) if level else toast_ref
|
|
264
|
+
).to(FunctionVar)
|
|
265
|
+
|
|
266
|
+
if isinstance(message, Var):
|
|
267
|
+
props.setdefault("title", message)
|
|
268
|
+
message = ""
|
|
269
|
+
elif message == "" and "title" not in props and "description" not in props:
|
|
270
|
+
msg = "Toast message or title or description must be provided."
|
|
271
|
+
raise ValueError(msg)
|
|
272
|
+
|
|
273
|
+
if props:
|
|
274
|
+
args = LiteralVar.create(ToastProps(component_name="rx.toast", **props)) # pyright: ignore [reportCallIssue]
|
|
275
|
+
toast = toast_command.call(message, args)
|
|
276
|
+
else:
|
|
277
|
+
toast = toast_command.call(message)
|
|
278
|
+
|
|
279
|
+
if fallback_to_alert:
|
|
280
|
+
toast = ternary_operation(
|
|
281
|
+
toast_ref.bool(),
|
|
282
|
+
toast,
|
|
283
|
+
FunctionVar("window.alert").call(
|
|
284
|
+
Var
|
|
285
|
+
.create(
|
|
286
|
+
message
|
|
287
|
+
if isinstance(message, str) and message
|
|
288
|
+
else props.get("title", props.get("description", ""))
|
|
289
|
+
)
|
|
290
|
+
.to(str)
|
|
291
|
+
.replace("<br/>", "\n")
|
|
292
|
+
),
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
return run_script(toast)
|
|
296
|
+
|
|
297
|
+
@staticmethod
|
|
298
|
+
def toast_info(message: str | Var[str] = "", **kwargs: Any) -> EventSpec:
|
|
299
|
+
"""Display an info toast message.
|
|
300
|
+
|
|
301
|
+
Args:
|
|
302
|
+
message: The message to display.
|
|
303
|
+
**kwargs: Additional toast props.
|
|
304
|
+
|
|
305
|
+
Returns:
|
|
306
|
+
The toast event.
|
|
307
|
+
"""
|
|
308
|
+
return Toaster.send_toast(message, level="info", **kwargs)
|
|
309
|
+
|
|
310
|
+
@staticmethod
|
|
311
|
+
def toast_warning(message: str | Var[str] = "", **kwargs: Any) -> EventSpec:
|
|
312
|
+
"""Display a warning toast message.
|
|
313
|
+
|
|
314
|
+
Args:
|
|
315
|
+
message: The message to display.
|
|
316
|
+
**kwargs: Additional toast props.
|
|
317
|
+
|
|
318
|
+
Returns:
|
|
319
|
+
The toast event.
|
|
320
|
+
"""
|
|
321
|
+
return Toaster.send_toast(message, level="warning", **kwargs)
|
|
322
|
+
|
|
323
|
+
@staticmethod
|
|
324
|
+
def toast_error(message: str | Var[str] = "", **kwargs: Any) -> EventSpec:
|
|
325
|
+
"""Display an error toast message.
|
|
326
|
+
|
|
327
|
+
Args:
|
|
328
|
+
message: The message to display.
|
|
329
|
+
**kwargs: Additional toast props.
|
|
330
|
+
|
|
331
|
+
Returns:
|
|
332
|
+
The toast event.
|
|
333
|
+
"""
|
|
334
|
+
return Toaster.send_toast(message, level="error", **kwargs)
|
|
335
|
+
|
|
336
|
+
@staticmethod
|
|
337
|
+
def toast_success(message: str | Var[str] = "", **kwargs: Any) -> EventSpec:
|
|
338
|
+
"""Display a success toast message.
|
|
339
|
+
|
|
340
|
+
Args:
|
|
341
|
+
message: The message to display.
|
|
342
|
+
**kwargs: Additional toast props.
|
|
343
|
+
|
|
344
|
+
Returns:
|
|
345
|
+
The toast event.
|
|
346
|
+
"""
|
|
347
|
+
return Toaster.send_toast(message, level="success", **kwargs)
|
|
348
|
+
|
|
349
|
+
@staticmethod
|
|
350
|
+
def toast_loading(message: str | Var[str] = "", **kwargs: Any) -> EventSpec:
|
|
351
|
+
"""Display a loading toast message.
|
|
352
|
+
|
|
353
|
+
Args:
|
|
354
|
+
message: The message to display.
|
|
355
|
+
**kwargs: Additional toast props.
|
|
356
|
+
|
|
357
|
+
Returns:
|
|
358
|
+
The toast event.
|
|
359
|
+
"""
|
|
360
|
+
return Toaster.send_toast(message, level="loading", **kwargs)
|
|
361
|
+
|
|
362
|
+
@staticmethod
|
|
363
|
+
def toast_dismiss(id: Var[str] | str | None = None) -> EventSpec:
|
|
364
|
+
"""Dismiss a toast.
|
|
365
|
+
|
|
366
|
+
Args:
|
|
367
|
+
id: The id of the toast to dismiss.
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
The toast dismiss event.
|
|
371
|
+
"""
|
|
372
|
+
dismiss_var_data = None
|
|
373
|
+
|
|
374
|
+
if isinstance(id, Var):
|
|
375
|
+
dismiss = f"{toast_ref}.dismiss({id!s})"
|
|
376
|
+
dismiss_var_data = id._get_all_var_data()
|
|
377
|
+
elif isinstance(id, str):
|
|
378
|
+
dismiss = f"{toast_ref}.dismiss('{id}')"
|
|
379
|
+
else:
|
|
380
|
+
dismiss = f"{toast_ref}.dismiss()"
|
|
381
|
+
dismiss_action = Var(
|
|
382
|
+
_js_expr=dismiss, _var_data=VarData.merge(dismiss_var_data)
|
|
383
|
+
)
|
|
384
|
+
return run_script(dismiss_action)
|
|
385
|
+
|
|
386
|
+
@classmethod
|
|
387
|
+
def create(cls, *children: Any, **props: Any) -> Component:
|
|
388
|
+
"""Create a toaster component.
|
|
389
|
+
|
|
390
|
+
Args:
|
|
391
|
+
*children: The children of the toaster.
|
|
392
|
+
**props: The properties of the toaster.
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
The toaster component.
|
|
396
|
+
"""
|
|
397
|
+
return super().create(*children, **props)
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
# TODO: figure out why loading toast stay open forever when using level="loading" in toast()
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
class ToastNamespace(ComponentNamespace):
|
|
404
|
+
"""Namespace for toast components."""
|
|
405
|
+
|
|
406
|
+
provider = staticmethod(Toaster.create)
|
|
407
|
+
options = staticmethod(ToastProps)
|
|
408
|
+
info = staticmethod(Toaster.toast_info)
|
|
409
|
+
warning = staticmethod(Toaster.toast_warning)
|
|
410
|
+
error = staticmethod(Toaster.toast_error)
|
|
411
|
+
success = staticmethod(Toaster.toast_success)
|
|
412
|
+
loading = staticmethod(Toaster.toast_loading)
|
|
413
|
+
dismiss = staticmethod(Toaster.toast_dismiss)
|
|
414
|
+
__call__ = staticmethod(Toaster.send_toast)
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
toast = ToastNamespace()
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"""Stub file for reflex_components_sonner/toast.py"""
|
|
2
|
+
|
|
3
|
+
# ------------------- DO NOT EDIT ----------------------
|
|
4
|
+
# This file was generated by `reflex/utils/pyi_generator.py`!
|
|
5
|
+
# ------------------------------------------------------
|
|
6
|
+
import dataclasses
|
|
7
|
+
from collections.abc import Mapping, Sequence
|
|
8
|
+
from typing import Any, Literal
|
|
9
|
+
|
|
10
|
+
from reflex_base.components.component import Component, ComponentNamespace
|
|
11
|
+
from reflex_base.components.props import NoExtrasAllowedProps
|
|
12
|
+
from reflex_base.constants.base import Dirs
|
|
13
|
+
from reflex_base.event import EventSpec, EventType, PointerEventInfo
|
|
14
|
+
from reflex_base.style import Style
|
|
15
|
+
from reflex_base.utils.imports import ImportVar
|
|
16
|
+
from reflex_base.utils.serializers import serializer
|
|
17
|
+
from reflex_base.vars import VarData
|
|
18
|
+
from reflex_base.vars.base import Var
|
|
19
|
+
from reflex_components_core.core.breakpoints import Breakpoints
|
|
20
|
+
from reflex_components_lucide.icon import Icon
|
|
21
|
+
|
|
22
|
+
LiteralPosition = Literal[
|
|
23
|
+
"top-left",
|
|
24
|
+
"top-center",
|
|
25
|
+
"top-right",
|
|
26
|
+
"bottom-left",
|
|
27
|
+
"bottom-center",
|
|
28
|
+
"bottom-right",
|
|
29
|
+
]
|
|
30
|
+
toast_ref = Var(
|
|
31
|
+
_js_expr="refs['__toast']",
|
|
32
|
+
_var_data=VarData(imports={f"$/{Dirs.STATE_PATH}": [ImportVar(tag="refs")]}),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
@dataclasses.dataclass
|
|
36
|
+
class ToastAction:
|
|
37
|
+
label: str
|
|
38
|
+
on_click: Any
|
|
39
|
+
|
|
40
|
+
@serializer
|
|
41
|
+
def serialize_action(action: ToastAction) -> dict: ...
|
|
42
|
+
|
|
43
|
+
class ToastProps(NoExtrasAllowedProps):
|
|
44
|
+
title: str | Var | None
|
|
45
|
+
description: str | Var | None
|
|
46
|
+
close_button: bool | None
|
|
47
|
+
invert: bool | None
|
|
48
|
+
important: bool | None
|
|
49
|
+
duration: int | None
|
|
50
|
+
position: LiteralPosition | None
|
|
51
|
+
dismissible: bool | None
|
|
52
|
+
action: ToastAction | None
|
|
53
|
+
cancel: ToastAction | None
|
|
54
|
+
id: str | Var | None
|
|
55
|
+
unstyled: bool | None
|
|
56
|
+
style: Style | None
|
|
57
|
+
class_name: str | None
|
|
58
|
+
action_button_styles: Style | None
|
|
59
|
+
cancel_button_styles: Style | None
|
|
60
|
+
on_dismiss: Any | None
|
|
61
|
+
on_auto_close: Any | None
|
|
62
|
+
|
|
63
|
+
def dict(self, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
|
|
64
|
+
|
|
65
|
+
class Toaster(Component):
|
|
66
|
+
def add_hooks(self) -> list[Var | str]: ...
|
|
67
|
+
@staticmethod
|
|
68
|
+
def send_toast(
|
|
69
|
+
message: str | Var[str] = "",
|
|
70
|
+
level: str | None = None,
|
|
71
|
+
fallback_to_alert: bool = False,
|
|
72
|
+
**props,
|
|
73
|
+
) -> EventSpec: ...
|
|
74
|
+
@staticmethod
|
|
75
|
+
def toast_info(message: str | Var[str] = "", **kwargs: Any) -> EventSpec: ...
|
|
76
|
+
@staticmethod
|
|
77
|
+
def toast_warning(message: str | Var[str] = "", **kwargs: Any) -> EventSpec: ...
|
|
78
|
+
@staticmethod
|
|
79
|
+
def toast_error(message: str | Var[str] = "", **kwargs: Any) -> EventSpec: ...
|
|
80
|
+
@staticmethod
|
|
81
|
+
def toast_success(message: str | Var[str] = "", **kwargs: Any) -> EventSpec: ...
|
|
82
|
+
@staticmethod
|
|
83
|
+
def toast_loading(message: str | Var[str] = "", **kwargs: Any) -> EventSpec: ...
|
|
84
|
+
@staticmethod
|
|
85
|
+
def toast_dismiss(id: Var[str] | str | None = None) -> EventSpec: ...
|
|
86
|
+
@classmethod
|
|
87
|
+
def create(
|
|
88
|
+
cls,
|
|
89
|
+
*children,
|
|
90
|
+
theme: Var[str] | str | None = None,
|
|
91
|
+
rich_colors: Var[bool] | bool | None = None,
|
|
92
|
+
expand: Var[bool] | bool | None = None,
|
|
93
|
+
visible_toasts: Var[int] | int | None = None,
|
|
94
|
+
position: Literal[
|
|
95
|
+
"bottom-center",
|
|
96
|
+
"bottom-left",
|
|
97
|
+
"bottom-right",
|
|
98
|
+
"top-center",
|
|
99
|
+
"top-left",
|
|
100
|
+
"top-right",
|
|
101
|
+
]
|
|
102
|
+
| Var[
|
|
103
|
+
Literal[
|
|
104
|
+
"bottom-center",
|
|
105
|
+
"bottom-left",
|
|
106
|
+
"bottom-right",
|
|
107
|
+
"top-center",
|
|
108
|
+
"top-left",
|
|
109
|
+
"top-right",
|
|
110
|
+
]
|
|
111
|
+
]
|
|
112
|
+
| None = None,
|
|
113
|
+
close_button: Var[bool] | bool | None = None,
|
|
114
|
+
offset: Var[str] | str | None = None,
|
|
115
|
+
dir: Var[str] | str | None = None,
|
|
116
|
+
hotkey: Var[str] | str | None = None,
|
|
117
|
+
invert: Var[bool] | bool | None = None,
|
|
118
|
+
toast_options: ToastProps | Var[ToastProps] | None = None,
|
|
119
|
+
gap: Var[int] | int | None = None,
|
|
120
|
+
loading_icon: Icon | Var[Icon] | None = None,
|
|
121
|
+
pause_when_page_is_hidden: Var[bool] | bool | None = None,
|
|
122
|
+
style: Sequence[Mapping[str, Any]]
|
|
123
|
+
| Mapping[str, Any]
|
|
124
|
+
| Var[Mapping[str, Any]]
|
|
125
|
+
| Breakpoints
|
|
126
|
+
| None = None,
|
|
127
|
+
key: Any | None = None,
|
|
128
|
+
id: Any | None = None,
|
|
129
|
+
ref: Var | None = None,
|
|
130
|
+
class_name: Any | None = None,
|
|
131
|
+
custom_attrs: dict[str, Var | Any] | None = None,
|
|
132
|
+
on_blur: EventType[()] | None = None,
|
|
133
|
+
on_click: EventType[()] | EventType[PointerEventInfo] | None = None,
|
|
134
|
+
on_context_menu: EventType[()] | EventType[PointerEventInfo] | None = None,
|
|
135
|
+
on_double_click: EventType[()] | EventType[PointerEventInfo] | None = None,
|
|
136
|
+
on_focus: EventType[()] | None = None,
|
|
137
|
+
on_mount: EventType[()] | None = None,
|
|
138
|
+
on_mouse_down: EventType[()] | None = None,
|
|
139
|
+
on_mouse_enter: EventType[()] | None = None,
|
|
140
|
+
on_mouse_leave: EventType[()] | None = None,
|
|
141
|
+
on_mouse_move: EventType[()] | None = None,
|
|
142
|
+
on_mouse_out: EventType[()] | None = None,
|
|
143
|
+
on_mouse_over: EventType[()] | None = None,
|
|
144
|
+
on_mouse_up: EventType[()] | None = None,
|
|
145
|
+
on_scroll: EventType[()] | None = None,
|
|
146
|
+
on_scroll_end: EventType[()] | None = None,
|
|
147
|
+
on_unmount: EventType[()] | None = None,
|
|
148
|
+
**props,
|
|
149
|
+
) -> Toaster:
|
|
150
|
+
"""Create a toaster component.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
*children: The children of the toaster.
|
|
154
|
+
**props: The properties of the toaster.
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
The toaster component.
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
class ToastNamespace(ComponentNamespace):
|
|
161
|
+
provider = staticmethod(Toaster.create)
|
|
162
|
+
options = staticmethod(ToastProps)
|
|
163
|
+
info = staticmethod(Toaster.toast_info)
|
|
164
|
+
warning = staticmethod(Toaster.toast_warning)
|
|
165
|
+
error = staticmethod(Toaster.toast_error)
|
|
166
|
+
success = staticmethod(Toaster.toast_success)
|
|
167
|
+
loading = staticmethod(Toaster.toast_loading)
|
|
168
|
+
dismiss = staticmethod(Toaster.toast_dismiss)
|
|
169
|
+
|
|
170
|
+
@staticmethod
|
|
171
|
+
def __call__(
|
|
172
|
+
message: str | Var[str] | str = "",
|
|
173
|
+
level: str | None = None,
|
|
174
|
+
fallback_to_alert: bool = False,
|
|
175
|
+
**props,
|
|
176
|
+
) -> EventSpec:
|
|
177
|
+
"""Send a toast message.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
message: The message to display.
|
|
181
|
+
level: The level of the toast.
|
|
182
|
+
fallback_to_alert: Whether to fallback to an alert if the toaster is not created.
|
|
183
|
+
**props: The options for the toast.
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
The toast event.
|
|
187
|
+
|
|
188
|
+
Raises:
|
|
189
|
+
ValueError: If the Toaster component is not created.
|
|
190
|
+
"""
|
|
191
|
+
|
|
192
|
+
toast = ToastNamespace()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: reflex-components-sonner
|
|
3
|
+
Version: 0.9.0a1
|
|
4
|
+
Summary: Reflex sonner components.
|
|
5
|
+
Author-email: Khaleel Al-Adhami <khaleel@reflex.dev>
|
|
6
|
+
Maintainer-email: Khaleel Al-Adhami <khaleel@reflex.dev>
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: reflex-components-lucide
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# reflex-components-sonner
|
|
12
|
+
|
|
13
|
+
Reflex sonner components.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
reflex_components_sonner/__init__.py,sha256=L_mdRIy7-ccRGSz5VK6J8O-c-e-D1p9xWw29_ErrvGg,68
|
|
2
|
+
reflex_components_sonner/toast.py,sha256=KVvd3_FhEAf93VtKs-UaKvkIPva6Hf7VYnaavjyamv0,12872
|
|
3
|
+
reflex_components_sonner/toast.pyi,sha256=xgqXR1phmM_DlMHhlx0fqPXA3jCgsfgEaiuEScXUruY,6542
|
|
4
|
+
reflex_components_sonner-0.9.0a1.dist-info/METADATA,sha256=BFLSH1ZuFSMZuhsw7Ayj-gntSQsXKLcaN8xPxVgN2MU,374
|
|
5
|
+
reflex_components_sonner-0.9.0a1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
6
|
+
reflex_components_sonner-0.9.0a1.dist-info/RECORD,,
|