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 full_width option to slider (#1120)
Akshay Agrawal16fdbafc1301
diff --git a/frontend/src/plugins/impl/SliderPlugin.tsx b/frontend/src/plugins/impl/SliderPlugin.tsxindex 89a4fa3a8e..bad6ad601d 100644--- a/frontend/src/plugins/impl/SliderPlugin.tsx+++ b/frontend/src/plugins/impl/SliderPlugin.tsx@@ -18,6 +18,7 @@ interface Data {debounce: boolean;orientation: "horizontal" | "vertical";showValue: boolean;+ fullWidth: boolean;}export class SliderPlugin implements IPlugin<T, Data> {@@ -32,6 +33,7 @@ export class SliderPlugin implements IPlugin<T, Data> {debounce: z.boolean().default(false),orientation: z.enum(["horizontal", "vertical"]).default("horizontal"),showValue: z.boolean().default(false),+ fullWidth: z.boolean().default(false),});render(props: IPluginProps<T, Data>): JSX.Element {@@ -60,6 +62,7 @@ const SliderComponent = ({debounce,orientation,showValue,+ fullWidth,}: SliderProps): JSX.Element => {const id = useId();@@ -71,49 +74,53 @@ const SliderComponent = ({}, [value]);return (- <Labeled- label={label}- id={id}- align={orientation === "horizontal" ? "left" : "top"}- >- <div- className={cn(- "flex items-center gap-2",- orientation === "vertical" &&- "items-end inline-flex justify-center self-center mx-2",- )}+ <div className={fullWidth ? "my-3" : ""}>+ <Labeled+ label={label}+ id={id}+ align={orientation === "horizontal" ? "left" : "top"}+ fullWidth={fullWidth}>- <Slider- id={id}+ <divclassName={cn(- "relative flex items-center select-none",- "data-[orientation=horizontal]:w-36 data-[orientation=vertical]:h-36",+ "flex items-center gap-2",+ orientation === "vertical" &&+ "items-end inline-flex justify-center self-center mx-2",)}- value={[internalValue]}- min={start}- max={stop}- step={step}- orientation={orientation}- // Triggered on all value changes- onValueChange={([nextValue]) => {- setInternalValue(nextValue);- if (!debounce) {- setValue(nextValue);- }- }}- // Triggered on mouse up- onValueCommit={([nextValue]) => {- if (debounce) {- setValue(nextValue);- }- }}- />- {showValue && (- <div className="text-xs text-muted-foreground min-w-[16px]">- {prettyNumber(internalValue)}- </div>- )}- </div>- </Labeled>+ >+ <Slider+ id={id}+ className={cn(+ "relative flex items-center select-none",+ !fullWidth && "data-[orientation=horizontal]:w-36 ",+ "data-[orientation=vertical]:h-36",+ )}+ value={[internalValue]}+ min={start}+ max={stop}+ step={step}+ orientation={orientation}+ // Triggered on all value changes+ onValueChange={([nextValue]) => {+ setInternalValue(nextValue);+ if (!debounce) {+ setValue(nextValue);+ }+ }}+ // Triggered on mouse up+ onValueCommit={([nextValue]) => {+ if (debounce) {+ setValue(nextValue);+ }+ }}+ />+ {showValue && (+ <div className="text-xs text-muted-foreground min-w-[16px]">+ {prettyNumber(internalValue)}+ </div>+ )}+ </div>+ </Labeled>+ </div>);};diff --git a/marimo/_plugins/ui/_impl/input.py b/marimo/_plugins/ui/_impl/input.pyindex 835b5ada00..e3ec188e03 100644--- a/marimo/_plugins/ui/_impl/input.py+++ b/marimo/_plugins/ui/_impl/input.py@@ -145,6 +145,8 @@ class slider(UIElement[Numeric, Numeric]):- `show_value`: whether to display the current value of the slider- `label`: text label for the element- `on_change`: optional callback to run when this element's value changes+ - `full_width`: whether the input should take up the full width of its+ container"""_name: Final[str] = "marimo-slider"@@ -161,6 +163,7 @@ class slider(UIElement[Numeric, Numeric]):*,label: str = "",on_change: Optional[Callable[[Optional[Numeric]], None]] = None,+ full_width: bool = False,) -> None:self._dtype = (float@@ -200,6 +203,7 @@ class slider(UIElement[Numeric, Numeric]):"debounce": debounce,"orientation": orientation,"show-value": show_value,+ "full-width": full_width,},on_change=on_change,)