Skip to content

Commit 35229d7

Browse files
committed
made AIO subclassing html.Div, and move layout to __init__
1 parent 35d49ca commit 35229d7

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

crystal_toolkit/components/error_msg.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
}
9595

9696

97-
class ErrorMessageAIO(MPComponent):
97+
class ErrorMessageAIO(html.Div, MPComponent):
9898
class ids:
9999
wrapper = lambda aio_id: {
100100
"component": "ErrorMessageAIO",
@@ -205,6 +205,19 @@ def __init__(
205205
if style:
206206
self.notification_style.update(style)
207207

208+
# Define the component's layout, this is originally from `layout()` for MPComponent
209+
# But since this is AIO, which subclassing html.Div
210+
sub_layouts = self._sub_layouts
211+
super().__init__(
212+
[ # Equivalent to `html.Div([...])`
213+
dcc.Store(id=self.ids.visible(self.snake_id), data=False),
214+
sub_layouts["notification_div"],
215+
sub_layouts["interval"],
216+
],
217+
id=self.ids.wrapper(self.snake_id),
218+
style={"display": "none"},
219+
)
220+
208221
@property
209222
def _sub_layouts(self):
210223
# Build inner content
@@ -265,6 +278,7 @@ def _sub_layouts(self):
265278

266279
return {"notification_div": notification_div, "interval": interval}
267280

281+
"""
268282
def layout(self) -> html.Div:
269283
sub_layouts = self._sub_layouts
270284
return html.Div(
@@ -276,6 +290,7 @@ def layout(self) -> html.Div:
276290
id=self.ids.wrapper(self.snake_id),
277291
style={"display": "none"},
278292
)
293+
"""
279294

280295
@callback(
281296
Output(ids.wrapper(MATCH), "style"),

crystal_toolkit/components/pourbaix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,12 @@ def _sub_layouts(self) -> dict[str, Component]:
463463
"Invalid composition input!",
464464
aio_id=self.id("invalid-comp-alarm"),
465465
msg_type="error",
466-
).layout(),
466+
),
467467
ErrorMessageAIO(
468468
"Invalid concentration input!",
469469
aio_id=self.id("invalid-conc-alarm"),
470470
msg_type="error",
471-
).layout(),
471+
),
472472
html.Div(
473473
[
474474
html.Div(

0 commit comments

Comments
 (0)