-
Notifications
You must be signed in to change notification settings - Fork 0
Checkbox
This document details the Checkbox
component, which provides functionality for creating and managing customizable checkboxes in a web application.
Checkboxes are interactive elements that allow users to select or deselect options. They are commonly used in forms and settings interfaces to toggle states.
The Checkbox
component accepts a configuration object (config
) to customize the checkbox's behavior and appearance.
The config
object can include the following properties:
Parameter | Type | Description | Optional |
---|---|---|---|
id |
string |
ID attribute for the checkbox element | No |
class_name |
string |
CSS class(es) for styling the checkbox | Yes |
target_id |
string |
ID of the target element affected by the checkbox state | No |
group_name |
string |
Group name for managing related checkboxes | No |
The Checkbox
component manages a click
event to toggle its state and update related elements.
import { Checkbox } from './path/to/Checkbox.js';
const config = {
id: 'myCheckbox',
class_name: 'custom-checkbox',
target_id: 'targetElement',
group_name: 'checkboxGroup'
};
const myCheckbox = new Checkbox(config).create();
document.body.appendChild(myCheckbox);
When managing the target IDs of checked checkboxes, the Checkbox component stores this information in localStorage. It uses the group name with a suffix of -checkboxes to store and retrieve these IDs. Here's an example of how to retrieve the target IDs:
// If the group_name in the config is 'checkboxGroup', retrieve it as 'checkboxGroup-checkboxes' from localStorage.
const ids = JSON.parse(localStorage.getItem('checkboxGroup-checkboxes')) || [];
console.log(ids) // Use the retrieved ids
-
create()
: Creates the checkbox element based on the provided configuration and attaches event listeners. -
remove()
: Removes the checkbox element from the DOM and cleans up related state management.
Created by members of Free Bird Operation Project | All rights reserved 2024