Skip to content

Commit

Permalink
Update InfoBox API
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Aug 22, 2024
1 parent d16f596 commit 93d2986
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
33 changes: 20 additions & 13 deletions aiidalab_widgets_base/infobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,37 @@
class InfoBox(ipw.VBox):
"""The `InfoBox` component is used to provide additional info regarding a widget or an app."""

def __init__(self, **kwargs):
"""`InfoBox` constructor."""
custom_css = kwargs.pop("custom-css", "")
def __init__(self, classes: list[str] | None = None, **kwargs):
"""`InfoBox` constructor.
Parameters
----------
`classes` : `list[str]`, optional
One or more CSS classes.
"""
super().__init__(**kwargs)
self.add_class("info-box")
if custom_css:
self.add_class(custom_css)
for custom_classes in classes or []:
for custom_class in custom_classes.split(" "):
if custom_class:
self.add_class(custom_class)


class InAppGuide(InfoBox):
"""The `InfoAppGuide` is used to set up in-app guides that may be toggle in unison."""

def __init__(self, guide_class="", **kwargs):
def __init__(self, guide_id: str, classes: list[str] | None = None, **kwargs):
"""`InAppGuide` constructor.
parameters
Parameters
----------
`guide_class` : `str`
A CSS class marking the widget as part of a guide collection.
May also be used for custom styling.
`guide_id` : `str`
The unique identifier for the guide.
`classes` : `list[str]`, optional
One or more CSS classes.
"""
super().__init__(**kwargs)
self.add_class("in-app-guide")
self.add_class(guide_class)
classes = ["in-app-guide", *(classes or []), guide_id]
super().__init__(classes=classes, **kwargs)


class FirstTimeUserMessage(ipw.VBox):
Expand Down
15 changes: 8 additions & 7 deletions tests/test_infobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@

def test_infobox_classes():
"""Test `InfoBox` classes."""
infobox = InfoBox()
assert "info-box" in infobox._dom_classes
infobox = InfoBox(**{"custom-css": "custom-info-box"})
custom_classes = ["custom-1", "custom-2 custom-3"]
infobox = InfoBox(classes=custom_classes)
assert all(
css_class in infobox._dom_classes
for css_class in (
"info-box",
"custom-info-box",
"custom-1",
"custom-2",
"custom-3",
)
)


def test_in_app_guide():
"""Test `InAppGuide` class."""
guide_class = "some_guide"
in_app_guide = InAppGuide(guide_class=guide_class)
guide_id = "some_guide"
in_app_guide = InAppGuide(guide_id=guide_id)
assert all(
css_class in in_app_guide._dom_classes
for css_class in (
"info-box",
"in-app-guide",
guide_class,
guide_id,
)
)

Expand Down

0 comments on commit 93d2986

Please sign in to comment.