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.

1.2 KB
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */
export interface FieldOptions {
  label?: string;
  description?: string;
  placeholder?: string;
  disabled?: boolean;
  hidden?: boolean;
  direction?: "row" | "column" | "two-columns";
  minLength?: number;
  /**
   * Only valid for string fields
   */
  inputType?:
    | "password"
    | "text"
    | "number"
    | "checkbox"
    | "select"
    | "textarea";
  special?:
    | "column_id"
    | "random_number_button"
    | "column_type"
    | "radio_group"
    | "column_filter"
    | "text_area_multiline"
    | "column_values"
    | "date"
    | "datetime"
    | "time"
    | "tabs"
    | "secret_textarea";
  /**
   * Only show options that match the regex
   */
  optionRegex?: string;
}

// oxlint-disable-next-line typescript/no-redeclare
export const FieldOptions = {
  of(options: FieldOptions): string {
    return JSON.stringify(options);
  },
  parse(options: string | undefined): FieldOptions {
    if (!options) {
      return {};
    }
    try {
      return JSON.parse(options) as FieldOptions;
    } catch {
      return {
        label: options,
      };
    }
  },
};

// Random number between 0 and 100_000
export function randomNumber(): number {
  return Math.floor(Math.random() * 100_000);
}