diff --git a/frontend/src/plugins/impl/CheckboxPlugin.tsx b/frontend/src/plugins/impl/CheckboxPlugin.tsx index b011174d276..40eb7432944 100644 --- a/frontend/src/plugins/impl/CheckboxPlugin.tsx +++ b/frontend/src/plugins/impl/CheckboxPlugin.tsx @@ -7,17 +7,23 @@ import { Checkbox } from "../../components/ui/checkbox"; import type { CheckedState } from "@radix-ui/react-checkbox"; import { Labeled } from "./common/labeled"; -export class CheckboxPlugin - implements IPlugin -{ +type T = boolean; + +interface Data { + label: string | null; + disabled?: boolean; +} + +export class CheckboxPlugin implements IPlugin { tagName = "marimo-checkbox"; validator = z.object({ initialValue: z.boolean(), label: z.string().nullable(), + disabled: z.boolean().optional(), }); - render(props: IPluginProps): JSX.Element { + render(props: IPluginProps): JSX.Element { return ; } } @@ -26,7 +32,7 @@ const CheckboxComponent = ({ value, setValue, data, -}: IPluginProps): JSX.Element => { +}: IPluginProps): JSX.Element => { const onClick = (newValue: CheckedState) => { // unsupported state if (newValue === "indeterminate") { @@ -43,6 +49,7 @@ const CheckboxComponent = ({ checked={value} onCheckedChange={onClick} id={id} + disabled={data.disabled} /> ); diff --git a/marimo/_plugins/ui/_impl/input.py b/marimo/_plugins/ui/_impl/input.py index 4cca8e0f58f..bc1a5ce2bf1 100644 --- a/marimo/_plugins/ui/_impl/input.py +++ b/marimo/_plugins/ui/_impl/input.py @@ -600,6 +600,7 @@ class checkbox(UIElement[bool, bool]): label (str, optional): Markdown label for the element. Defaults to "". on_change (Callable[[bool], None], optional): Optional callback to run when this element's value changes. Defaults to None. + disabled (bool, optional): Whether the checkbox is disabled. Defaults to False. """ _name: Final[str] = "marimo-checkbox" @@ -609,13 +610,16 @@ def __init__( value: bool = False, *, label: str = "", + disabled: bool = False, on_change: Optional[Callable[[bool], None]] = None, ) -> None: super().__init__( component_name=checkbox._name, initial_value=value, label=label, - args={}, + args={ + "disabled": disabled, + }, on_change=on_change, )