Skip to content

Commit 7dcfb0a

Browse files
committed
add get_alarm_window() to MPComponent
1 parent d51cae8 commit 7dcfb0a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

crystal_toolkit/components/pourbaix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ def _sub_layouts(self) -> dict[str, Component]:
460460
[
461461
html.Div(
462462
[
463-
dcc.ConfirmDialog(
464-
id=self.id("invalid-comp-alarm"),
463+
self.get_alarm_window(
464+
self.id("invalid-comp-alarm"),
465465
message="Illegal composition entry!",
466466
),
467467
html.Div(
@@ -521,7 +521,7 @@ def _sub_layouts(self) -> dict[str, Component]:
521521
),
522522
html.Div(
523523
[
524-
dcc.ConfirmDialog(
524+
self.get_alarm_window(
525525
id=self.id("invalid-conc-alarm"),
526526
message=f"Illegal concentration entry! Must be between {MIN_CONCENTRATION} and {MAX_CONCENTRATION} M",
527527
),

crystal_toolkit/core/mpcomponent.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,32 @@ def pair_element(idx, key=None, value=None):
627627

628628
return add_label_help(dict_input, label, help_str)
629629

630+
def get_alarm_window(
631+
self,
632+
id: str,
633+
message: str,
634+
**kwargs,
635+
):
636+
"""Get the pop-out alarm window component, default set to not display
637+
Eaxmple:
638+
self.get_alarm_window(
639+
self.id("invalid-comp-alarm"),
640+
message="Illegal composition entry!"
641+
),
642+
643+
Return True in the callback function to show alarm
644+
Output(self.id("invalid-conc-alarm"), "displayed") -> True
645+
646+
Args:
647+
:param id: The name of the corresponding Python input, this is used
648+
to name the component.
649+
:param message (str): A default value for this input.
650+
"""
651+
if not message:
652+
raise ValueError("The error message cannot be empty!")
653+
654+
return dcc.ConfirmDialog(id=id, message=message, displayed=False, **kwargs)
655+
630656
def get_kwarg_id(self, kwarg_name) -> dict[str, str]:
631657
return {
632658
"component_id": self._id,

0 commit comments

Comments
 (0)