Skip to content

Commit b6a3b11

Browse files
committed
Refactor download controls with shared mixin
1 parent 631be6f commit b6a3b11

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

shiny/playwright/controller/_file.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@
55
from ._base import InputActionBase, WidthLocM
66

77

8-
# TODO: Use mixin for dowloadlink and download button
9-
class DownloadLink(InputActionBase):
8+
class _DownloadMixin(WidthLocM, InputActionBase):
9+
"""Mixin for download controls."""
10+
11+
def __init__(self, page: Page, id: str, *, loc_suffix: str) -> None:
12+
super().__init__(
13+
page,
14+
id=id,
15+
loc=f"#{id}.shiny-download-link{loc_suffix}",
16+
)
17+
18+
19+
class DownloadLink(_DownloadMixin):
1020
"""
1121
Controller for :func:`shiny.ui.download_link`.
1222
"""
@@ -22,17 +32,10 @@ def __init__(self, page: Page, id: str) -> None:
2232
id
2333
The ID of the download link.
2434
"""
25-
super().__init__(
26-
page,
27-
id=id,
28-
loc=f"#{id}.shiny-download-link:not(.btn)",
29-
)
35+
super().__init__(page, id=id, loc_suffix=":not(.btn)")
3036

3137

32-
class DownloadButton(
33-
WidthLocM,
34-
InputActionBase,
35-
):
38+
class DownloadButton(_DownloadMixin):
3639
"""
3740
Controller for :func:`shiny.ui.download_button`
3841
"""
@@ -48,8 +51,4 @@ def __init__(self, page: Page, id: str) -> None:
4851
id
4952
The ID of the download button.
5053
"""
51-
super().__init__(
52-
page,
53-
id=id,
54-
loc=f"#{id}.btn.shiny-download-link",
55-
)
54+
super().__init__(page, id=id, loc_suffix=".btn")

0 commit comments

Comments
 (0)