Skip to content

Commit f42d080

Browse files
authored
Camel case class name (#684)
* Fix formatting * Use className in docs and examples
1 parent 57cc568 commit f42d080

File tree

285 files changed

+846
-952
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+846
-952
lines changed

docs/components_page/__init__.py

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,9 @@
33

44
import dash
55
import dash_bootstrap_components as dbc
6-
from dash import dcc, html
6+
from dash import html
77
from jinja2 import Environment, FileSystemLoader
88

9-
10-
# TODO: delete once Dash 2.0 is released
11-
def class_name_shim(fn):
12-
def new_init(self, *args, **kwargs):
13-
kwargs["className"] = kwargs.get("class_name", kwargs.get("className"))
14-
return fn(
15-
self,
16-
*args,
17-
**{k: v for k, v in kwargs.items() if k != "class_name"},
18-
)
19-
20-
return new_init
21-
22-
23-
for component in [
24-
dcc.Markdown,
25-
html.A,
26-
html.Blockquote,
27-
html.Div,
28-
html.H1,
29-
html.H2,
30-
html.H3,
31-
html.H4,
32-
html.H5,
33-
html.H6,
34-
html.Hr,
35-
html.I,
36-
html.P,
37-
html.Small,
38-
]:
39-
component.__init__ = class_name_shim(component.__init__)
40-
41-
429
from .components.table.simple import table_body, table_header # noqa
4310
from .components.tabs.simple import tab1_content, tab2_content # noqa
4411
from .markdown_parser import parse # noqa
@@ -195,11 +162,11 @@ def register_apps():
195162

196163
if slug == "layout":
197164
app.layout = html.Div(
198-
parse(app, **kwargs), class_name="layout-demo"
165+
parse(app, **kwargs), className="layout-demo"
199166
)
200167
elif slug == "button_group":
201168
app.layout = html.Div(
202-
parse(app, **kwargs), class_name="button-group-demo"
169+
parse(app, **kwargs), className="button-group-demo"
203170
)
204171
else:
205172
app.layout = parse(app, **kwargs)

docs/components_page/components/__tests__/helpers.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ def py_source_to_app(py_source, env):
88
Create a Dash app from a string defining the app.
99
"""
1010
env = env or {}
11-
# TODO: remove class_name modifiers
12-
exec(
13-
py_source.replace("class_name", "className").replace(
14-
"_className", "_class_name"
15-
),
16-
env,
17-
)
11+
exec(py_source, env)
1812
return env["app"]
1913

2014

@@ -61,27 +55,19 @@ def load_r_app(path, component_name, extra_args=""):
6155
snippet = path.read_text()
6256
if extra_args:
6357
snippet = f"{extra_args}\n{snippet}"
64-
return (
65-
R_WRAPPER.format(
66-
snippet=snippet,
67-
components=component_name,
68-
port=8050,
69-
)
70-
.replace("class_name", "className")
71-
.replace("_className", "_class_name")
72-
) # TODO: remove this in future
58+
return R_WRAPPER.format(
59+
snippet=snippet,
60+
components=component_name,
61+
port=8050,
62+
)
7363

7464

7565
def load_jl_app(path, component_name, extra_args=""):
7666
snippet = path.read_text()
7767
if extra_args:
7868
snippet = f"{extra_args}\n{snippet}"
79-
return (
80-
JL_WRAPPER.format(
81-
snippet=snippet,
82-
components=component_name,
83-
port=8050,
84-
)
85-
.replace("class_name", "className")
86-
.replace("_className", "_class_name")
87-
) # TODO: remove this in future
69+
return JL_WRAPPER.format(
70+
snippet=snippet,
71+
components=component_name,
72+
port=8050,
73+
)

docs/components_page/components/__tests__/test_snippets.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ def assert_layouts_equal(
141141
components=", ".join(x[2] for x in compare),
142142
port=port,
143143
)
144-
.replace("class_name", "className")
145-
.replace("_className", "_class_name") # TODO: remove
146144
)
147145
layout = requests.get(f"{runner.url}/_dash-layout").json()
148146

docs/components_page/components/__tests__/test_tabs.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def test_jl_tabs_card(dashjl):
2323

2424

2525
def check_tabs_card_callbacks(runner):
26-
2726
tab_links = runner.find_elements("#card-tabs > div.nav-item > a.nav-link")
2827
wait.until(lambda: tab_links[1].text == "Tab 2", timeout=4)
2928

@@ -43,45 +42,44 @@ def check_tabs_card_callbacks(runner):
4342
tab1_content <- dbcCard(
4443
dbcCardBody(
4544
list(
46-
htmlP("This is tab 1!", class_name = "card-text"),
45+
htmlP("This is tab 1!", className = "card-text"),
4746
dbcButton("Click here", color = "success")
4847
)
4948
),
50-
class_name = "mt-3"
49+
className = "mt-3"
5150
)
5251
5352
tab2_content <- dbcCard(
5453
dbcCardBody(
5554
list(
56-
htmlP("This is tab 2!", class_name = "card-text"),
55+
htmlP("This is tab 2!", className = "card-text"),
5756
dbcButton("Don't click here", color = "danger")
5857
)
5958
),
60-
class_name = "mt-3",
59+
className = "mt-3",
6160
)
6261
"""
6362

6463
active_tab_content_jl = """
6564
tab1_content = dbc_card(
6665
dbc_cardbody([
67-
html_p("This is tab 1!", class_name="card-text"),
66+
html_p("This is tab 1!", className="card-text"),
6867
dbc_button("Click here", color="success"),
6968
]),
70-
class_name="mt-3",
69+
className="mt-3",
7170
);
7271
7372
tab2_content = dbc_card(
7473
dbc_cardbody([
75-
html_p("This is tab 2!", class_name="card-text"),
74+
html_p("This is tab 2!", className="card-text"),
7675
dbc_button("Don't click here", color="danger"),
7776
]),
78-
class_name="mt-3",
77+
className="mt-3",
7978
);
8079
"""
8180

8281

8382
def test_r_tabs_active_tab(dashr):
84-
8583
r_app = load_r_app(
8684
(HERE.parent / "tabs" / "active_tab.R"),
8785
"tabs",
@@ -92,7 +90,6 @@ def test_r_tabs_active_tab(dashr):
9290

9391

9492
def test_jl_tabs_active_tab(dashjl):
95-
9693
jl_app = load_jl_app(
9794
(HERE.parent / "tabs" / "active_tab.jl"),
9895
"tabs",
@@ -103,7 +100,6 @@ def test_jl_tabs_active_tab(dashjl):
103100

104101

105102
def check_tabs_active_tab_callbacks(runner):
106-
107103
# Get julia to wait until it's loaded
108104
wait.until(lambda: len(runner.find_elements(".card")) > 0, timeout=4)
109105

docs/components_page/components/accordion/callback.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ accordion <- htmlDiv(
2525
id = "accordion",
2626
active_item = "item-1"
2727
),
28-
htmlDiv(id = "accordion-contents", class_name = "mt-3")
28+
htmlDiv(id = "accordion-contents", className = "mt-3")
2929
)
3030
)
3131

docs/components_page/components/accordion/callback.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ accordion = html_div([
2222
id = "accordion",
2323
active_item = "item-1",
2424
),
25-
html_div(id = "accordion-contents", class_name = "mt-3"),
25+
html_div(id = "accordion-contents", className = "mt-3"),
2626
])
2727

2828

docs/components_page/components/accordion/callback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
id="accordion",
2525
active_item="item-1",
2626
),
27-
html.Div(id="accordion-contents", class_name="mt-3"),
27+
html.Div(id="accordion-contents", className="mt-3"),
2828
]
2929
)
3030

docs/components_page/components/alert/auto_dismiss.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ library(dashHtmlComponents)
44
alert <- htmlDiv(
55
list(
66
dbcButton("Toggle",
7-
id = "alert-toggle-auto", class_name = "me-1",
7+
id = "alert-toggle-auto", className = "me-1",
88
n_clicks = 0
99
),
1010
htmlHr(),

docs/components_page/components/alert/auto_dismiss.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using DashBootstrapComponents, DashHtmlComponents
22

33
alert = html_div([
4-
dbc_button("Toggle", id = "alert-toggle-auto", class_name = "me-1", n_clicks = 0),
4+
dbc_button("Toggle", id = "alert-toggle-auto", className = "me-1", n_clicks = 0),
55
html_hr(),
66
dbc_alert(
77
"Hello! I am an auto-dismissing alert!",

docs/components_page/components/alert/auto_dismiss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
alert = html.Div(
55
[
66
dbc.Button(
7-
"Toggle", id="alert-toggle-auto", class_name="me-1", n_clicks=0
7+
"Toggle", id="alert-toggle-auto", className="me-1", n_clicks=0
88
),
99
html.Hr(),
1010
dbc.Alert(

0 commit comments

Comments
 (0)