A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: add footer to sidebar and disbale some Html fluid apis (callout, batch) (#1392)
Myles Scolnickfc1f63bc76ac
diff --git a/frontend/src/components/editor/renderers/vertical-layout/sidebar/sidebar.tsx b/frontend/src/components/editor/renderers/vertical-layout/sidebar/sidebar.tsxindex 703b7e7acc..5c6836df6b 100644--- a/frontend/src/components/editor/renderers/vertical-layout/sidebar/sidebar.tsx+++ b/frontend/src/components/editor/renderers/vertical-layout/sidebar/sidebar.tsx@@ -15,13 +15,13 @@ export const Sidebar = ({ isOpen, toggle }: SidebarProps) => {data-expanded={isOpen}className={cn("app-sidebar auto-collapse-nav",- "absolute top-0 left-0 z-20 h-screen -translate-x-full lg:translate-x-0 transition-[width] ease-in-out duration-300",+ "absolute top-0 left-0 z-20 h-full -translate-x-full lg:translate-x-0 transition-[width] ease-in-out duration-300",// These values need to match wrapped-with-sidebar.tsxisOpen ? "w-72" : "w-[68px]",)}><SidebarToggle isOpen={isOpen} toggle={toggle} />- <div className="relative h-full flex flex-col px-3 pb-4 pt-14 overflow-y-auto shadow-sm border-l">+ <div className="relative h-full flex flex-col px-3 pb-16 pt-14 overflow-y-auto shadow-sm border-l"><SidebarSlot /></div></aside>diff --git a/marimo/_plugins/stateless/flex.py b/marimo/_plugins/stateless/flex.pyindex adb85372e3..c9a74d384c 100644--- a/marimo/_plugins/stateless/flex.py+++ b/marimo/_plugins/stateless/flex.py@@ -22,7 +22,7 @@ def _flex(align: Optional[Literal["start", "end", "center", "stretch"]],wrap: bool,gap: float,- widths: Optional[Sequence[float]],+ child_flexes: Optional[Sequence[Optional[float]]],) -> Html:justify_content_map = {"start": "flex-start",@@ -42,6 +42,7 @@ def _flex(style = create_style({"display": "flex",+ "flex": "1","flex-direction": direction,"justify-content": justify_content_map[justify],"align-items": align_items_map[align],@@ -51,12 +52,12 @@ def _flex()def create_style_for_item(idx: int) -> Optional[str]:- if widths is None:+ if child_flexes is None:return ""- width = widths[idx]- if width is None:+ child_flex = child_flexes[idx]+ if child_flex is None:return ""- return create_style({"flex": f"{width}"})+ return create_style({"flex": f"{child_flex}"})grid_items = [h.div(as_html(item).text, style=create_style_for_item(i))@@ -68,8 +69,13 @@ def _flex(@mddocdef vstack(items: Sequence[object],+ *,align: Optional[Literal["start", "end", "center", "stretch"]] = None,+ justify: Literal[+ "start", "center", "end", "space-between", "space-around"+ ] = "start",gap: float = 0.5,+ heights: Optional[Literal["equal"] | Sequence[float]] = None,) -> Html:"""Stack items vertically, in a column.@@ -105,17 +111,20 @@ def vstack(return _flex(items,direction="column",- justify="start",+ justify=justify,align=align,wrap=False,gap=gap,- widths=None,+ child_flexes=[1 for _ in range(len(items))]+ if heights == "equal"+ else heights,)@mddocdef hstack(items: Sequence[object],+ *,justify: Literal["start", "center", "end", "space-between", "space-around"] = "space-between",@@ -168,7 +177,9 @@ def hstack(align=align,wrap=wrap,gap=gap,- widths=[1 for _ in range(len(items))] if widths == "equal" else widths,+ child_flexes=[1 for _ in range(len(items))]+ if widths == "equal"+ else widths,)diff --git a/marimo/_plugins/stateless/sidebar.py b/marimo/_plugins/stateless/sidebar.pyindex 71b575d985..44f15e4cd6 100644--- a/marimo/_plugins/stateless/sidebar.py+++ b/marimo/_plugins/stateless/sidebar.py@@ -1,6 +1,8 @@# Copyright 2024 Marimo. All rights reserved.from __future__ import annotations+from typing import Any, Optional+from marimo._output import mdfrom marimo._output.formatting import as_htmlfrom marimo._output.hypertext import Html@@ -10,9 +12,7 @@ from marimo._plugins.stateless.flex import vstack@mddoc-def sidebar(- item: object,-) -> Html:+class sidebar(Html):"""Displays content in a sidebar. This is a special layout component thatwill display the content in a sidebar layout, rather than below/above@@ -55,17 +55,51 @@ def sidebar(- An `Html` object."""- # If its a string, wrap in md- if isinstance(item, str):- item = md.md(item)- # If its an array, wrap in vstack- if isinstance(item, list):- item = vstack(item)-- return Html(- build_stateless_plugin(- "marimo-sidebar",- {},- as_html(item).text,+ def __init__(self, item: object, footer: Optional[object] = None) -> None:+ # If its a string, wrap in md+ if isinstance(item, str):+ item = md.md(item)+ # If its an array, wrap in vstack+ if isinstance(item, list):+ item = vstack(item)++ # Maybe add footer+ if footer:+ if isinstance(footer, str):+ footer = md.md(footer)+ if isinstance(footer, list):+ footer = vstack(footer)+ item = vstack([item, footer], justify="space-between")++ super().__init__(+ build_stateless_plugin(+ "marimo-sidebar",+ {},+ as_html(item).text,+ ))- )++ # Not supported+ def batch(self, *args: Any, **kwargs: Any) -> Any:+ del args, kwargs+ raise TypeError(".batch() is not supported on mo.sidebar")++ def center(self, *args: Any, **kwargs: Any) -> Html:+ del args, kwargs+ raise TypeError(".center() is not supported on mo.sidebar")++ def right(self, *args: Any, **kwargs: Any) -> Html:+ del args, kwargs+ raise TypeError(".right() is not supported on mo.sidebar")++ def left(self, *args: Any, **kwargs: Any) -> Html:+ del args, kwargs+ raise TypeError(".left() is not supported on mo.sidebar")++ def callout(self, *args: Any, **kwargs: Any) -> Html:+ del args, kwargs+ raise TypeError(".callout() is not supported on mo.sidebar")++ def style(self, *args: Any, **kwargs: Any) -> Html:+ del args, kwargs+ raise TypeError(".style() is not supported on mo.sidebar")diff --git a/tests/_plugins/stateless/test_flex.py b/tests/_plugins/stateless/test_flex.pyindex cd64a5a3f3..3305b5c5c6 100644--- a/tests/_plugins/stateless/test_flex.py+++ b/tests/_plugins/stateless/test_flex.py@@ -1,4 +1,6 @@# Copyright 2024 Marimo. All rights reserved.+from __future__ import annotations+from marimo._plugins.stateless.flex import hstack, vstack@@ -6,7 +8,13 @@ def test_vstack() -> None:result = vstack(["item1", "item2"], align="center", gap=1)assert (result.text- == "<div style='display: flex;flex-direction: column;justify-content: flex-start;align-items: center;flex-wrap: nowrap;gap: 1rem'><div><span>item1</span></div><div><span>item2</span></div></div>" # noqa: E501+ == "<div style='display: flex;flex: 1;flex-direction: column;justify-content: flex-start;align-items: center;flex-wrap: nowrap;gap: 1rem'><div><span>item1</span></div><div><span>item2</span></div></div>" # noqa: E501+ )++ result = vstack(["item1", "item2"], justify="center", heights=[1, 2])+ assert (+ result.text+ == "<div style='display: flex;flex: 1;flex-direction: column;justify-content: center;align-items: normal;flex-wrap: nowrap;gap: 0.5rem'><div style='flex: 1'><span>item1</span></div><div style='flex: 2'><span>item2</span></div></div>" # noqa: E501)@@ -14,11 +22,11 @@ def test_hstack() -> None:result = hstack(["item1", "item2"], justify="center", gap=1, wrap=True)assert (result.text- == "<div style='display: flex;flex-direction: row;justify-content: center;align-items: normal;flex-wrap: wrap;gap: 1rem'><div><span>item1</span></div><div><span>item2</span></div></div>" # noqa: E501+ == "<div style='display: flex;flex: 1;flex-direction: row;justify-content: center;align-items: normal;flex-wrap: wrap;gap: 1rem'><div><span>item1</span></div><div><span>item2</span></div></div>" # noqa: E501)result = hstack(["item1", "item2"], align="center", widths=[1, 2])assert (result.text- == "<div style='display: flex;flex-direction: row;justify-content: space-between;align-items: center;flex-wrap: nowrap;gap: 0.5rem'><div style='flex: 1'><span>item1</span></div><div style='flex: 2'><span>item2</span></div></div>" # noqa: E501+ == "<div style='display: flex;flex: 1;flex-direction: row;justify-content: space-between;align-items: center;flex-wrap: nowrap;gap: 0.5rem'><div style='flex: 1'><span>item1</span></div><div style='flex: 2'><span>item2</span></div></div>" # noqa: E501)