Checkbox

A versatile and accessible checkbox component with variants, sizes, indeterminate state, select-all pattern, and label support.

Checkbox Component Documentation

Checkboxes demonstrating different visual variants: default, filled, outlined, soft.

Complete Installation Guide

Comprehensive step-by-step instructions to install and use the Checkboxcomponent in your React/Next.js project with TypeScript and JavaScript support.

Step 1: Install Component

Description: Install the component using our CLI tool

Type: cli

TypeScript Installation Command:

npx screenui add checkbox --lang ts --path src/components

JavaScript Installation Command:

npx screenui add checkbox --lang js --path src/components

Step 2: Usage Example

Description: Copy and use the component in your project

Type: usage

TypeScript Implementation

Complete TypeScript code examples for the Checkbox component with full type safety, props interface, and implementation details.

File: Checkbox.tsx

Language: tsx

File Type: TypeScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function VariantCheckboxDemo() {
  const [defaultChecked, setDefaultChecked] = useState(false);
  const [filledChecked, setFilledChecked] = useState(true);
  const [outlinedChecked, setOutlinedChecked] = useState(false);
  const [softChecked, setSoftChecked] = useState(true);

  return (
    <div className="space-y-8">
      <div className="flex gap-4 flex-wrap">
        <CheckboxWithLabel
          label="Default"
          variant="default"
          checked={defaultChecked}
          onChange={(c) => setDefaultChecked(c === 'indeterminate' ? true : c)}
        />
        <CheckboxWithLabel
          label="Filled"
          variant="filled"
          checked={filledChecked}
          onChange={(c) => setFilledChecked(c === 'indeterminate' ? true : c)}
        />
        <CheckboxWithLabel
          label="Outlined"
          variant="outlined"
          checked={outlinedChecked}
          onChange={(c) => setOutlinedChecked(c === 'indeterminate' ? true : c)}
        />
        <CheckboxWithLabel
          label="Soft"
          variant="soft"
          checked={softChecked}
          onChange={(c) => setSoftChecked(c === 'indeterminate' ? true : c)}
        />
      </div>
    </div>
  );
}

JavaScript Implementation

Complete JavaScript code examples for the Checkbox component with ES6+ syntax, modern React patterns, and compatibility notes.

File: Checkbox.jsx

Language: jsx

File Type: JavaScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function VariantCheckboxDemo() {
  const [defaultChecked, setDefaultChecked] = useState(false);
  const [filledChecked, setFilledChecked] = useState(true);
  const [outlinedChecked, setOutlinedChecked] = useState(false);
  const [softChecked, setSoftChecked] = useState(true);

  return (
    <div className="space-y-8">
      <div className="flex gap-4 flex-wrap">
        <CheckboxWithLabel
          label="Default"
          variant="default"
          checked={defaultChecked}
          onChange={(c) => setDefaultChecked(c === 'indeterminate' ? true : c)}
        />
        <CheckboxWithLabel
          label="Filled"
          variant="filled"
          checked={filledChecked}
          onChange={(c) => setFilledChecked(c === 'indeterminate' ? true : c)}
        />
        <CheckboxWithLabel
          label="Outlined"
          variant="outlined"
          checked={outlinedChecked}
          onChange={(c) => setOutlinedChecked(c === 'indeterminate' ? true : c)}
        />
        <CheckboxWithLabel
          label="Soft"
          variant="soft"
          checked={softChecked}
          onChange={(c) => setSoftChecked(c === 'indeterminate' ? true : c)}
        />
      </div>
    </div>
  );
}

Required Dependencies and Prerequisites

The following packages and tools are required to use this component. Ensure all dependencies are installed and properly configured.

  • react - Core React library for component functionality
  • tailwindcss - Utility-first CSS framework for styling
  • lucide-react - Icon library for visual elements

Usage Examples and Best Practices

Practical examples and recommended patterns for implementing and customizing the Checkbox component in your React/Next.js application.

Basic Usage

Import and use the Checkbox component in your React components. The component supports both TypeScript and JavaScript projects.

Advanced Configuration

Customize the component with props, styling, event handlers, and advanced patterns as shown in the code examples above.

Integration Notes

This component is designed to work seamlessly with Next.js, Tailwind CSS, and modern React patterns. It supports server-side rendering, static generation, and client-side hydration.

Accessibility Features

The component includes built-in accessibility features such as ARIA labels, keyboard navigation, screen reader support, and focus management.

Performance Considerations

Optimized for performance with React.memo, efficient re-rendering, and minimal bundle impact. Supports code splitting and lazy loading.

Frequently Asked Questions

How do I customize the styling?

Use Tailwind CSS classes via the className prop, or apply custom CSS using CSS modules or styled-components.

Is this component accessible?

Yes, the component follows WCAG guidelines and includes proper ARIA attributes, keyboard navigation, and screen reader support.

Can I use this with other frameworks?

This component is designed for React/Next.js, but the patterns can be adapted for other frameworks like Vue.js or Angular.

Variant Checkbox

Formsv1.0.0

Checkboxes demonstrating different visual variants: default, filled, outlined, soft.

Last updated: 2025-09-28

Checkbox Examples

Checkbox Component Documentation

Checkboxes showing various sizes: small, medium, large, XL.

Complete Installation Guide

Comprehensive step-by-step instructions to install and use the Checkboxcomponent in your React/Next.js project with TypeScript and JavaScript support.

Step 1: Usage Example

Description: Copy and use the component in your project

Type: usage

TypeScript Implementation

Complete TypeScript code examples for the Checkbox component with full type safety, props interface, and implementation details.

File: Checkbox.tsx

Language: tsx

File Type: TypeScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function SizeCheckboxDemo() {
  const [sm, setSm] = useState(false);
  const [md, setMd] = useState(true);
  const [lg, setLg] = useState(false);
  const [xl, setXl] = useState(true);

  return (
    <div className="space-y-8">
      <div className="flex gap-4 flex-wrap">
        <CheckboxWithLabel label="Small" size="sm" checked={sm} onChange={(c) => setSm(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Medium" size="md" checked={md} onChange={(c) => setMd(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Large" size="lg" checked={lg} onChange={(c) => setLg(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="XL" size="xl" checked={xl} onChange={(c) => setXl(c === 'indeterminate' ? true : c)} />
      </div>
    </div>
  );
}

JavaScript Implementation

Complete JavaScript code examples for the Checkbox component with ES6+ syntax, modern React patterns, and compatibility notes.

File: Checkbox.jsx

Language: jsx

File Type: JavaScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function SizeCheckboxDemo() {
  const [sm, setSm] = useState(false);
  const [md, setMd] = useState(true);
  const [lg, setLg] = useState(false);
  const [xl, setXl] = useState(true);

  return (
    <div className="space-y-8">
      <div className="flex gap-4 flex-wrap">
        <CheckboxWithLabel label="Small" size="sm" checked={sm} onChange={(c) => setSm(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Medium" size="md" checked={md} onChange={(c) => setMd(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Large" size="lg" checked={lg} onChange={(c) => setLg(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="XL" size="xl" checked={xl} onChange={(c) => setXl(c === 'indeterminate' ? true : c)} />
      </div>
    </div>
  );
}

Required Dependencies and Prerequisites

The following packages and tools are required to use this component. Ensure all dependencies are installed and properly configured.

  • react - Core React library for component functionality
  • tailwindcss - Utility-first CSS framework for styling
  • lucide-react - Icon library for visual elements

Usage Examples and Best Practices

Practical examples and recommended patterns for implementing and customizing the Checkbox component in your React/Next.js application.

Basic Usage

Import and use the Checkbox component in your React components. The component supports both TypeScript and JavaScript projects.

Advanced Configuration

Customize the component with props, styling, event handlers, and advanced patterns as shown in the code examples above.

Integration Notes

This component is designed to work seamlessly with Next.js, Tailwind CSS, and modern React patterns. It supports server-side rendering, static generation, and client-side hydration.

Accessibility Features

The component includes built-in accessibility features such as ARIA labels, keyboard navigation, screen reader support, and focus management.

Performance Considerations

Optimized for performance with React.memo, efficient re-rendering, and minimal bundle impact. Supports code splitting and lazy loading.

Frequently Asked Questions

How do I customize the styling?

Use Tailwind CSS classes via the className prop, or apply custom CSS using CSS modules or styled-components.

Is this component accessible?

Yes, the component follows WCAG guidelines and includes proper ARIA attributes, keyboard navigation, and screen reader support.

Can I use this with other frameworks?

This component is designed for React/Next.js, but the patterns can be adapted for other frameworks like Vue.js or Angular.

Size Checkbox

Formsv1.0.0

Checkboxes showing various sizes: small, medium, large, XL.

Last updated: 2025-09-28

Checkbox Examples

Checkbox Component Documentation

Checkboxes demonstrating border radius options: none, small, medium, large, full.

Complete Installation Guide

Comprehensive step-by-step instructions to install and use the Checkboxcomponent in your React/Next.js project with TypeScript and JavaScript support.

Step 1: Usage Example

Description: Copy and use the component in your project

Type: usage

TypeScript Implementation

Complete TypeScript code examples for the Checkbox component with full type safety, props interface, and implementation details.

File: Checkbox.tsx

Language: tsx

File Type: TypeScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function RoundedCheckboxDemo() {
  const [sm, setSm] = useState(true);
  const [md, setMd] = useState(false);
  const [lg, setLg] = useState(true);
  const [full, setFull] = useState(false);

  return (
    <div className="space-y-8">
      <div className="flex gap-4 flex-wrap">
        <CheckboxWithLabel label="Small" rounded="sm" checked={sm} onChange={(c) => setSm(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Medium" rounded="md" checked={md} onChange={(c) => setMd(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Large" rounded="lg" checked={lg} onChange={(c) => setLg(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Full" rounded="full" checked={full} onChange={(c) => setFull(c === 'indeterminate' ? true : c)} />
      </div>
    </div>
  );
}

JavaScript Implementation

Complete JavaScript code examples for the Checkbox component with ES6+ syntax, modern React patterns, and compatibility notes.

File: Checkbox.jsx

Language: jsx

File Type: JavaScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function RoundedCheckboxDemo() {
  const [sm, setSm] = useState(true);
  const [md, setMd] = useState(false);
  const [lg, setLg] = useState(true);
  const [full, setFull] = useState(false);

  return (
    <div className="space-y-8">
      <div className="flex gap-4 flex-wrap">
        <CheckboxWithLabel label="Small" rounded="sm" checked={sm} onChange={(c) => setSm(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Medium" rounded="md" checked={md} onChange={(c) => setMd(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Large" rounded="lg" checked={lg} onChange={(c) => setLg(c === 'indeterminate' ? true : c)} />
        <CheckboxWithLabel label="Full" rounded="full" checked={full} onChange={(c) => setFull(c === 'indeterminate' ? true : c)} />
      </div>
    </div>
  );
}

Required Dependencies and Prerequisites

The following packages and tools are required to use this component. Ensure all dependencies are installed and properly configured.

  • react - Core React library for component functionality
  • tailwindcss - Utility-first CSS framework for styling
  • lucide-react - Icon library for visual elements

Usage Examples and Best Practices

Practical examples and recommended patterns for implementing and customizing the Checkbox component in your React/Next.js application.

Basic Usage

Import and use the Checkbox component in your React components. The component supports both TypeScript and JavaScript projects.

Advanced Configuration

Customize the component with props, styling, event handlers, and advanced patterns as shown in the code examples above.

Integration Notes

This component is designed to work seamlessly with Next.js, Tailwind CSS, and modern React patterns. It supports server-side rendering, static generation, and client-side hydration.

Accessibility Features

The component includes built-in accessibility features such as ARIA labels, keyboard navigation, screen reader support, and focus management.

Performance Considerations

Optimized for performance with React.memo, efficient re-rendering, and minimal bundle impact. Supports code splitting and lazy loading.

Frequently Asked Questions

How do I customize the styling?

Use Tailwind CSS classes via the className prop, or apply custom CSS using CSS modules or styled-components.

Is this component accessible?

Yes, the component follows WCAG guidelines and includes proper ARIA attributes, keyboard navigation, and screen reader support.

Can I use this with other frameworks?

This component is designed for React/Next.js, but the patterns can be adapted for other frameworks like Vue.js or Angular.

Rounded Checkbox

Formsv1.0.0

Checkboxes demonstrating border radius options: none, small, medium, large, full.

Last updated: 2025-09-28

Checkbox Examples

Checkbox Component Documentation

Checkboxes demonstrating special states like indeterminate and disabled.

Complete Installation Guide

Comprehensive step-by-step instructions to install and use the Checkboxcomponent in your React/Next.js project with TypeScript and JavaScript support.

Step 1: Usage Example

Description: Copy and use the component in your project

Type: usage

TypeScript Implementation

Complete TypeScript code examples for the Checkbox component with full type safety, props interface, and implementation details.

File: Checkbox.tsx

Language: tsx

File Type: TypeScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function SpecialStateCheckboxDemo() {
  const [indeterminate, setIndeterminate] = useState<'indeterminate' | boolean>('indeterminate');

  return (
    <div className="space-y-8">
      <CheckboxWithLabel
        label="Indeterminate"
        checked={indeterminate}
        onChange={setIndeterminate}
      />
      <div className="flex gap-4 flex-wrap mt-4">
        <CheckboxWithLabel label="Disabled Checked" checked={true} disabled />
        <CheckboxWithLabel label="Disabled Unchecked" checked={false} disabled />
      </div>
    </div>
  );
}

JavaScript Implementation

Complete JavaScript code examples for the Checkbox component with ES6+ syntax, modern React patterns, and compatibility notes.

File: Checkbox.jsx

Language: jsx

File Type: JavaScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function SpecialStateCheckboxDemo() {
  const [indeterminate, setIndeterminate] = useState<'indeterminate' | boolean>('indeterminate');

  return (
    <div className="space-y-8">
      <CheckboxWithLabel
        label="Indeterminate"
        checked={indeterminate}
        onChange={setIndeterminate}
      />
      <div className="flex gap-4 flex-wrap mt-4">
        <CheckboxWithLabel label="Disabled Checked" checked={true} disabled />
        <CheckboxWithLabel label="Disabled Unchecked" checked={false} disabled />
      </div>
    </div>
  );
}

Required Dependencies and Prerequisites

The following packages and tools are required to use this component. Ensure all dependencies are installed and properly configured.

  • react - Core React library for component functionality
  • tailwindcss - Utility-first CSS framework for styling
  • lucide-react - Icon library for visual elements

Usage Examples and Best Practices

Practical examples and recommended patterns for implementing and customizing the Checkbox component in your React/Next.js application.

Basic Usage

Import and use the Checkbox component in your React components. The component supports both TypeScript and JavaScript projects.

Advanced Configuration

Customize the component with props, styling, event handlers, and advanced patterns as shown in the code examples above.

Integration Notes

This component is designed to work seamlessly with Next.js, Tailwind CSS, and modern React patterns. It supports server-side rendering, static generation, and client-side hydration.

Accessibility Features

The component includes built-in accessibility features such as ARIA labels, keyboard navigation, screen reader support, and focus management.

Performance Considerations

Optimized for performance with React.memo, efficient re-rendering, and minimal bundle impact. Supports code splitting and lazy loading.

Frequently Asked Questions

How do I customize the styling?

Use Tailwind CSS classes via the className prop, or apply custom CSS using CSS modules or styled-components.

Is this component accessible?

Yes, the component follows WCAG guidelines and includes proper ARIA attributes, keyboard navigation, and screen reader support.

Can I use this with other frameworks?

This component is designed for React/Next.js, but the patterns can be adapted for other frameworks like Vue.js or Angular.

Special State Checkbox

Formsv1.0.0

Checkboxes demonstrating special states like indeterminate and disabled.

Last updated: 2025-09-28

Checkbox Examples

Checkbox Component Documentation

A functional select-all pattern controlling multiple checkboxes.

Complete Installation Guide

Comprehensive step-by-step instructions to install and use the Checkboxcomponent in your React/Next.js project with TypeScript and JavaScript support.

Step 1: Usage Example

Description: Copy and use the component in your project

Type: usage

TypeScript Implementation

Complete TypeScript code examples for the Checkbox component with full type safety, props interface, and implementation details.

File: Checkbox.tsx

Language: tsx

File Type: TypeScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function SelectAllCheckboxDemo() {
  const [selectAll, setSelectAll] = useState<'indeterminate' | boolean>(false);
  const [item1, setItem1] = useState(false);
  const [item2, setItem2] = useState(false);
  const [item3, setItem3] = useState(false);

  const handleSelectAll = (c: boolean | 'indeterminate') => {
    const value = c === 'indeterminate' ? true : c;
    setSelectAll(value);
    setItem1(value);
    setItem2(value);
    setItem3(value);
  };

  const handleItemChange = (setter: (v: boolean) => void, c: boolean | 'indeterminate') => {
    const value = c === 'indeterminate' ? true : c;
    setter(value);

    const items = [item1, item2, item3];
    const idx = setter === setItem1 ? 0 : setter === setItem2 ? 1 : 2;
    items[idx] = value;

    const count = items.filter(Boolean).length;
    if (count === 0) setSelectAll(false);
    else if (count === 3) setSelectAll(true);
    else setSelectAll('indeterminate');
  };

  return (
    <div className="space-y-4">
      <CheckboxWithLabel
        label="Select All Items example (3)"
        checked={selectAll}
        onChange={handleSelectAll}
      />
      <div className="ml-6 space-y-2 border-l-2 border-gray-200 pl-3">
        <CheckboxWithLabel label="Select Item 1" checked={item1} onChange={(c) => handleItemChange(setItem1, c)} />
        <CheckboxWithLabel label="Select Item 2" checked={item2} onChange={(c) => handleItemChange(setItem2, c)} />
        <CheckboxWithLabel label="Select Item 3" checked={item3} onChange={(c) => handleItemChange(setItem3, c)} />
      </div>
    </div>
  );
}

JavaScript Implementation

Complete JavaScript code examples for the Checkbox component with ES6+ syntax, modern React patterns, and compatibility notes.

File: Checkbox.jsx

Language: jsx

File Type: JavaScript React Component

import React, { useState } from "react";
import { CheckboxWithLabel } from "@/components/Checkbox";

export default function SelectAllCheckboxDemo() {
  const [selectAll, setSelectAll] = useState<'indeterminate' | boolean>(false);
  const [item1, setItem1] = useState(false);
  const [item2, setItem2] = useState(false);
  const [item3, setItem3] = useState(false);

  const handleSelectAll = (c: boolean | 'indeterminate') => {
    const value = c === 'indeterminate' ? true : c;
    setSelectAll(value);
    setItem1(value);
    setItem2(value);
    setItem3(value);
  };

  const handleItemChange = (setter: (v: boolean) => void, c: boolean | 'indeterminate') => {
    const value = c === 'indeterminate' ? true : c;
    setter(value);

    const items = [item1, item2, item3];
    const idx = setter === setItem1 ? 0 : setter === setItem2 ? 1 : 2;
    items[idx] = value;

    const count = items.filter(Boolean).length;
    if (count === 0) setSelectAll(false);
    else if (count === 3) setSelectAll(true);
    else setSelectAll('indeterminate');
  };

  return (
    <div className="space-y-4">
      <CheckboxWithLabel
        label="Select All Items example (3)"
        checked={selectAll}
        onChange={handleSelectAll}
      />
      <div className="ml-6 space-y-2 border-l-2 border-gray-200 pl-3">
        <CheckboxWithLabel label="Select Item 1" checked={item1} onChange={(c) => handleItemChange(setItem1, c)} />
        <CheckboxWithLabel label="Select Item 2" checked={item2} onChange={(c) => handleItemChange(setItem2, c)} />
        <CheckboxWithLabel label="Select Item 3" checked={item3} onChange={(c) => handleItemChange(setItem3, c)} />
      </div>
    </div>
  );
}

Required Dependencies and Prerequisites

The following packages and tools are required to use this component. Ensure all dependencies are installed and properly configured.

  • react - Core React library for component functionality
  • tailwindcss - Utility-first CSS framework for styling
  • lucide-react - Icon library for visual elements

Usage Examples and Best Practices

Practical examples and recommended patterns for implementing and customizing the Checkbox component in your React/Next.js application.

Basic Usage

Import and use the Checkbox component in your React components. The component supports both TypeScript and JavaScript projects.

Advanced Configuration

Customize the component with props, styling, event handlers, and advanced patterns as shown in the code examples above.

Integration Notes

This component is designed to work seamlessly with Next.js, Tailwind CSS, and modern React patterns. It supports server-side rendering, static generation, and client-side hydration.

Accessibility Features

The component includes built-in accessibility features such as ARIA labels, keyboard navigation, screen reader support, and focus management.

Performance Considerations

Optimized for performance with React.memo, efficient re-rendering, and minimal bundle impact. Supports code splitting and lazy loading.

Frequently Asked Questions

How do I customize the styling?

Use Tailwind CSS classes via the className prop, or apply custom CSS using CSS modules or styled-components.

Is this component accessible?

Yes, the component follows WCAG guidelines and includes proper ARIA attributes, keyboard navigation, and screen reader support.

Can I use this with other frameworks?

This component is designed for React/Next.js, but the patterns can be adapted for other frameworks like Vue.js or Angular.

Select All Checkbox

Formsv1.0.0

A functional select-all pattern controlling multiple checkboxes.

Last updated: 2025-09-28

Checkbox Examples

Usage Notes

Variants

  • default : The standard checkbox style.
  • filled : A checkbox with filled background for emphasis.
  • outlined : Checkbox with border outline, minimal fill.
  • soft : A lighter variant with subtle background.

Sizes

  • sm : Small checkbox for compact UIs.
  • md (default) : Default medium size for standard forms.
  • lg : Large checkbox for emphasis or touch targets.
  • xl : Extra large checkbox, rarely used.

Rounded Corners

  • sm : Slightly rounded corners.
  • md : Medium rounded corners.
  • lg : Large rounded corners.
  • full : Completely rounded checkbox.

Special States

  • indeterminate : Checkbox partially checked, usually for parent-child relationships.
  • disabled : Non-interactive checkbox to indicate disabled option.

Select All Pattern

A parent checkbox can control multiple child checkboxes, supporting the "indeterminate" state.

<CheckboxWithLabel label="Select All" checked= selectAll onChange=handleSelectAll />

Disabled State

Use disabled to make checkboxes non-interactive.

<CheckboxWithLabel label="Option" checked= disabled />