Skip to content

Commit 041bf0f

Browse files
committed
chore: Add ToastType type alias
1 parent a5b5c67 commit 041bf0f

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

shiny/playwright/controller/_toast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from playwright.sync_api import Locator, Page
44
from playwright.sync_api import expect as playwright_expect
55

6-
from ...ui._toast import _normalize_toast_position, _normalize_toast_type
6+
from ...ui._toast import ToastType, _normalize_toast_position, _normalize_toast_type
77
from .._types import PatternOrStr, Timeout
88
from ..expect._internal import (
99
expect_attribute_to_have_value as _expect_attribute_to_have_value,
@@ -94,7 +94,7 @@ def expect_header(self, value: PatternOrStr, *, timeout: Timeout = None) -> None
9494
"""
9595
playwright_expect(self.loc_header).to_have_text(value, timeout=timeout)
9696

97-
def expect_type(self, value: str, *, timeout: Timeout = None) -> None:
97+
def expect_type(self, value: ToastType, *, timeout: Timeout = None) -> None:
9898
"""
9999
Expects the toast to have the specified type class.
100100

shiny/ui/_toast.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
if TYPE_CHECKING:
2929
from ..session import Session
3030

31+
# Valid toast types
32+
ToastType = Literal[
33+
"primary",
34+
"secondary",
35+
"success",
36+
"info",
37+
"warning",
38+
"danger",
39+
"error", # alias for "danger", handled in normalization
40+
"light",
41+
"dark",
42+
]
43+
3144

3245
class ToastPayload(RenderedDeps):
3346
id: str
@@ -50,7 +63,7 @@ def __init__(
5063
header: Optional[ToastHeader | TagNode] = None,
5164
icon: Optional[TagNode] = None,
5265
id: Optional[str] = None,
53-
type: Optional[str] = None,
66+
type: Optional[ToastType] = None,
5467
duration: Optional[float] = 5000,
5568
position: str = "top-right",
5669
closable: bool = True,
@@ -174,19 +187,7 @@ def toast(
174187
header: Optional[str | ToastHeader | TagNode] = None,
175188
icon: Optional[TagNode] = None,
176189
id: Optional[str] = None,
177-
type: Optional[
178-
Literal[
179-
"primary",
180-
"secondary",
181-
"success",
182-
"info",
183-
"warning",
184-
"danger",
185-
"error",
186-
"light",
187-
"dark",
188-
]
189-
] = None,
190+
type: Optional[ToastType] = None,
190191
duration_s: Optional[int | float] = 5,
191192
position: str | list[str] | tuple[str, ...] = "top-right",
192193
closable: bool = True,
@@ -479,14 +480,14 @@ def hide_toast(
479480

480481

481482
@overload
482-
def _normalize_toast_type(type: str) -> str: ...
483+
def _normalize_toast_type(type: ToastType) -> ToastType: ...
483484

484485

485486
@overload
486487
def _normalize_toast_type(type: None) -> None: ...
487488

488489

489-
def _normalize_toast_type(type: Optional[str]) -> Optional[str]:
490+
def _normalize_toast_type(type: Optional[ToastType]) -> Optional[ToastType]:
490491
"""Normalize toast type, converting "error" to "danger"."""
491492
if type == "error":
492493
return "danger"

0 commit comments

Comments
 (0)