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
Add bordered grid and image styling (#345)
Myles Scolnicke3a22134c949
diff --git a/frontend/src/components/editor/renderers/grid-layout/grid-layout.tsx b/frontend/src/components/editor/renderers/grid-layout/grid-layout.tsxindex 8153b0cff8..8ebf3b450f 100644--- a/frontend/src/components/editor/renderers/grid-layout/grid-layout.tsx+++ b/frontend/src/components/editor/renderers/grid-layout/grid-layout.tsx@@ -1,5 +1,11 @@/* Copyright 2023 Marimo. All rights reserved. */-import React, { PropsWithChildren, memo, useMemo, useState } from "react";+import React, {+ PropsWithChildren,+ memo,+ useEffect,+ useMemo,+ useState,+} from "react";import { Responsive, WidthProvider } from "react-grid-layout";import { ICellRendererProps } from "../types";import { GridLayout, GridLayoutCellSide } from "./types";@@ -35,6 +41,7 @@ import {import { Objects } from "@/utils/objects";import { Maps } from "@/utils/maps";import { startCase } from "lodash-es";+import { BorderAllIcon } from "@radix-ui/react-icons";type Props = ICellRendererProps<GridLayout>;@@ -69,6 +76,20 @@ export const GridLayoutRenderer: React.FC<Props> = ({[layout.columns]);+ // Add class to update the background of the app+ useEffect(() => {+ const appEl = document.getElementById("App");+ if (layout.bordered) {+ appEl?.classList.add("grid-bordered");+ } else {+ appEl?.classList.remove("grid-bordered");+ }++ return () => {+ appEl?.classList.remove("grid-bordered");+ };+ }, [layout.bordered]);+const { isDragging, ...dragProps } = useIsDragging();const enableInteractions = !isReading && !isLocked;@@ -101,10 +122,11 @@ export const GridLayoutRenderer: React.FC<Props> = ({};const styles: React.CSSProperties = {};+ // Max width stylesif (layout.maxWidth) {styles.maxWidth = `${layout.maxWidth}px`;- styles.margin = "0 auto";}+ // Editing background stylesif (enableInteractions) {styles.backgroundImage ="repeating-linear-gradient(var(--gray-4) 0 1px, transparent 1px 100%), repeating-linear-gradient(90deg, var(--gray-4) 0 1px, transparent 1px 100%)";@@ -122,9 +144,16 @@ export const GridLayoutRenderer: React.FC<Props> = ({cols={cols}allowOverlap={false}className={cn(- "w-full",- !isReading && "min-h-full",- isReading && "disable-animation",+ "w-full mx-auto bg-background flex-1 min-h-full",+ // Show grid border and background when editing+ enableInteractions && "bg-[var(--slate-2)] border-r",+ // Disable animations and add padding when reading+ isReading && "disable-animation px-4 ",+ // Add border styles+ layout.bordered &&+ "border-t border-x rounded-t shadow-sm overflow-hidden",+ // Add additional padding if bordered when reading+ layout.bordered && isReading && "mt-4 w-[calc(100%-2rem)]",!layout.maxWidth && "min-w-[800px]")}margin={MARGIN}@@ -237,16 +266,15 @@ export const GridLayoutRenderer: React.FC<Props> = ({isLocked={isLocked}setIsLocked={setIsLocked}/>- <div className={cn("relative flex gap-2 px-2 pb-2 z-10")}>+ <div className={cn("relative flex gap-2 px-2 z-10")}><divclassName={cn(- "flex-grow overflow-auto border rounded bg-[var(--slate-2)] shadow-sm transparent-when-disconnected",- !enableInteractions && "bg-background"+ "flex-grow overflow-auto transparent-when-disconnected")}>{grid}</div>- <div className="flex-none flex flex-col w-[300px] p-2 gap-2 overflow-auto h-full bg-[var(--slate-2)] border rounded shadow-sm transparent-when-disconnected">+ <div className="flex-none flex flex-col w-[300px] p-2 gap-2 overflow-auto h-full bg-[var(--slate-2)] border-t border-x rounded-t shadow-sm transparent-when-disconnected"><div className="text font-bold text-[var(--slate-20)] flex-shrink-0">Outputs</div>@@ -349,7 +377,7 @@ const GridControls: React.FC<{setIsLocked: (isLocked: boolean) => void;}> = ({ layout, setLayout, isLocked, setIsLocked }) => {return (- <div className="flex flex-row absolute left-5 top-4 gap-4 w-full justify-end pr-[450px]">+ <div className="flex flex-row absolute left-5 top-4 gap-4 w-full justify-end pr-[350px]"><div className="flex flex-row items-center gap-2"><Label htmlFor="columns">Columns</Label><Input@@ -391,6 +419,7 @@ const GridControls: React.FC<{type="number"value={layout.maxWidth}className="w-[70px]"+ step={100}placeholder="Full"onChange={(e) => {setLayout({@@ -400,6 +429,23 @@ const GridControls: React.FC<{}}/></div>+ <div className="flex flex-row items-center gap-2">+ <Label className="flex flex-row items-center gap-1" htmlFor="lock">+ <BorderAllIcon className="h-3 w-3" />+ Bordered+ </Label>+ <Switch+ id="lock"+ checked={layout.bordered}+ size="sm"+ onCheckedChange={(bordered) => {+ setLayout({+ ...layout,+ bordered,+ });+ }}+ />+ </div><div className="flex flex-row items-center gap-2"><Label className="flex flex-row items-center gap-1" htmlFor="lock"><LockIcon className="h-3 w-3" />diff --git a/frontend/src/components/editor/renderers/grid-layout/plugin.tsx b/frontend/src/components/editor/renderers/grid-layout/plugin.tsxindex 0c3167f86f..739c04f63e 100644--- a/frontend/src/components/editor/renderers/grid-layout/plugin.tsx+++ b/frontend/src/components/editor/renderers/grid-layout/plugin.tsx@@ -27,6 +27,7 @@ export const GridLayoutPlugin: ICellRendererPlugin<columns: z.number().min(1),rowHeight: z.number().min(1),maxWidth: z.number().optional(),+ bordered: z.boolean().optional(),cells: z.array(z.object({position: z@@ -84,9 +85,12 @@ export const GridLayoutPlugin: ICellRendererPlugin<});return {+ // Grid configcolumns: serialized.columns,rowHeight: serialized.rowHeight,maxWidth: serialized.maxWidth,+ bordered: serialized.bordered,+ // Cell configcells: cellLayouts,cellSide: cellSide,scrollableCells: scrollableCells,@@ -115,9 +119,12 @@ export const GridLayoutPlugin: ICellRendererPlugin<});return {+ // Grid configcolumns: layout.columns,rowHeight: layout.rowHeight,maxWidth: layout.maxWidth,+ bordered: layout.bordered,+ // Cell configcells: serializedCells,};},@@ -125,9 +132,12 @@ export const GridLayoutPlugin: ICellRendererPlugin<Component: GridLayoutRenderer,getInitialLayout: () => ({+ // Grid configcolumns: 24,rowHeight: 20,maxWidth: 1400,+ bordered: true,+ // Cell configscrollableCells: new Set(),cellSide: new Map(),cells: [],diff --git a/frontend/src/components/editor/renderers/grid-layout/styles.css b/frontend/src/components/editor/renderers/grid-layout/styles.cssindex 2e6df756f9..76ea74930d 100644--- a/frontend/src/components/editor/renderers/grid-layout/styles.css+++ b/frontend/src/components/editor/renderers/grid-layout/styles.css@@ -19,3 +19,13 @@transition-property: none !important;transition: none !important;}++/* for images we expand the image to fill the grid item */+.output img {+ height: 100%;+ object-fit: contain;+}++#App.grid-bordered {+ background-color: var(--slate-1);+}diff --git a/frontend/src/components/editor/renderers/grid-layout/types.ts b/frontend/src/components/editor/renderers/grid-layout/types.tsindex 40d4cdd555..0449f14218 100644--- a/frontend/src/components/editor/renderers/grid-layout/types.ts+++ b/frontend/src/components/editor/renderers/grid-layout/types.ts@@ -37,6 +37,11 @@ export interface SerializedGridLayout {* track as they move around.*/cells: SerializedGridLayoutCell[];++ /**+ * Bordered grid+ */+ bordered?: boolean;}export interface SerializedGridLayoutCell {diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsxindex 343e740bb6..1f8ae697a2 100644--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx@@ -4,6 +4,7 @@ import { cn } from "@/utils/cn";import { AppConfig } from "@/core/config/config-schema";interface Props {+ className?: string;appConfig: AppConfig;invisible?: boolean;}@@ -11,10 +12,11 @@ interface Props {export const VerticalLayoutWrapper: React.FC<PropsWithChildren<Props>> = ({invisible,appConfig,+ className,children,}) => {return (- <div className="sm:px-16 md:px-32">+ <div className={cn("sm:px-16 md:px-32", className)}><divclassName={cn("m-auto pb-12",diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsxindex 601d651f64..5fe9b78bca 100644--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx@@ -19,7 +19,11 @@ const VerticalLayoutRenderer: React.FC<VerticalLayoutProps> = ({}) => {const { invisible } = useDelayVisibility(cells.length, mode);return (- <VerticalLayoutWrapper invisible={invisible} appConfig={appConfig}>+ <VerticalLayoutWrapper+ className="sm:pt-8"+ invisible={invisible}+ appConfig={appConfig}+ >{cells.map((cell) => (<VerticalCellkey={cell.id}diff --git a/frontend/src/core/App.tsx b/frontend/src/core/App.tsxindex 9b7c2247f7..4ac69404c2 100644--- a/frontend/src/core/App.tsx+++ b/frontend/src/core/App.tsx@@ -15,7 +15,6 @@ import { Controls } from "@/components/editor/Controls";import { DirCompletionInput } from "@/components/editor/DirCompletionInput";import { FilenameForm } from "@/components/editor/FilenameForm";import { UUID } from "../utils/uuid";-import clsx from "clsx";import { WebSocketState } from "./websocket/types";import { useMarimoWebSocket } from "./websocket/useMarimoWebSocket";import {@@ -55,6 +54,7 @@ import { getSerializedLayout } from "./layout/layout";import { useAtom } from "jotai";import { useRunStaleCells } from "../components/editor/cell/useRunCells";import { formatAll } from "./codemirror/format";+import { cn } from "@/utils/cn";interface AppProps {userConfig: UserConfig;@@ -311,7 +311,7 @@ export const App: React.FC<AppProps> = ({ userConfig, appConfig }) => {{statusOverlay}<divid="App"- className={clsx(+ className={cn(connStatus.state === WebSocketState.CLOSED && "disconnected","bg-background w-full h-full text-textColor","flex flex-col overflow-y-auto overflow-x-hidden",@@ -319,9 +319,8 @@ export const App: React.FC<AppProps> = ({ userConfig, appConfig }) => {)}><div- className={clsx(- (isEditing || isPresenting) && "pt-4 sm:pt-12 pb-2 mb-4",- (isPresenting || isReading) && "sm:pt-8"+ className={cn(+ (isEditing || isPresenting) && "pt-4 sm:pt-12 pb-2 mb-4")}>{isEditing && (