Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions frontend/src/plugins/impl/CheckboxPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean, { label: string | null }>
{
type T = boolean;

interface Data {
label: string | null;
disabled?: boolean;
}

export class CheckboxPlugin implements IPlugin<T, Data> {
tagName = "marimo-checkbox";

validator = z.object({
initialValue: z.boolean(),
label: z.string().nullable(),
disabled: z.boolean().optional(),
});

render(props: IPluginProps<boolean, { label: string | null }>): JSX.Element {
render(props: IPluginProps<T, Data>): JSX.Element {
return <CheckboxComponent {...props} />;
}
}
Expand All @@ -26,7 +32,7 @@ const CheckboxComponent = ({
value,
setValue,
data,
}: IPluginProps<boolean, { label: string | null }>): JSX.Element => {
}: IPluginProps<T, Data>): JSX.Element => {
const onClick = (newValue: CheckedState) => {
// unsupported state
if (newValue === "indeterminate") {
Expand All @@ -43,6 +49,7 @@ const CheckboxComponent = ({
checked={value}
onCheckedChange={onClick}
id={id}
disabled={data.disabled}
/>
</Labeled>
);
Expand Down
6 changes: 5 additions & 1 deletion marimo/_plugins/ui/_impl/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
)

Expand Down
Loading