shadimage
mksingh
componentjsonforms-boolean-toggle-controlsource: ok · hit

Jsonforms Boolean Toggle Control

JSONForms switch/toggle renderer for boolean fields. Activated by setting options.toggle to true in the UISchema.

npx shadcn add "https://mksingh.dev/r/jsonforms-boolean-toggle-control.json"
free

No selection tags yet — empty means no evidence, not lack of support.

Dependencies

Bundle weight · light
@jsonforms/core@jsonforms/react

Registry dependencies

https://mksingh.dev/r/typography.jsonswitchlabel

Files1 · source cached 10/15/2026, 1:07:07 AM

registry/forms/renderers/boolean-toggle-control.tsx
import { useState } from 'react';

import { and, ControlProps, isBooleanControl, optionIs, rankWith } from '@jsonforms/core';
import { withJsonFormsControlProps } from '@jsonforms/react';

import Typography from '~/components/ui/typography';
import { Label } from '~/components/ui/label';
import { Switch } from '~/components/ui/switch';
import { shouldShowError } from '~/components/forms/utils';

const BooleanToggleControlRenderer = (props: ControlProps) => {
    const { label, data, handleChange, path, visible, enabled, id, errors, config } = props;
    const [touched, setTouched] = useState(false);

    if (!visible) return null;

    return (
        <div className="flex flex-col gap-1 py-2">
            <div className="flex items-center gap-2">
                <Switch
                    id={id}
                    checked={data ?? false}
                    onCheckedChange={checked => handleChange(path, checked)}
                    onBlur={() => setTouched(true)}
                    disabled={!enabled}
                />
                {label && (
                    <Label htmlFor={id} className="text-xs font-medium text-foreground cursor-pointer">
                        {label}
                    </Label>
                )}
            </div>
            {shouldShowError(config, touched) && errors && <Typography variant="error">{errors.split("\n")[0]}</Typography>}
        </div>
    );
};

export const booleanToggleControlTester = rankWith(3, and(isBooleanControl, optionIs('toggle', true)));
export default withJsonFormsControlProps(BooleanToggleControlRenderer);

More from mksingh

Browse all components in this library →