Skip to content

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.

improvement: user settings modal (#2348)

Myles Scolnick15fa3dbef1bb
diff --git a/frontend/src/components/app-config/app-config-button.tsx b/frontend/src/components/app-config/app-config-button.tsx
index 3594980b7e..662aeeffdc 100644
--- a/frontend/src/components/app-config/app-config-button.tsx
+++ b/frontend/src/components/app-config/app-config-button.tsx
@@ -4,49 +4,80 @@ import {
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
-import { Button } from "../editor/inputs/Inputs";
+import { Button as EditorButton } from "../editor/inputs/Inputs";
import { SettingsIcon } from "lucide-react";
import { UserConfigForm } from "./user-config-form";
import { Tooltip } from "../ui/tooltip";
+import { Dialog, DialogTrigger, DialogContent } from "../ui/dialog";
import { AppConfigForm } from "@/components/app-config/app-config-form";
+import { atom, useAtom } from "jotai";
+import { Button } from "../ui/button";
interface Props {
showAppConfig?: boolean;
}
+export const settingDialogAtom = atom<boolean>(false);
+
export const ConfigButton: React.FC<Props> = ({ showAppConfig = true }) => {
+ const [settingDialog, setSettingDialog] = useAtom(settingDialogAtom);
+ const button = (
+ <EditorButton
+ aria-label="Config"
+ data-testid="app-config-button"
+ shape="circle"
+ size="small"
+ className="h-[27px] w-[27px]"
+ color="hint-green"
+ >
+ <Tooltip content="Settings">
+ <SettingsIcon strokeWidth={1.8} />
+ </Tooltip>
+ </EditorButton>
+ );
+
+ const userSettingsDialog = (
+ <DialogContent className="w-[80vw] h-[70vh] overflow-hidden sm:max-w-5xl top-[15vh] p-0">
+ <UserConfigForm />
+ </DialogContent>
+ );
+
+ if (!showAppConfig) {
+ return (
+ <Dialog open={settingDialog} onOpenChange={setSettingDialog}>
+ <DialogTrigger>{button}</DialogTrigger>
+ {userSettingsDialog}
+ </Dialog>
+ );
+ }
+
return (
- <Popover>
- <PopoverTrigger asChild={true}>
- <Button
- aria-label="Config"
- data-testid="app-config-button"
- shape="circle"
- size="small"
- className="h-[27px] w-[27px]"
- color="hint-green"
+ <>
+ <Popover>
+ <PopoverTrigger asChild={true}>{button}</PopoverTrigger>
+ <PopoverContent
+ className="w-80 overflow-auto"
+ align="end"
+ side="bottom"
+ // prevent focus outside to hack around a bug in which
+ // interacting with buttons closes the popover ...
+ onFocusOutside={(evt) => evt.preventDefault()}
>
- <Tooltip content="Settings">
- <SettingsIcon strokeWidth={1.8} />
- </Tooltip>
- </Button>
- </PopoverTrigger>
- <PopoverContent
- className="w-80 h-[90vh] overflow-auto"
- align="end"
- side="bottom"
- // prevent focus outside to hack around a bug in which
- // interacting with buttons closes the popover ...
- onFocusOutside={(evt) => evt.preventDefault()}
- >
- {showAppConfig && (
- <>
- <AppConfigForm />
- <div className="h-px bg-border my-4" />
- </>
- )}
- <UserConfigForm />
- </PopoverContent>
- </Popover>
+ <AppConfigForm />
+ <div className="h-px bg-border my-2" />
+ <Button
+ onClick={() => setSettingDialog(true)}
+ variant="link"
+ className="px-0"
+ >
+ <SettingsIcon strokeWidth={1.8} className="w-4 h-4 mr-2" />
+ User settings
+ </Button>
+ </PopoverContent>
+ </Popover>
+ <Dialog open={settingDialog} onOpenChange={setSettingDialog}>
+ {userSettingsDialog}
+ </Dialog>
+ </>
);
};
diff --git a/frontend/src/components/app-config/common.tsx b/frontend/src/components/app-config/common.tsx
index 7c37240387..ae20242e16 100644
--- a/frontend/src/components/app-config/common.tsx
+++ b/frontend/src/components/app-config/common.tsx
@@ -1,5 +1,6 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import type { PropsWithChildren } from "react";
+import { cn } from "@/utils/cn";
+import type { HTMLProps, PropsWithChildren } from "react";
export const SettingTitle: React.FC<PropsWithChildren> = ({ children }) => {
return (
@@ -9,9 +10,19 @@ export const SettingTitle: React.FC<PropsWithChildren> = ({ children }) => {
);
};
-export const SettingSubtitle: React.FC<PropsWithChildren> = ({ children }) => {
+export const SettingSubtitle: React.FC<HTMLProps<HTMLDivElement>> = ({
+ children,
+ className,
+ ...props
+}) => {
return (
- <div className="text-sm font-semibold underline-offset-2 text-accent-foreground uppercase tracking-wide">
+ <div
+ {...props}
+ className={cn(
+ "text-sm font-semibold underline-offset-2 text-accent-foreground uppercase tracking-wide",
+ className,
+ )}
+ >
{children}
</div>
);
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsx
index eb580f8f93..3356cf3bdf 100644
--- a/frontend/src/components/app-config/user-config-form.tsx
+++ b/frontend/src/components/app-config/user-config-form.tsx
@@ -1,6 +1,10 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import { zodResolver } from "@hookform/resolvers/zod";
+import { SettingSubtitle } from "./common";
+
+import React, { useRef, useState } from "react";
import { useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useSetAtom } from "jotai";
import {
Form,
FormControl,
@@ -10,35 +14,79 @@ import {
FormLabel,
FormMessage,
} from "@/components/ui/form";
+import { Input } from "@/components/ui/input";
+import { Checkbox } from "@/components/ui/checkbox";
+import { Button } from "@/components/ui/button";
+import { NativeSelect } from "@/components/ui/native-select";
+import { NumberField } from "@/components/ui/number-field";
+import { Kbd } from "@/components/ui/kbd";
+import { CopilotConfig } from "@/core/codemirror/copilot/copilot-config";
+import { KEYMAP_PRESETS } from "@/core/codemirror/keymaps/keymaps";
+import { useUserConfig } from "@/core/config/config";
import {
+ UserConfigSchema,
APP_WIDTHS,
+ PackageManagerNames,
type UserConfig,
- UserConfigSchema,
-} from "../../core/config/config-schema";
-import { Checkbox } from "../ui/checkbox";
-import { Input } from "../ui/input";
-import { saveUserConfig } from "../../core/network/requests";
-import { useUserConfig } from "../../core/config/config";
-import { NativeSelect } from "../ui/native-select";
-import { KEYMAP_PRESETS } from "@/core/codemirror/keymaps/keymaps";
-import { CopilotConfig } from "@/core/codemirror/copilot/copilot-config";
-import { SettingTitle, SettingDescription, SettingSubtitle } from "./common";
-import { THEMES } from "@/theme/useTheme";
+} from "@/core/config/config-schema";
+import { saveUserConfig } from "@/core/network/requests";
import { isWasm } from "@/core/wasm/utils";
-import { PackageManagerNames } from "../../core/config/config-schema";
-import { Kbd } from "../ui/kbd";
-import { NumberField } from "@/components/ui/number-field";
-import { useRef } from "react";
-import { useSetAtom } from "jotai";
+import { THEMES } from "@/theme/useTheme";
import { keyboardShortcutsAtom } from "../editor/controls/keyboard-shortcuts";
-import { Button } from "../ui/button";
+import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
+import {
+ EditIcon,
+ MonitorIcon,
+ PackageIcon,
+ CpuIcon,
+ BrainIcon,
+} from "lucide-react";
+import { cn } from "@/utils/cn";
const formItemClasses = "flex flex-row items-center space-x-1 space-y-0";
+const categories = [
+ {
+ id: "editor",
+ label: "Editor",
+ Icon: EditIcon,
+ className: "bg-[var(--blue-4)]",
+ },
+ {
+ id: "display",
+ label: "Display",
+ Icon: MonitorIcon,
+ className: "bg-[var(--grass-4)]",
+ },
+ {
+ id: "packageManagement",
+ label: "Package Management",
+ Icon: PackageIcon,
+ className: "bg-[var(--red-4)]",
+ },
+ {
+ id: "runtime",
+ label: "Runtime",
+ Icon: CpuIcon,
+ className: "bg-[var(--amber-4)]",
+ },
+ {
+ id: "ai",
+ label: "AI",
+ Icon: BrainIcon,
+ className: "bg-[linear-gradient(45deg,var(--purple-5),var(--cyan-5))]",
+ },
+] as const;
+
+type CategoryId = (typeof categories)[number]["id"];
+
export const UserConfigForm: React.FC = () => {
const [config, setConfig] = useUserConfig();
const formElement = useRef<HTMLFormElement>(null);
const setKeyboardShortcutsOpen = useSetAtom(keyboardShortcutsAtom);
+ const [activeCategory, setActiveCategory] = useState<CategoryId>(
+ categories[0].id,
+ );
// Create form
const form = useForm<UserConfig>({
@@ -101,557 +149,711 @@ export const UserConfigForm: React.FC = () => {
}
};
- return (
- <Form {...form}>
- <form
- ref={formElement}
- onChange={form.handleSubmit(onSubmit)}
- className="flex flex-col gap-5"
- >
- <div>
- <SettingTitle>User Config</SettingTitle>
- <SettingDescription>
- Settings applied to all marimo notebooks
- </SettingDescription>
- </div>
- <SettingGroup title="Editor">
- <FormField
- control={form.control}
- name="save.autosave"
- render={({ field }) => (
- <FormItem className={formItemClasses}>
- <FormLabel className="font-normal">Autosave</FormLabel>
- <FormControl>
- <Checkbox
- data-testid="autosave-checkbox"
- checked={field.value === "after_delay"}
- disabled={field.disabled}
- onCheckedChange={(checked) => {
- field.onChange(checked ? "after_delay" : "off");
- }}
- />
- </FormControl>
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="save.autosave_delay"
- render={({ field }) => (
- <FormItem className={formItemClasses}>
- <FormLabel>Autosave delay (seconds)</FormLabel>
- <FormControl>
- <span className="inline-flex mr-2">
- <NumberField
- data-testid="autosave-delay-input"
- className="m-0 w-24"
- isDisabled={
- form.getValues("save.autosave") !== "after_delay"
- }
- {...field}
- value={field.value / 1000}
- minValue={1}
- onChange={(value) => {
- field.onChange(value * 1000);
- onSubmit(form.getValues());
- }}
- />
- </span>
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="save.format_on_save"
- render={({ field }) => (
- <FormItem className={formItemClasses}>
- <FormLabel className="font-normal">Format on save</FormLabel>
- <FormControl>
- <Checkbox
- data-testid="format-on-save-checkbox"
- checked={field.value}
- disabled={field.disabled}
- onCheckedChange={(checked) => {
- field.onChange(checked);
- }}
- />
- </FormControl>
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="formatting.line_length"
- render={({ field }) => (
- <div className="flex flex-col space-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel>Line length</FormLabel>
- <FormControl>
- <span className="inline-flex mr-2">
+ const renderBody = () => {
+ switch (activeCategory) {
+ case "editor":
+ return (
+ <>
+ <SettingGroup title="Autosave">
+ <FormField
+ control={form.control}
+ name="save.autosave"
+ render={({ field }) => (
+ <FormItem className={formItemClasses}>
+ <FormLabel className="font-normal">
+ Autosave enabled
+ </FormLabel>
+ <FormControl>
+ <Checkbox
+ data-testid="autosave-checkbox"
+ checked={field.value === "after_delay"}
+ disabled={field.disabled}
+ onCheckedChange={(checked) => {
+ field.onChange(checked ? "after_delay" : "off");
+ }}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="save.autosave_delay"
+ render={({ field }) => (
+ <FormItem className={formItemClasses}>
+ <FormLabel>Autosave delay (seconds)</FormLabel>
+ <FormControl>
<NumberField
- data-testid="line-length-input"
+ data-testid="autosave-delay-input"
className="m-0 w-24"
+ isDisabled={
+ form.getValues("save.autosave") !== "after_delay"
+ }
{...field}
- value={field.value}
+ value={field.value / 1000}
minValue={1}
- maxValue={1000}
onChange={(value) => {
- field.onChange(value);
- onSubmit(form.getValues());
+ field.onChange(value * 1000);
+ if (!Number.isNaN(value)) {
+ onSubmit(form.getValues());
+ }
}}
/>
- </span>
- </FormControl>
- <FormMessage />
- </FormItem>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </SettingGroup>
+ <SettingGroup title="Formatting">
+ <FormField
+ control={form.control}
+ name="save.format_on_save"
+ render={({ field }) => (
+ <FormItem className={formItemClasses}>
+ <FormLabel className="font-normal">
+ Format on save
+ </FormLabel>
+ <FormControl>
+ <Checkbox
+ data-testid="format-on-save-checkbox"
+ checked={field.value}
+ disabled={field.disabled}
+ onCheckedChange={(checked) => {
+ field.onChange(checked);
+ }}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="formatting.line_length"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Line length</FormLabel>
+ <FormControl>
+ <NumberField
+ data-testid="line-length-input"
+ className="m-0 w-24"
+ {...field}
+ value={field.value}
+ minValue={1}
+ maxValue={1000}
+ onChange={(value) => {
+ // Ignore NaN
+ field.onChange(value);
+ if (!Number.isNaN(value)) {
+ onSubmit(form.getValues());
+ }
+ }}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
- <FormDescription>
- Maximum line length when formatting code.
- </FormDescription>
- </div>
- )}
- />
- <FormField
- control={form.control}
- name="completion.activate_on_typing"
- render={({ field }) => (
- <div className="flex flex-col space-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel className="font-normal">Autocomplete</FormLabel>
- <FormControl>
- <Checkbox
- data-testid="autocomplete-checkbox"
- checked={field.value}
- disabled={field.disabled}
- onCheckedChange={(checked) => {
- field.onChange(Boolean(checked));
- }}
- />
- </FormControl>
- </FormItem>
- <FormDescription>
- When unchecked, code completion is still available through a
- hotkey.
- </FormDescription>
- </div>
- )}
- />
- <FormField
- control={form.control}
- name="keymap.preset"
- render={({ field }) => (
- <div className="flex flex-col space-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel>Keymap</FormLabel>
- <FormControl>
- <NativeSelect
- data-testid="keymap-select"
- onChange={(e) => field.onChange(e.target.value)}
- value={field.value}
- disabled={field.disabled}
- className="inline-flex mr-2"
- >
- {KEYMAP_PRESETS.map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- <FormMessage />
- </FormItem>
+ <FormDescription>
+ Maximum line length when formatting code.
+ </FormDescription>
+ </div>
+ )}
+ />
+ </SettingGroup>
+ <SettingGroup title="Autocomplete">
+ <FormField
+ control={form.control}
+ name="completion.activate_on_typing"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel className="font-normal">
+ Autocomplete
+ </FormLabel>
+ <FormControl>
+ <Checkbox
+ data-testid="autocomplete-checkbox"
+ checked={field.value}
+ disabled={field.disabled}
+ onCheckedChange={(checked) => {
+ field.onChange(Boolean(checked));
+ }}
+ />
+ </FormControl>
+ </FormItem>
+ <FormDescription>
+ When unchecked, code completion is still available through
+ a hotkey.
+ </FormDescription>
- <div>
- <Button
- variant="link"
- size="xs"
- className="mb-0 px-0"
- type="button"
- onClick={(evt) => {
- evt.preventDefault();
- evt.stopPropagation();
- setKeyboardShortcutsOpen(true);
- }}
- >
- Edit Keyboard Shortcuts
- </Button>
- </div>
- </div>
- )}
- />
- </SettingGroup>
- <SettingGroup title="Display">
- <FormField
- control={form.control}
- name="display.default_width"
- render={({ field }) => (
- <div className="flex flex-col space-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel>Default width</FormLabel>
- <FormControl>
- <NativeSelect
- data-testid="user-config-width-select"
- onChange={(e) => field.onChange(e.target.value)}
- value={field.value}
- disabled={field.disabled}
- className="inline-flex mr-2"
- >
- {APP_WIDTHS.map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- <FormMessage />
- </FormItem>
+ <div>
+ <Button
+ variant="link"
+ className="mb-0 px-0"
+ type="button"
+ onClick={(evt) => {
+ evt.preventDefault();
+ evt.stopPropagation();
+ setActiveCategory("ai");
+ }}
+ >
+ Edit AI autocomplete
+ </Button>
+ </div>
+ </div>
+ )}
+ />
+ </SettingGroup>
+ <SettingGroup title="Keymap">
+ <FormField
+ control={form.control}
+ name="keymap.preset"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Keymap</FormLabel>
+ <FormControl>
+ <NativeSelect
+ data-testid="keymap-select"
+ onChange={(e) => field.onChange(e.target.value)}
+ value={field.value}
+ disabled={field.disabled}
+ className="inline-flex mr-2"
+ >
+ {KEYMAP_PRESETS.map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
- <FormDescription>
- The default app width for new notebooks; overridden by "width"
- in the application config.
- </FormDescription>
- </div>
- )}
- />
- <FormField
- control={form.control}
- name="display.theme"
- render={({ field }) => (
- <FormItem className={formItemClasses}>
- <FormLabel>Theme</FormLabel>
- <FormControl>
- <NativeSelect
- data-testid="theme-select"
- onChange={(e) => field.onChange(e.target.value)}
- value={field.value}
- disabled={field.disabled}
- className="inline-flex mr-2"
- >
- {THEMES.map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="display.cell_output"
- render={({ field }) => (
- <div className="flex flex-col space-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel>Cell output area</FormLabel>
- <FormControl>
- <NativeSelect
- data-testid="cell-output-select"
- onChange={(e) => field.onChange(e.target.value)}
- value={field.value}
- disabled={field.disabled}
- className="inline-flex mr-2"
- >
- {["above", "below"].map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- <FormMessage />
- </FormItem>
+ <div>
+ <Button
+ variant="link"
+ className="mb-0 px-0"
+ type="button"
+ onClick={(evt) => {
+ evt.preventDefault();
+ evt.stopPropagation();
+ setKeyboardShortcutsOpen(true);
+ }}
+ >
+ Edit Keyboard Shortcuts
+ </Button>
+ </div>
+ </div>
+ )}
+ />
+ </SettingGroup>
+ </>
+ );
+ case "display":
+ return (
+ <>
+ <SettingGroup title="Display">
+ <FormField
+ control={form.control}
+ name="display.default_width"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Default width</FormLabel>
+ <FormControl>
+ <NativeSelect
+ data-testid="user-config-width-select"
+ onChange={(e) => field.onChange(e.target.value)}
+ value={field.value}
+ disabled={field.disabled}
+ className="inline-flex mr-2"
+ >
+ {APP_WIDTHS.map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
- <FormDescription>
- Where to display cell's output.
- </FormDescription>
- </div>
- )}
- />
- <FormField
- control={form.control}
- name="display.dataframes"
- render={({ field }) => (
- <div className="flex flex-col space-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel>Dataframe viewer</FormLabel>
- <FormControl>
- <NativeSelect
- data-testid="display-dataframes-select"
- onChange={(e) => field.onChange(e.target.value)}
- value={field.value}
- disabled={field.disabled}
- className="inline-flex mr-2"
- >
- {["rich", "plain"].map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- <FormMessage />
- </FormItem>
+ <FormDescription>
+ The default app width for new notebooks; overridden by
+ "width" in the application config.
+ </FormDescription>
+ </div>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="display.theme"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Theme</FormLabel>
+ <FormControl>
+ <NativeSelect
+ data-testid="theme-select"
+ onChange={(e) => field.onChange(e.target.value)}
+ value={field.value}
+ disabled={field.disabled}
+ className="inline-flex mr-2"
+ >
+ {THEMES.map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
- <FormDescription>
- Whether to use marimo's rich dataframe viewer or a plain HTML
- table; requires notebook restart to take effect.
- </FormDescription>
- </div>
- )}
- />
- <FormField
- control={form.control}
- name="display.code_editor_font_size"
- render={({ field }) => (
- <FormItem className={formItemClasses}>
- <FormLabel>Code editor font size</FormLabel>
- <FormControl>
- <span className="inline-flex mr-2">
- <NumberField
- data-testid="code-editor-font-size-input"
- className="m-0 w-24"
- {...field}
- value={field.value}
- minValue={8}
- maxValue={32}
- onChange={(value) => {
- field.onChange(value);
- onSubmit(form.getValues());
- }}
- />
- </span>
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- </SettingGroup>
+ <FormDescription>
+ This theme will be applied to the user's configuration; it
+ does not affect theme when sharing the notebook.
+ </FormDescription>
+ </div>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="display.code_editor_font_size"
+ render={({ field }) => (
+ <FormItem className={formItemClasses}>
+ <FormLabel>Code editor font size (px)</FormLabel>
+ <FormControl>
+ <span className="inline-flex mr-2">
+ <NumberField
+ data-testid="code-editor-font-size-input"
+ className="m-0 w-24"
+ {...field}
+ value={field.value}
+ minValue={8}
+ maxValue={32}
+ onChange={(value) => {
+ field.onChange(value);
+ onSubmit(form.getValues());
+ }}
+ />
+ </span>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </SettingGroup>
+ <SettingGroup title="Outputs">
+ <FormField
+ control={form.control}
+ name="display.cell_output"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Cell output area</FormLabel>
+ <FormControl>
+ <NativeSelect
+ data-testid="cell-output-select"
+ onChange={(e) => field.onChange(e.target.value)}
+ value={field.value}
+ disabled={field.disabled}
+ className="inline-flex mr-2"
+ >
+ {["above", "below"].map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
- <SettingGroup title="Package Management">
- <FormField
- control={form.control}
- disabled={isWasmRuntime}
- name="package_management.manager"
- render={({ field }) => (
- <FormItem className={formItemClasses}>
- <FormLabel>Manager</FormLabel>
- <FormControl>
- <NativeSelect
- data-testid="package-manager-select"
- onChange={(e) => field.onChange(e.target.value)}
- value={field.value}
- disabled={field.disabled}
- className="inline-flex mr-2"
- >
- {PackageManagerNames.map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- </SettingGroup>
- <SettingGroup title="Runtime">
- <FormField
- control={form.control}
- name="runtime.auto_instantiate"
- render={({ field }) => (
- <FormItem className={formItemClasses}>
- <FormLabel className="font-normal">
- Autorun on startup
- </FormLabel>
- <FormControl>
- <Checkbox
- data-testid="auto-instantiate-checkbox"
- disabled={field.disabled}
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="runtime.on_cell_change"
- render={({ field }) => (
- <div className="flex flex-col gap-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel className="font-normal">On cell change</FormLabel>
- <FormControl>
- <NativeSelect
- data-testid="on-cell-change-select"
- onChange={(e) => field.onChange(e.target.value)}
- value={field.value}
- className="inline-flex mr-2"
+ <FormDescription>
+ Where to display cell's output.
+ </FormDescription>
+ </div>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="display.dataframes"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Dataframe viewer</FormLabel>
+ <FormControl>
+ <NativeSelect
+ data-testid="display-dataframes-select"
+ onChange={(e) => field.onChange(e.target.value)}
+ value={field.value}
+ disabled={field.disabled}
+ className="inline-flex mr-2"
+ >
+ {["rich", "plain"].map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+
+ <FormDescription>
+ Whether to use marimo's rich dataframe viewer or a plain
+ HTML table. This requires restarting your notebook to take
+ effect.
+ </FormDescription>
+ </div>
+ )}
+ />
+ </SettingGroup>
+ </>
+ );
+ case "packageManagement":
+ return (
+ <SettingGroup title="Package Management">
+ <FormField
+ control={form.control}
+ disabled={isWasmRuntime}
+ name="package_management.manager"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Manager</FormLabel>
+ <FormControl>
+ <NativeSelect
+ data-testid="package-manager-select"
+ onChange={(e) => field.onChange(e.target.value)}
+ value={field.value}
+ disabled={field.disabled}
+ className="inline-flex mr-2"
+ >
+ {PackageManagerNames.map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+
+ <FormDescription>
+ When marimo comes across a module that is not installed, you
+ will be prompted to install it using your preferred package
+ manager. Learn more in the{" "}
+ <a
+ className="text-link hover:underline"
+ href="https://docs.marimo.io/guides/editor_features/package_management.html"
+ target="_blank"
+ rel="noreferrer"
>
- {["lazy", "autorun"].map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- </FormItem>
- <FormDescription>
- Whether marimo should automatically run cells or just mark
- them as stale. If "autorun", marimo will automatically run
- affected cells when a cell is run or a UI element is
- interacted with; if "lazy", marimo will mark affected cells as
- stale but won't re-run them.
- </FormDescription>
- </div>
- )}
- />
- <FormField
- control={form.control}
- name="runtime.auto_reload"
- render={({ field }) => (
- <div className="flex flex-col gap-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel className="font-normal">
- On module change
- </FormLabel>
- <FormControl>
- <NativeSelect
- data-testid="auto-reload-select"
- onChange={(e) => field.onChange(e.target.value)}
- value={field.value}
- disabled={isWasmRuntime}
- className="inline-flex mr-2"
+ docs
+ </a>
+ .
+ <br />
+ <br />
+ Running marimo in a{" "}
+ <a
+ className="text-link hover:underline"
+ href="https://docs.marimo.io/guides/editor_features/package_management.html#running-marimo-in-a-sandbox-environment-uv-only"
+ target="_blank"
+ rel="noreferrer"
>
- {["off", "lazy", "autorun"].map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- </FormItem>
- <FormDescription>
- Whether marimo should automatically reload modules before
- executing cells. If "lazy", marimo will mark cells affected by
- module modifications as stale; if "autorun", affected cells
- will be automatically re-run.
- </FormDescription>
- </div>
- )}
- />
- </SettingGroup>
- <SettingGroup title="AI Assist">
- <p className="text-sm text-muted-secondary">
- Add an API key to <Kbd className="inline">~/.marimo.toml</Kbd> to
- activate marimo's AI assistant; see{" "}
- <a
- className="text-link hover:underline"
- href="https://docs.marimo.io/guides/editor_features/ai_completion.html"
- target="_blank"
- rel="noreferrer"
- >
- docs
- </a>{" "}
- for more info.
- </p>
- <FormField
- control={form.control}
- disabled={isWasmRuntime}
- name="ai.open_ai.base_url"
- render={({ field }) => (
- <FormItem className={formItemClasses}>
- <FormLabel>Base URL</FormLabel>
- <FormControl>
- <Input
- data-testid="ai-base-url-input"
- className="m-0 inline-flex"
- placeholder="https://api.openai.com/v1"
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- disabled={isWasmRuntime}
- name="ai.open_ai.model"
- render={({ field }) => (
- <div className="flex flex-col space-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel>Model</FormLabel>
- <FormControl>
- <Input
- data-testid="ai-model-input"
- className="m-0 inline-flex"
- placeholder="gpt-4-turbo"
- {...field}
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- <FormDescription>
- If the model starts with "claude-", we will use your Anthropic
- API key. Otherwise, we will use your OpenAI API key.
- </FormDescription>
- </div>
- )}
- />
- </SettingGroup>
- <SettingGroup title="AI Code Completion">
- <p className="text-sm text-muted-secondary">
- You may use GitHub Copilot or Codeium for AI code completion.
- </p>
+ sandboxed environment
+ </a>{" "}
+ is only supported by <Kbd className="inline">uv</Kbd>
+ </FormDescription>
+ </div>
+ )}
+ />
+ </SettingGroup>
+ );
+ case "runtime":
+ return (
+ <SettingGroup title="Runtime configuration">
+ <FormField
+ control={form.control}
+ name="runtime.auto_instantiate"
+ render={({ field }) => (
+ <div className="flex flex-col gap-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel className="font-normal">
+ Autorun on startup
+ </FormLabel>
+ <FormControl>
+ <Checkbox
+ data-testid="auto-instantiate-checkbox"
+ disabled={field.disabled}
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
- <FormField
- control={form.control}
- name="completion.copilot"
- render={({ field }) => (
- <div className="flex flex-col space-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel>Provider</FormLabel>
- <FormControl>
- <NativeSelect
- data-testid="copilot-select"
- onChange={(e) => {
- if (e.target.value === "none") {
- field.onChange(false);
- } else {
- field.onChange(e.target.value);
- }
- }}
- value={
- field.value === true
- ? "github"
- : field.value === false
- ? "none"
- : field.value
- }
- disabled={field.disabled}
- className="inline-flex mr-2"
- >
- {["none", "github", "codeium"].map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- <FormMessage />
- </FormItem>
- </div>
- )}
- />
+ <FormDescription>
+ Whether to automatically run all cells on startup.
+ </FormDescription>
+ </div>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="runtime.on_cell_change"
+ render={({ field }) => (
+ <div className="flex flex-col gap-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel className="font-normal">
+ On cell change
+ </FormLabel>
+ <FormControl>
+ <NativeSelect
+ data-testid="on-cell-change-select"
+ onChange={(e) => field.onChange(e.target.value)}
+ value={field.value}
+ className="inline-flex mr-2"
+ >
+ {["lazy", "autorun"].map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ </FormItem>
+ <FormDescription>
+ Whether marimo should automatically run cells or just mark
+ them as stale. If "autorun", marimo will automatically run
+ affected cells when a cell is run or a UI element is
+ interacted with; if "lazy", marimo will mark affected cells
+ as stale but won't re-run them.
+ </FormDescription>
+ </div>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="runtime.auto_reload"
+ render={({ field }) => (
+ <div className="flex flex-col gap-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel className="font-normal">
+ On module change
+ </FormLabel>
+ <FormControl>
+ <NativeSelect
+ data-testid="auto-reload-select"
+ onChange={(e) => field.onChange(e.target.value)}
+ value={field.value}
+ disabled={isWasmRuntime}
+ className="inline-flex mr-2"
+ >
+ {["off", "lazy", "autorun"].map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ </FormItem>
+ <FormDescription>
+ Whether marimo should automatically reload modules before
+ executing cells. If "lazy", marimo will mark cells affected
+ by module modifications as stale; if "autorun", affected
+ cells will be automatically re-run.
+ </FormDescription>
+ </div>
+ )}
+ />
+
+ <FormDescription>
+ Learn more in the{" "}
+ <a
+ className="text-link hover:underline"
+ href="https://docs.marimo.io/guides/reactivity.html#runtime-configuration"
+ target="_blank"
+ rel="noreferrer"
+ >
+ docs
+ </a>
+ .
+ </FormDescription>
+ </SettingGroup>
+ );
+ case "ai":
+ return (
+ <>
+ <SettingGroup title="AI Assist">
+ <p className="text-sm text-muted-secondary">
+ Add an API key to <Kbd className="inline">~/.marimo.toml</Kbd>{" "}
+ to activate marimo's AI assistant; see{" "}
+ <a
+ className="text-link hover:underline"
+ href="https://docs.marimo.io/guides/editor_features/ai_completion.html"
+ target="_blank"
+ rel="noreferrer"
+ >
+ docs
+ </a>{" "}
+ for more info.
+ </p>
+ <FormField
+ control={form.control}
+ disabled={isWasmRuntime}
+ name="ai.open_ai.base_url"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Base URL</FormLabel>
+ <FormControl>
+ <Input
+ data-testid="ai-base-url-input"
+ className="m-0 inline-flex"
+ placeholder="https://api.openai.com/v1"
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ <FormDescription>
+ This URL can be any OpenAI-compatible API endpoint.
+ </FormDescription>
+ </div>
+ )}
+ />
+ <FormField
+ control={form.control}
+ disabled={isWasmRuntime}
+ name="ai.open_ai.model"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Model</FormLabel>
+ <FormControl>
+ <Input
+ data-testid="ai-model-input"
+ className="m-0 inline-flex"
+ placeholder="gpt-4-turbo"
+ {...field}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ <FormDescription>
+ If the model starts with "claude-", we will use your
+ Anthropic API key. Otherwise, we will use your OpenAI API
+ key.
+ </FormDescription>
+ </div>
+ )}
+ />
+ </SettingGroup>
+ <SettingGroup title="AI Code Completion">
+ <p className="text-sm text-muted-secondary">
+ You may use GitHub Copilot or Codeium for AI code completion.
+ </p>
- {renderCopilotProvider()}
- </SettingGroup>
+ <FormField
+ control={form.control}
+ name="completion.copilot"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className={formItemClasses}>
+ <FormLabel>Provider</FormLabel>
+ <FormControl>
+ <NativeSelect
+ data-testid="copilot-select"
+ onChange={(e) => {
+ if (e.target.value === "none") {
+ field.onChange(false);
+ } else {
+ field.onChange(e.target.value);
+ }
+ }}
+ value={
+ field.value === true
+ ? "github"
+ : field.value === false
+ ? "none"
+ : field.value
+ }
+ disabled={field.disabled}
+ className="inline-flex mr-2"
+ >
+ {["none", "github", "codeium"].map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ </div>
+ )}
+ />
+
+ {renderCopilotProvider()}
+ </SettingGroup>
+ </>
+ );
+ }
+ };
+
+ const configMessage = (
+ <p className="text-muted-secondary">
+ User configuration is stored in <Kbd className="inline">.marimo.toml</Kbd>
+ <br />
+ Run <Kbd className="inline">marimo config show</Kbd> in your terminal to
+ show your current configuration and file location.
+ </p>
+ );
+
+ return (
+ <Form {...form}>
+ <form
+ ref={formElement}
+ onChange={form.handleSubmit(onSubmit)}
+ className="flex text-pretty overflow-hidden"
+ >
+ <Tabs
+ value={activeCategory}
+ onValueChange={(value) => setActiveCategory(value as CategoryId)}
+ orientation="vertical"
+ className="w-1/3 pr-4 border-r h-full overflow-auto p-6"
+ >
+ <TabsList className="self-start max-h-none flex flex-col gap-2 flex-shrink-0 bg-background flex-1 min-h-full">
+ {categories.map((category) => (
+ <TabsTrigger
+ key={category.id}
+ value={category.id}
+ className="w-full text-left p-2 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground justify-start"
+ >
+ <div className="flex gap-4 items-center text-lg">
+ <span
+ className={cn(
+ category.className,
+ "w-8 h-8 rounded flex items-center justify-center text-muted-foreground",
+ )}
+ >
+ <category.Icon className="w-4 h-4" />
+ </span>
+ {category.label}
+ </div>
+ </TabsTrigger>
+ ))}
+ <div className="flex-1" />
+ {!isWasm() && configMessage}
+ </TabsList>
+ </Tabs>
+ <div className="w-2/3 pl-6 gap-2 flex flex-col overflow-auto p-6">
+ {renderBody()}
+ </div>
</form>
</Form>
);
@@ -662,8 +864,8 @@ const SettingGroup = ({
children,
}: { title: string; children: React.ReactNode }) => {
return (
- <div className="flex flex-col gap-3">
- <SettingSubtitle>{title}</SettingSubtitle>
+ <div className="flex flex-col gap-4 pb-4">
+ <SettingSubtitle className="text-base">{title}</SettingSubtitle>
{children}
</div>
);
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsx
index 229ec7842e..680559242e 100644
--- a/frontend/src/components/editor/actions/useNotebookActions.tsx
+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx
@@ -30,6 +30,7 @@ import {
EditIcon,
LayoutTemplateIcon,
Files,
+ SettingsIcon,
} from "lucide-react";
import { commandPaletteAtom } from "../controls/command-palette";
import { useCellActions, useNotebook } from "@/core/cells/cells";
@@ -64,6 +65,7 @@ import { useLayoutState, useLayoutActions } from "@/core/layout/layout";
import { useTogglePresenting } from "@/core/layout/useTogglePresenting";
import { useCopyNotebook } from "./useCopyNotebook";
import { isWasm } from "@/core/wasm/utils";
+import { settingDialogAtom } from "@/components/app-config/app-config-button";
const NOOP_HANDLER = (event?: Event) => {
event?.preventDefault();
@@ -83,6 +85,7 @@ export function useNotebookActions() {
const restartKernel = useRestartKernel();
const copyNotebook = useCopyNotebook(filename);
const setCommandPaletteOpen = useSetAtom(commandPaletteAtom);
+ const setSettingsDialogOpen = useSetAtom(settingDialogAtom);
const setKeyboardShortcutsOpen = useSetAtom(keyboardShortcutsAtom);
const disabledCells = disabledCellIds(notebook);
@@ -350,6 +353,12 @@ export function useNotebookActions() {
handle: () => setCommandPaletteOpen((open) => !open),
},
+ {
+ icon: <SettingsIcon size={14} strokeWidth={1.5} />,
+ label: "User settings",
+ handle: () => setSettingsDialogOpen((open) => !open),
+ },
+
{
icon: <KeyboardIcon size={14} strokeWidth={1.5} />,
label: "Keyboard shortcuts",
diff --git a/frontend/src/components/ui/form.tsx b/frontend/src/components/ui/form.tsx
index 2dbbd9e414..c6edd96caf 100644
--- a/frontend/src/components/ui/form.tsx
+++ b/frontend/src/components/ui/form.tsx
@@ -36,7 +36,8 @@ const FormField = <
...props
}: ControllerProps<TFieldValues, TName>) => {
return (
- <FormFieldContext.Provider value={{ name: props.name }}>
+ // Need key to prevent context value from being stale
+ <FormFieldContext.Provider key={props.name} value={{ name: props.name }}>
<Controller {...props} />
</FormFieldContext.Provider>
);
@@ -147,7 +148,7 @@ const FormDescription = React.forwardRef<
<p
ref={ref}
id={formDescriptionId}
- className={cn("text-xs text-muted-foreground", className)}
+ className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
);
diff --git a/frontend/src/core/codemirror/copilot/copilot-config.tsx b/frontend/src/core/codemirror/copilot/copilot-config.tsx
index c26b460547..83ba250928 100644
--- a/frontend/src/core/codemirror/copilot/copilot-config.tsx
+++ b/frontend/src/core/codemirror/copilot/copilot-config.tsx
@@ -186,9 +186,11 @@ export const CopilotConfig = memo(() => {
case "signedIn":
return (
- <div className="flex items-center justify-between">
- <Label className="font-normal flex">
- <CheckIcon className="h-4 w-4 mr-1" />
+ <div className="flex items-center gap-5">
+ <Label className="font-normal flex items-center">
+ <div className="inline-flex items-center justify-center bg-[var(--grass-7)] rounded-full p-1 mr-2">
+ <CheckIcon className="h-3 w-3 text-white" />
+ </div>
Connected
</Label>
<Button onClick={signOut} size="xs" variant="text">
diff --git a/frontend/src/css/globals.css b/frontend/src/css/globals.css
index 5ada1b2b16..90a8279fd2 100644
--- a/frontend/src/css/globals.css
+++ b/frontend/src/css/globals.css
@@ -20,6 +20,8 @@
@import url('@radix-ui/colors/yellow-dark.css');
@import url('@radix-ui/colors/blue.css');
@import url('@radix-ui/colors/blue-dark.css');
+@import url('@radix-ui/colors/purple.css');
+@import url('@radix-ui/colors/purple-dark.css');
@tailwind base;
@tailwind components;