4.4.12 • Published 6 months ago

@conectate/ct-checkbox v4.4.12

Weekly downloads
7
License
BSD-3-Clause
Repository
github
Last release
6 months ago

Published on webcomponents.org

ct-checkbox

A customizable checkbox web component built with LitElement.

Installation

# npm
npm i @conectate/ct-checkbox

# yarn
yarn add @conectate/ct-checkbox

# pnpm
pnpm i @conectate/ct-checkbox

Usage

Basic Usage

import '@conectate/ct-checkbox';

// Then use in your HTML
<ct-checkbox>Check me</ct-checkbox>

Examples

<!-- Basic checkbox -->
<ct-checkbox>Basic checkbox</ct-checkbox>

<!-- Pre-checked checkbox -->
<ct-checkbox checked>Pre-checked</ct-checkbox>

<!-- With label property -->
<ct-checkbox label="Using label property"></ct-checkbox>

<!-- Indeterminate state -->
<ct-checkbox indeterminate>Indeterminate</ct-checkbox>

<!-- Disabled checkbox -->
<ct-checkbox disabled>Disabled</ct-checkbox>

<!-- With value and name -->
<ct-checkbox name="accept" value="terms">Accept terms</ct-checkbox>

Event Handling

// Listen for state changes
const checkbox = document.querySelector('ct-checkbox');
checkbox.addEventListener('checked', (e) => {
  console.log('Checkbox checked:', e.detail.checked);
});

// Standard change event is also dispatched
checkbox.addEventListener('change', (e) => {
  console.log('Change event fired');
});

Theming

The ct-checkbox component can be customized using CSS custom properties:

ct-checkbox {
	/* Size and shape */
	--ct-checkbox-box-size: 24px;
	--ct-checkbox-box-border-radius: 8px;
	--ct-checkbox-height: var(--ct-checkbox-box-size);
	--ct-checkbox-box-border-size: 3px;

	/* Colors */
	--color-primary: #2cb5e8;
	--color-on-primary: #fff;
	--color-on-background: #535353;
}

API

Properties

PropertyAttributeTypeDefaultDescription
checkedcheckedbooleanfalseCheckbox checked state
indeterminateindeterminatebooleanfalseCheckbox indeterminate state
disableddisabledbooleanfalseDisables the checkbox
valuevalueany-Value associated with the checkbox
namenamestring""Name attribute for form submission
labellabelstring""Text label (alternative to slot)

Methods

NameDescription
click()Programmatically clicks the checkbox

Events

Event NameDetailDescription
checked{checked: boolean}Fires when checked state changes
changeNative event (redispatched)Standard input change event

Slots

NameDescription
(default)Content is used as the checkbox label

Styling

Shadow Parts

The component uses internal styling but can be customized with CSS custom properties.

CSS Custom Properties

PropertyDescription
--ct-checkbox-box-sizeSize of the checkbox (default: 24px)
--ct-checkbox-box-border-radiusBorder radius of checkbox (default: 8px)
--ct-checkbox-heightHeight of the checkbox component
--ct-checkbox-box-border-sizeBorder size of unchecked box (default: 3px)
--color-primaryColor used for the checked state
--color-on-primaryColor of the checkmark
--color-on-backgroundColor of the unchecked checkbox border

Follow me

Herberth Obregón

https://x.com/herberthobregon

https://dev.to/herberthobregon

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

  • v1.0.1 Initial Release

License

See LICENSE

4.4.9

6 months ago

4.3.1

9 months ago

4.4.12

6 months ago

4.3.0

9 months ago

4.0.0

1 year ago

3.12.3

2 years ago

3.12.2

2 years ago

3.9.0

2 years ago

3.8.1

2 years ago

3.11.0

2 years ago

3.8.0

2 years ago

3.10.0

2 years ago

3.12.1

2 years ago

3.12.0

2 years ago

3.11.1

2 years ago

3.7.6

2 years ago

3.7.5

3 years ago

3.7.4

3 years ago

3.7.3

3 years ago

3.7.2

3 years ago

3.7.1

3 years ago

3.7.0

3 years ago

3.6.0

4 years ago

3.5.0

4 years ago

3.4.4

4 years ago

3.4.0

4 years ago

3.4.2

4 years ago

3.4.1

4 years ago

3.3.1

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.0

5 years ago

3.0.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago