Skip to content

Table of Contents

Checkbox - Control CboxCtrl

Overview

The CboxCtrl component represents a single, customizable checkbox input element. It includes an associated label, optional link, and feedback messages (text and/or icon) for status or validation. It's designed for individual checkbox selections within forms.

Properties

This section details all the configurable properties (props) that the Checkbox component accepts.

NameDescriptionPossible ValuesDefault Setting
asThe component or HTML element to use as the wrapper for the checkbox input.React.ElementType (e.g., 'div', _Builtin.FormCheckboxWrapper)_Builtin.FormCheckboxWrapper
compControls the overall rendering of the component. If false, the component renders as null.booleantrue
txtControls the visibility of the checkbox label.booleantrue
linkControls the visibility of an optional link associated with the checkbox.booleanfalse
fbkControls the visibility of the feedback section (message and icon).booleanfalse
idA unique identifier for the checkbox input element.string"cbox"
itmNameThe name attribute for the checkbox input, used for form submission.stringundefined
itmValueThe value attribute for the checkbox input, representing the value submitted when checked.stringundefined
itmActiveDetermines if the checkbox is checked. Use "True" or "False".string (e.g., "True", "False")"False"
itmLblSrcThe content displayed as the label for the checkbox.React.ReactNode (string, JSX, etc.)"Label"
itmLblSzControls the size styling of the label text.string (e.g., "r3", "r4")"r3"
lblForAssociates the label with a specific input element via the for attribute, aiding accessibility.string"cbox"
itmClickAn object containing additional runtime props to be spread onto the checkbox wrapper, for custom interactions.object (e.g., { onClick: () => ... }){}
alignSpecifies the alignment of the checkbox input and label within its container (e.g., 'l' for left).string"l"
tabOrderDefines the navigation order for the checkbox when using the Tab key.string (e.g., "0", "1")"0"
linkTxtSrcThe text content for the optional link.React.ReactNode (string, JSX, etc.)"Link here"
fbkFbkTxtControls the visibility of the feedback text message.booleantrue
fbkFbkIcnControls the visibility of the feedback icon.booleantrue
fbkFbkTxtSrcThe text content to display in the feedback message.React.ReactNode (string, JSX, etc.)"Feedback message"
fbkFbkIcnSrcThe source or identifier for the feedback icon (e.g., name of an icon from a library).React.ReactNode (string, JSX, etc.)"clearcirc"
fbkFbkClrThe color theme applied to the feedback message (text and/or icon).string (e.g., "fd500", "success100")"fd500"
onChangeA callback function executed when the state of the checkbox changes (e.g., checked status).string or Function (typically React.ChangeEventHandler)""
linkSrcAn object containing properties for the link, primarily the href.object (e.g., { href: "/path" }){ href: "#" }
linkClickAn object containing additional runtime props to be spread onto the link element for custom interactions.object{}
lblShdwApplies shadow styling to the main label.stringundefined
linkShdwApplies shadow styling to the optional link.stringundefined
fbkFbkIcnLocDetermines the position of the feedback icon relative to the text (e.g., 'l' for left, 'r' for right).string"r"

Styling

The CboxCtrl component uses CSS Modules (CboxCtrl.module.css) for styling.

  • Item Container (.itm_ctrl):

    • Styles the main container for the checkbox, label, link, and feedback.
    • Uses position: relative for feedback positioning.
    • Applies flex display (display: flex, align-items: center) for horizontal arrangement.
    • flex: 1 allows the item to grow.
    • Includes responsive adjustments for min-height.
    • Uses data-input-align attribute for alignment control.
  • Checkbox Input (.cbox):

    • Defines the visual appearance of the checkbox itself (size, border, background, border-radius).
    • Includes styles for interaction states:
      • :hover: Changes border color.
      • :active: Changes border color.
      • :global(.w--redirected-checked): Styles the checkbox when checked (border color, background color).
      • :global(.w--redirected-focus): Styles the checkbox when focused via keyboard navigation (box-shadow).
  • Label (.cbox-label):

    • Styles the label element, managing padding and display.
    • Uses data-lbl-size for label sizing.
  • Link (.cbox-link):

    • Styles the optional link, managing display, margin, and color.
  • Feedback Container (.itm_fbk):

    • Styles the container for feedback messages and icons.
    • Uses position: absolute for placement, typically anchored to the right (right: 0%).
    • Applies flex properties for alignment within the feedback area.

Usage

jsx
// Import the component
import { CboxCtrl } from './CboxCtrl';

// --- Basic Example ---
// A simple checkbox with default label.
<CboxCtrl />

// --- Example: Setting Core Properties ---
// Demonstrating setting label text, name, value, and active state.
<CboxCtrl
  id="myCbox1"
  itmName="featureEnabled"
  itmValue="notifications"
  itmLblSrc="Enable Notifications"
  itmActive="True" // Or "False"
/>

// --- Example: With Link and Feedback ---
// Showing a checkbox with an associated link and a success feedback message.
<CboxCtrl
  id="myCbox2"
  itmLblSrc="Agree to Terms"
  link={true}
  linkTxtSrc="View Terms"
  linkSrc={{ href: "/terms" }}
  fbk={true}
  fbkFbkTxtSrc="You must agree to proceed."
  fbkFbkIcnSrc="warning-sign"
  fbkFbkClr="warning"
  fbkFbkIcnLoc="l" // Icon on the left
/>

// --- Example: Handling Change Event ---
// Attaching an onChange handler to detect state changes.
const handleCheckboxChange = (event) => {
  console.log(`Checkbox status: ${event.target.checked}`);
};

<CboxCtrl
  id="myCbox3"
  itmLblSrc="Remember Me"
  onChange={handleCheckboxChange}
/>

// --- Example: Custom Alignment and Click Handler ---
// Using custom alignment and a click handler via itmClick.
const handleCustomClick = () => {
  console.log("Custom click action!");
};

<CboxCtrl
  id="myCbox4"
  itmLblSrc="Custom Style"
  align="right" // Uses data-input-align="right" internally
  itmClick={{ onClick: handleCustomClick }}
/>

// --- Example: Inactive State (via itmActive) and Feedback ---
// Rendering a checkbox in an inactive state with error feedback.
<CboxCtrl
  id="myCbox5"
  itmLblSrc="Input Disabled"
  itmActive="False" // Simulates inactive/disabled appearance
  fbk={true}
  fbkFbkTxtSrc="This field is disabled."
  fbkFbkClr="danger"
/>

Released under the MIT License.