|  | 
|  | 1 | +""" | 
|  | 2 | +Shims for `ui.insert_*()`, `ui.update_*()`, etc. functions that lead to a more ergonomic | 
|  | 3 | +Express API. | 
|  | 4 | +
 | 
|  | 5 | +These functions tend to have one issue in common: if they were re-exported verbatim from | 
|  | 6 | +Core to Express, they would want to take RecallContextManager(s) as input, which leads | 
|  | 7 | +to a somewhat awkward API. That's because, you'd have to know to use something like | 
|  | 8 | +@ui.hold() pass the UI as a value without displaying it. | 
|  | 9 | +""" | 
|  | 10 | + | 
|  | 11 | +from typing import Literal, Optional | 
|  | 12 | + | 
|  | 13 | +from htmltools import TagAttrs, TagChild | 
|  | 14 | + | 
|  | 15 | +from ..._docstring import add_example | 
|  | 16 | +from ...session import Session | 
|  | 17 | +from ...types import MISSING, MISSING_TYPE | 
|  | 18 | + | 
|  | 19 | + | 
|  | 20 | +@add_example() | 
|  | 21 | +def insert_accordion_panel( | 
|  | 22 | +    id: str, | 
|  | 23 | +    panel_title: str, | 
|  | 24 | +    *panel_contents: TagChild | TagAttrs, | 
|  | 25 | +    panel_value: str | MISSING_TYPE | None = MISSING, | 
|  | 26 | +    panel_icon: TagChild = None, | 
|  | 27 | +    target: Optional[str] = None, | 
|  | 28 | +    position: Literal["after", "before"] = "after", | 
|  | 29 | +    session: Optional[Session] = None, | 
|  | 30 | +) -> None: | 
|  | 31 | +    """ | 
|  | 32 | +    Insert an accordion panel into an existing accordion. | 
|  | 33 | +
 | 
|  | 34 | +    Parameters | 
|  | 35 | +    ---------- | 
|  | 36 | +    id | 
|  | 37 | +        A string that matches an existing :func:`~shiny.ui.express.accordion`'s `id`. | 
|  | 38 | +    panel_title | 
|  | 39 | +        The title to appear in the panel header. | 
|  | 40 | +    panel_contents | 
|  | 41 | +        UI elements for the panel's body. Can also be a dict of tag attributes for the | 
|  | 42 | +        body's HTML container. | 
|  | 43 | +    panel_value | 
|  | 44 | +        A character string that uniquely identifies this panel. If `MISSING`, the | 
|  | 45 | +        `title` will be used. | 
|  | 46 | +    panel_icon | 
|  | 47 | +        A :class:`~htmltools.TagChild` which is positioned just before the `title`. | 
|  | 48 | +    target | 
|  | 49 | +        The `value` of an existing panel to insert next to. | 
|  | 50 | +    position | 
|  | 51 | +        Should `panel` be added before or after the target? When `target=None`, | 
|  | 52 | +        `"after"` will append after the last panel and `"before"` will prepend before | 
|  | 53 | +        the first panel. | 
|  | 54 | +    session | 
|  | 55 | +        A Shiny session object (the default should almost always be used). | 
|  | 56 | +
 | 
|  | 57 | +    References | 
|  | 58 | +    ---------- | 
|  | 59 | +    [Bootstrap Accordion](https://getbootstrap.com/docs/5.3/components/accordion/) | 
|  | 60 | +
 | 
|  | 61 | +    See Also | 
|  | 62 | +    -------- | 
|  | 63 | +    * :func:`~shiny.ui.express.accordion` | 
|  | 64 | +    * :func:`~shiny.ui.express.accordion_panel` | 
|  | 65 | +    * :func:`~shiny.ui.express.update_accordion` | 
|  | 66 | +    """ | 
|  | 67 | + | 
|  | 68 | +    from ...ui import accordion_panel, insert_accordion_panel | 
|  | 69 | + | 
|  | 70 | +    panel = accordion_panel( | 
|  | 71 | +        panel_title, *panel_contents, value=panel_value, icon=panel_icon | 
|  | 72 | +    ) | 
|  | 73 | + | 
|  | 74 | +    insert_accordion_panel( | 
|  | 75 | +        id=id, | 
|  | 76 | +        panel=panel, | 
|  | 77 | +        target=target, | 
|  | 78 | +        position=position, | 
|  | 79 | +        session=session, | 
|  | 80 | +    ) | 
0 commit comments