Skip to content

Commit b2576ba

Browse files
committed
Close #45: pass attributes that clash with user supplied keyword arguments as a dictionary instead of keywords
1 parent d344306 commit b2576ba

File tree

8 files changed

+34
-27
lines changed

8 files changed

+34
-27
lines changed

examples/inputs/app.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
},
4949
),
5050
st.input_action_button(
51-
"button", "input_action_button()", icon=icon_svg("check")
51+
"button",
52+
"input_action_button()",
53+
icon=icon_svg("check"),
54+
class_="btn-primary",
5255
),
5356
st.input_file("file", "File upload"),
5457
),
@@ -69,7 +72,10 @@
6972
),
7073
tags.br(),
7174
st.input_action_button(
72-
"btn", "Show modal", icon=icon_svg("info-circle")
75+
"btn",
76+
"Show modal",
77+
icon=icon_svg("info-circle"),
78+
class_="btn-primary",
7379
),
7480
st.panel_fixed(
7581
st.panel_well(
@@ -138,7 +144,13 @@ def image():
138144
def _():
139145
btn = input.btn()
140146
if btn and btn > 0:
141-
st.modal_show(st.modal("Hello there!", easy_close=True))
147+
st.modal_show(
148+
st.modal(
149+
"Hello there!",
150+
easy_close=True,
151+
footer=st.modal_button("Dismiss", class_="btn-primary"),
152+
)
153+
)
142154

143155
@reactive.effect()
144156
def _():

shiny/ui_toolkit/bootstrap.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def row(*args: TagChildArg, **kwargs: TagAttrArg) -> Tag:
26-
return div(*args, class_="row", **kwargs)
26+
return div({"class": "row"}, *args, **kwargs)
2727

2828

2929
def column(
@@ -38,7 +38,7 @@ def column(
3838
# https://github.com/twbs/bootstrap/blob/74b8fe7/docs/4.3/migration/index.html#L659
3939
off = str(offset)
4040
cls += f" offset-md-{off} col-sm-offset-{off}"
41-
return div(*args, class_=cls, **kwargs)
41+
return div({"class": cls}, *args, **kwargs)
4242

4343

4444
# TODO: also accept a generic list (and wrap in panel in that case)
@@ -49,23 +49,23 @@ def layout_sidebar(
4949

5050

5151
def panel_well(*args: TagChildArg, **kwargs: TagAttrArg) -> Tag:
52-
return div(*args, class_="well", **kwargs)
52+
return div({"class": "well"}, *args, **kwargs)
5353

5454

5555
def panel_sidebar(*args: TagChildArg, width: int = 4, **kwargs: TagAttrArg) -> Tag:
5656
return div(
57+
{"class": "col-sm-" + str(width)},
5758
# A11y semantic landmark for sidebar
58-
tags.form(*args, role="complementary", class_="well", **kwargs),
59-
class_="col-sm-" + str(width),
59+
tags.form({"class": "well"}, *args, role="complementary", **kwargs),
6060
)
6161

6262

6363
def panel_main(*args: TagChildArg, width: int = 8, **kwargs: TagAttrArg) -> Tag:
6464
return div(
65+
{"class": "col-sm-" + str(width)},
6566
# A11y semantic landmark for main region
6667
*args,
6768
role="main",
68-
class_="col-sm-" + str(width),
6969
**kwargs,
7070
)
7171

@@ -131,4 +131,4 @@ def panel_absolute(
131131

132132

133133
def help_text(*args: TagChildArg, **kwargs: TagAttrArg) -> Tag:
134-
return span(*args, class_="help-block", **kwargs)
134+
return span({"class": "help-block"}, *args, **kwargs)

shiny/ui_toolkit/download_button.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@
55
from ..shinyenv import is_pyodide
66

77

8-
# TODO: implement icon
98
def download_button(
109
id: str,
1110
label: TagChildArg,
1211
icon: TagChildArg = None,
13-
class_: Optional[str] = None,
1412
width: Optional[str] = None,
1513
**kwargs: TagAttrArg,
1614
) -> Tag:
1715
return tags.a(
1816
icon,
1917
label,
18+
{"class": "btn btn-default shiny-download-link", "style": css(width=width)},
2019
id=id,
21-
class_=f"btn btn-default shiny-download-link {class_}",
22-
style=css(width=width),
2320
# This is a fake link that just results in a 404. It will be replaced by a
2421
# working link after the server side logic runs, so this link will only be
2522
# visited in cases where the user clicks the button too fast, or if the server
@@ -38,16 +35,14 @@ def download_link(
3835
id: str,
3936
label: TagChildArg,
4037
icon: TagChildArg = None,
41-
class_: Optional[str] = None,
4238
width: Optional[str] = None,
4339
**kwargs: TagAttrArg,
4440
) -> Tag:
4541
return tags.a(
4642
icon,
4743
label,
44+
{"class": "shiny-download-link", "style": css(width=width)},
4845
id=id,
49-
class_=f"shiny-download-link {class_}",
50-
style=css(width=width),
5146
href="session/0/download/missing_download",
5247
target="_blank",
5348
download=None if is_pyodide else True,

shiny/ui_toolkit/input_action_button.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ def input_action_button(
1111
**kwargs: TagAttrArg,
1212
) -> Tag:
1313
return tags.button(
14+
{"class": "btn btn-default action-button", "style": css(width=width)},
1415
icon,
1516
label,
1617
id=id,
1718
type="button",
18-
class_="btn btn-default action-button",
19-
style=css(width=width),
2019
**kwargs,
2120
)
2221

@@ -27,4 +26,4 @@ def input_action_link(
2726
icon: TagChildArg = None,
2827
**kwargs: TagAttrArg,
2928
) -> Tag:
30-
return tags.a(icon, label, id=id, href="#", class_="action-button", **kwargs)
29+
return tags.a({"class": "action-button"}, icon, label, id=id, href="#", **kwargs)

shiny/ui_toolkit/input_date.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def date_input_tag(
124124
):
125125
return tags.input(
126126
datepicker_deps(),
127+
{"class": "form-control"},
127128
type="text",
128-
class_="form-control",
129129
# `aria-labelledby` attribute is required for accessibility to avoid doubled labels (#2951).
130130
aria_labelledby=id + "-label",
131131
# title attribute is announced for screen readers for date format.

shiny/ui_toolkit/modal.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
from ..session import Session, _require_active_session, _process_deps
1313

1414

15-
def modal_button(label: str, icon: TagChildArg = None) -> Tag:
15+
def modal_button(label: str, icon: TagChildArg = None, **kwargs: TagChildArg) -> Tag:
1616
return tags.button(
1717
icon,
1818
label,
19+
{"class": "btn btn-default"},
1920
type="button",
20-
class_="btn btn-default",
2121
data_dismiss="modal",
2222
data_bs_dismiss="modal",
23+
**kwargs
2324
)
2425

2526

@@ -43,7 +44,7 @@ def modal(
4344
dialog = div(
4445
div(
4546
title_div,
46-
div(*args, class_="modal-body", **kwargs),
47+
div({"class": "modal-body"}, *args, **kwargs),
4748
footer,
4849
class_="modal-content",
4950
),

shiny/ui_toolkit/output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ def output_ui(
3939
) -> Tag:
4040
if not container:
4141
container = tags.span if inline else tags.div
42-
return container(id=id, class_="shiny-html-output", **kwargs) # type: ignore
42+
return container({"class": "shiny-html-output"}, id=id, **kwargs)

shiny/ui_toolkit/page.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ def page_fluid(
6262
*args: Any, title: Optional[str] = None, lang: Optional[str] = None, **kwargs: str
6363
) -> Tag:
6464
return page_bootstrap(
65-
div(*args, class_="container-fluid", **kwargs), title=title, lang=lang
65+
div({"class": "container-fluid"}, *args, **kwargs), title=title, lang=lang
6666
)
6767

6868

6969
def page_fixed(
7070
*args: Any, title: Optional[str] = None, lang: Optional[str] = None, **kwargs: str
7171
) -> Tag:
7272
return page_bootstrap(
73-
div(*args, class_="container", **kwargs), title=title, lang=lang
73+
div({"class": "container"}, *args, **kwargs), title=title, lang=lang
7474
)
7575

7676

0 commit comments

Comments
 (0)