EditableCheckboxField
EditableCheckboxField displays a boolean value as a checkbox icon in read mode (checked or unchecked). Clicking the edit icon renders an interactive CheckboxField. On save the boolean value (true/false) is persisted via API.
Props
| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| name | string | Yes | — | Field name sent as the key in the update payload. |
| value | boolean | Yes | false | Current boolean value. |
| updatePath | string | Yes | — | API endpoint path used to persist the change. |
| label | string | No | — | Label shown beside the checkbox in edit mode and in read mode. |
| description | string | No | — | Helper text shown beside the label in edit mode. |
| apiBaseUrl | string | No | — | Base URL prepended to updatePath. |
| useAuthToken | boolean | No | false | When true, the request includes the authorization token. |
| onEditStart | () => void | No | — | Called when edit mode begins. |
| onEditSuccess | (updatedValue: boolean, newFormData: any) => void | No | — | Called after successful save. |
| onEditError | (error: any) => void | No | — | Called on API error; value is reverted. |
| onEditCancel | () => void | No | — | Called when the user cancels; value is reverted. |
| editIcon | string | No | "pencil" | Icon name for the edit button. |
| saveIcon | string | No | "check" | Icon name for the save button. |
| cancelIcon | string | No | "close" | Icon name for the cancel button. |
| containerStyle | React.CSSProperties | No | — | Style for the outermost wrapper. |
| labelStyle | React.CSSProperties | No | — | Style for the label text. |
| descriptionStyle | React.CSSProperties | No | — | Style for the description text. |
Usage
Basic
import React, { useState } from 'react';
import EditableCheckboxField from '@/components/editable-fields/EditableCheckboxField';
export default function Example() {
const [isActive, setIsActive] = useState(true);
return (
<EditableCheckboxField
label="Active"
name="is_active"
value={isActive}
updatePath="/v1/users/42"
apiBaseUrl="https://api.example.com"
useAuthToken
onEditSuccess={(updated) => setIsActive(updated)}
/>
);
}