|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import TYPE_CHECKING, Literal, Optional, TypeVar |
| 3 | +from typing import TYPE_CHECKING, Literal, Optional, TypeVar, Union |
4 | 4 |
|
5 | 5 | from htmltools import Tag, TagAttrs, TagAttrValue, TagChild, css, tags |
6 | 6 |
|
|
16 | 16 |
|
17 | 17 | if TYPE_CHECKING: |
18 | 18 | from ..session import Session |
| 19 | + from ..express._recall_context import RecallContextManager |
19 | 20 |
|
20 | 21 | __all__ = ( |
21 | 22 | "accordion", |
@@ -447,7 +448,7 @@ def update_accordion( |
447 | 448 | @add_example() |
448 | 449 | def insert_accordion_panel( |
449 | 450 | id: str, |
450 | | - panel: AccordionPanel, |
| 451 | + panel: Union[AccordionPanel, "RecallContextManager[AccordionPanel]"], |
451 | 452 | target: Optional[str] = None, |
452 | 453 | position: Literal["after", "before"] = "after", |
453 | 454 | session: Optional[Session] = None, |
@@ -486,14 +487,24 @@ def insert_accordion_panel( |
486 | 487 | if position not in ("after", "before"): |
487 | 488 | raise ValueError("`position` must be either 'after' or 'before'") |
488 | 489 | session = require_active_session(session) |
| 490 | + |
| 491 | + # Handle both AccordionPanel and RecallContextManager[AccordionPanel] |
| 492 | + from ..express._recall_context import RecallContextManager |
| 493 | + if isinstance(panel, RecallContextManager): |
| 494 | + # This is a RecallContextManager, extract the AccordionPanel |
| 495 | + accordion_panel = panel.fn(*panel.args, **panel.kwargs) |
| 496 | + else: |
| 497 | + # This is already an AccordionPanel |
| 498 | + accordion_panel = panel |
| 499 | + |
489 | 500 | # Add accordion ID to panel; Used when `accordion(multiple=False)` |
490 | | - panel._accordion_id = id |
| 501 | + accordion_panel._accordion_id = id |
491 | 502 |
|
492 | 503 | _send_panel_message( |
493 | 504 | id, |
494 | 505 | session, |
495 | 506 | method="insert", |
496 | | - panel=session._process_ui(panel.resolve()), |
| 507 | + panel=session._process_ui(accordion_panel.resolve()), |
497 | 508 | target=None if target is None else _assert_str(target), |
498 | 509 | position=position, |
499 | 510 | ) |
|
0 commit comments