Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 3 additions & 36 deletions docs/components_page/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,9 @@

import dash
import dash_bootstrap_components as dbc
from dash import dcc, html
from dash import html
from jinja2 import Environment, FileSystemLoader


# TODO: delete once Dash 2.0 is released
def class_name_shim(fn):
def new_init(self, *args, **kwargs):
kwargs["className"] = kwargs.get("class_name", kwargs.get("className"))
return fn(
self,
*args,
**{k: v for k, v in kwargs.items() if k != "class_name"},
)

return new_init


for component in [
dcc.Markdown,
html.A,
html.Blockquote,
html.Div,
html.H1,
html.H2,
html.H3,
html.H4,
html.H5,
html.H6,
html.Hr,
html.I,
html.P,
html.Small,
]:
component.__init__ = class_name_shim(component.__init__)


from .components.table.simple import table_body, table_header # noqa
from .components.tabs.simple import tab1_content, tab2_content # noqa
from .markdown_parser import parse # noqa
Expand Down Expand Up @@ -195,11 +162,11 @@ def register_apps():

if slug == "layout":
app.layout = html.Div(
parse(app, **kwargs), class_name="layout-demo"
parse(app, **kwargs), className="layout-demo"
)
elif slug == "button_group":
app.layout = html.Div(
parse(app, **kwargs), class_name="button-group-demo"
parse(app, **kwargs), className="button-group-demo"
)
else:
app.layout = parse(app, **kwargs)
Expand Down
36 changes: 11 additions & 25 deletions docs/components_page/components/__tests__/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ def py_source_to_app(py_source, env):
Create a Dash app from a string defining the app.
"""
env = env or {}
# TODO: remove class_name modifiers
exec(
py_source.replace("class_name", "className").replace(
"_className", "_class_name"
),
env,
)
exec(py_source, env)
return env["app"]


Expand Down Expand Up @@ -61,27 +55,19 @@ def load_r_app(path, component_name, extra_args=""):
snippet = path.read_text()
if extra_args:
snippet = f"{extra_args}\n{snippet}"
return (
R_WRAPPER.format(
snippet=snippet,
components=component_name,
port=8050,
)
.replace("class_name", "className")
.replace("_className", "_class_name")
) # TODO: remove this in future
return R_WRAPPER.format(
snippet=snippet,
components=component_name,
port=8050,
)


def load_jl_app(path, component_name, extra_args=""):
snippet = path.read_text()
if extra_args:
snippet = f"{extra_args}\n{snippet}"
return (
JL_WRAPPER.format(
snippet=snippet,
components=component_name,
port=8050,
)
.replace("class_name", "className")
.replace("_className", "_class_name")
) # TODO: remove this in future
return JL_WRAPPER.format(
snippet=snippet,
components=component_name,
port=8050,
)
2 changes: 0 additions & 2 deletions docs/components_page/components/__tests__/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ def assert_layouts_equal(
components=", ".join(x[2] for x in compare),
port=port,
)
.replace("class_name", "className")
.replace("_className", "_class_name") # TODO: remove
)
layout = requests.get(f"{runner.url}/_dash-layout").json()

Expand Down
20 changes: 8 additions & 12 deletions docs/components_page/components/__tests__/test_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def test_jl_tabs_card(dashjl):


def check_tabs_card_callbacks(runner):

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

Expand All @@ -43,45 +42,44 @@ def check_tabs_card_callbacks(runner):
tab1_content <- dbcCard(
dbcCardBody(
list(
htmlP("This is tab 1!", class_name = "card-text"),
htmlP("This is tab 1!", className = "card-text"),
dbcButton("Click here", color = "success")
)
),
class_name = "mt-3"
className = "mt-3"
)

tab2_content <- dbcCard(
dbcCardBody(
list(
htmlP("This is tab 2!", class_name = "card-text"),
htmlP("This is tab 2!", className = "card-text"),
dbcButton("Don't click here", color = "danger")
)
),
class_name = "mt-3",
className = "mt-3",
)
"""

active_tab_content_jl = """
tab1_content = dbc_card(
dbc_cardbody([
html_p("This is tab 1!", class_name="card-text"),
html_p("This is tab 1!", className="card-text"),
dbc_button("Click here", color="success"),
]),
class_name="mt-3",
className="mt-3",
);

tab2_content = dbc_card(
dbc_cardbody([
html_p("This is tab 2!", class_name="card-text"),
html_p("This is tab 2!", className="card-text"),
dbc_button("Don't click here", color="danger"),
]),
class_name="mt-3",
className="mt-3",
);
"""


def test_r_tabs_active_tab(dashr):

r_app = load_r_app(
(HERE.parent / "tabs" / "active_tab.R"),
"tabs",
Expand All @@ -92,7 +90,6 @@ def test_r_tabs_active_tab(dashr):


def test_jl_tabs_active_tab(dashjl):

jl_app = load_jl_app(
(HERE.parent / "tabs" / "active_tab.jl"),
"tabs",
Expand All @@ -103,7 +100,6 @@ def test_jl_tabs_active_tab(dashjl):


def check_tabs_active_tab_callbacks(runner):

# Get julia to wait until it's loaded
wait.until(lambda: len(runner.find_elements(".card")) > 0, timeout=4)

Expand Down
2 changes: 1 addition & 1 deletion docs/components_page/components/accordion/callback.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ accordion <- htmlDiv(
id = "accordion",
active_item = "item-1"
),
htmlDiv(id = "accordion-contents", class_name = "mt-3")
htmlDiv(id = "accordion-contents", className = "mt-3")
)
)

Expand Down
2 changes: 1 addition & 1 deletion docs/components_page/components/accordion/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ accordion = html_div([
id = "accordion",
active_item = "item-1",
),
html_div(id = "accordion-contents", class_name = "mt-3"),
html_div(id = "accordion-contents", className = "mt-3"),
])


Expand Down
2 changes: 1 addition & 1 deletion docs/components_page/components/accordion/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
id="accordion",
active_item="item-1",
),
html.Div(id="accordion-contents", class_name="mt-3"),
html.Div(id="accordion-contents", className="mt-3"),
]
)

Expand Down
2 changes: 1 addition & 1 deletion docs/components_page/components/alert/auto_dismiss.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ library(dashHtmlComponents)
alert <- htmlDiv(
list(
dbcButton("Toggle",
id = "alert-toggle-auto", class_name = "me-1",
id = "alert-toggle-auto", className = "me-1",
n_clicks = 0
),
htmlHr(),
Expand Down
2 changes: 1 addition & 1 deletion docs/components_page/components/alert/auto_dismiss.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using DashBootstrapComponents, DashHtmlComponents

alert = html_div([
dbc_button("Toggle", id = "alert-toggle-auto", class_name = "me-1", n_clicks = 0),
dbc_button("Toggle", id = "alert-toggle-auto", className = "me-1", n_clicks = 0),
html_hr(),
dbc_alert(
"Hello! I am an auto-dismissing alert!",
Expand Down
2 changes: 1 addition & 1 deletion docs/components_page/components/alert/auto_dismiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
alert = html.Div(
[
dbc.Button(
"Toggle", id="alert-toggle-auto", class_name="me-1", n_clicks=0
"Toggle", id="alert-toggle-auto", className="me-1", n_clicks=0
),
html.Hr(),
dbc.Alert(
Expand Down
4 changes: 2 additions & 2 deletions docs/components_page/components/alert/content.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library(dashHtmlComponents)

alert <- dbcAlert(
list(
htmlH4("Well done!", class_name = "alert-heading"),
htmlH4("Well done!", className = "alert-heading"),
htmlP(
paste(
"This is a success alert with loads of extra text in it. So much",
Expand All @@ -14,7 +14,7 @@ alert <- dbcAlert(
htmlHr(),
htmlP(
"Let's put some more text down here, but remove the bottom margin",
class_name = "mb-0",
className = "mb-0",
)
)
)
4 changes: 2 additions & 2 deletions docs/components_page/components/alert/content.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using DashBootstrapComponents, DashHtmlComponents

alert = dbc_alert([
html_h4("Well done!", class_name = "alert-heading"),
html_h4("Well done!", className = "alert-heading"),
html_p(
"This is a success alert with loads of extra text in it. So much " *
"that you can see how spacing within an alert works with this " *
Expand All @@ -10,6 +10,6 @@ alert = dbc_alert([
html_hr(),
html_p(
"Let's put some more text down here, but remove the bottom margin",
class_name = "mb-0",
className = "mb-0",
),
]);
4 changes: 2 additions & 2 deletions docs/components_page/components/alert/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

alert = dbc.Alert(
[
html.H4("Well done!", class_name="alert-heading"),
html.H4("Well done!", className="alert-heading"),
html.P(
"This is a success alert with loads of extra text in it. So much "
"that you can see how spacing within an alert works with this "
Expand All @@ -12,7 +12,7 @@
html.Hr(),
html.P(
"Let's put some more text down here, but remove the bottom margin",
class_name="mb-0",
className="mb-0",
),
]
)
2 changes: 1 addition & 1 deletion docs/components_page/components/alert/dismiss.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ alert <- htmlDiv(
dbcButton(
"Toggle alert with fade",
id = "alert-toggle-fade", n_clicks = 0,
class_name = "me-1"
className = "me-1"
),
dbcButton("Toggle alert without fade",
id = "alert-toggle-no-fade",
Expand Down
2 changes: 1 addition & 1 deletion docs/components_page/components/alert/dismiss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ alert = html_div([
dbc_button(
"Toggle alert with fade",
id = "alert-toggle-fade",
class_name = "me-1",
className = "me-1",
n_clicks = 0,
),
dbc_button("Toggle alert without fade", id = "alert-toggle-no-fade", n_clicks = 0),
Expand Down
2 changes: 1 addition & 1 deletion docs/components_page/components/alert/dismiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
dbc.Button(
"Toggle alert with fade",
id="alert-toggle-fade",
class_name="me-1",
className="me-1",
n_clicks=0,
),
dbc.Button(
Expand Down
16 changes: 8 additions & 8 deletions docs/components_page/components/alert/icon.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ alerts <- htmlDiv(
list(
dbcAlert(
list(
htmlI(class_name = "bi bi-info-circle-fill me-2"),
htmlI(className = "bi bi-info-circle-fill me-2"),
"An example info alert with an icon"
),
color = "info",
class_name = "d-flex align-items-center"
className = "d-flex align-items-center"
),
dbcAlert(
list(
htmlI(class_name = "bi bi-check-circle-fill me-2"),
htmlI(className = "bi bi-check-circle-fill me-2"),
"An example success alert with an icon"
),
color = "success",
class_name = "d-flex align-items-center"
className = "d-flex align-items-center"
),
dbcAlert(
list(
htmlI(class_name = "bi bi-exclamation-triangle-fill me-2"),
htmlI(className = "bi bi-exclamation-triangle-fill me-2"),
"An example warning alert with an icon"
),
color = "warning",
class_name = "d-flex align-items-center"
className = "d-flex align-items-center"
),
dbcAlert(
list(
htmlI(class_name = "bi bi-x-octagon-fill me-2"),
htmlI(className = "bi bi-x-octagon-fill me-2"),
"An example danger alert with an icon"
),
color = "danger",
class_name = "d-flex align-items-center"
className = "d-flex align-items-center"
)
)
)
Loading