@sixbell-telco/sdk
Version:
A collection of reusable components designed for use in Sixbell Telco Angular projects
162 lines (158 loc) • 6.76 kB
JavaScript
import * as i0 from '@angular/core';
import { input, model, output, computed, ChangeDetectionStrategy, Component } from '@angular/core';
import * as i1 from '@angular/forms';
import { FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
import { cn } from '@sixbell-telco/sdk/utils/cn';
import { cva } from 'class-variance-authority';
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* @internal
* Generates base checkbox classes with style variants
*/
const checkboxComponent = cva(['checkbox', 'font-body'], {
variants: {
variant: {
primary: ['checkbox-primary'],
secondary: ['checkbox-secondary'],
tertiary: ['checkbox-tertiary'],
accent: ['checkbox-accent'],
success: ['checkbox-success'],
warning: ['checkbox-warning'],
info: ['checkbox-info'],
error: ['checkbox-error'],
},
size: {
xs: ['checkbox-xs'],
sm: ['checkbox-sm'],
md: ['checkbox-md'],
lg: ['checkbox-lg'],
xl: ['checkbox-xl'],
},
},
compoundVariants: [],
defaultVariants: {
variant: 'primary',
size: 'md',
},
});
/**
* A customizable checkbox component with various styling options
*
* @remarks
* Implements ControlValueAccessor for seamless integration with Angular forms.
* Supports both standalone usage and form integration with reactive/template-driven forms.
*
* @example
* ```html
* <!-- Basic usage -->
* <st-checkbox [(value)]="isChecked"></st-checkbox>
* ```
*
* @example
* ```html
* <!-- With label and custom styling -->
* <st-checkbox
* variant="success"
* size="lg"
* label="Accept terms"
* [(value)]="termsAccepted"
* ></st-checkbox>
* ```
*/
class CheckboxComponent {
/**
* Checkbox color variant
* @defaultValue 'primary'
*/
variant = input('primary');
/**
* Checkbox size variant
* @defaultValue 'md'
*/
size = input('md');
/**
* Label text displayed next to the checkbox
*/
label = input('');
/**
* HTML name attribute for the checkbox
*/
name = input(null);
/**
* Two-way bindable checkbox state
*/
value = model(false);
/**
* Event emitted when checkbox state changes
*/
valueUpdated = output();
// ControlValueAccessor implementation
onControlChange = () => { };
onControlTouch = () => { };
/**
* Whether the checkbox is disabled
* @defaultValue false
*/
disabled = model(false);
/**
* @internal
* Computed class string for the checkbox
*/
componentClass = computed(() => {
return cn(checkboxComponent({
variant: this.variant(),
size: this.size(),
}));
});
// ControlValueAccessor methods
writeValue(obj) {
this.value.set(obj);
}
registerOnChange(fn) {
this.onControlChange = fn;
}
registerOnTouched(fn) {
this.onControlTouch = fn;
}
setDisabledState(isDisabled) {
this.disabled.set(isDisabled);
}
/**
* @internal
* Handles checkbox state changes
*/
handleChange() {
this.onControlChange(this.value());
this.valueUpdated.emit(this.value());
}
/**
* @internal
* Handles blur event
*/
handleBlur() {
this.onControlTouch();
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CheckboxComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.0", type: CheckboxComponent, isStandalone: true, selector: "st-checkbox", inputs: { variant: { classPropertyName: "variant", publicName: "variant", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", valueUpdated: "valueUpdated", disabled: "disabledChange" }, providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: CheckboxComponent,
multi: true,
},
], ngImport: i0, template: "<label class=\"fieldset-label text-base-content font-body\">\n\t<input\n\t\ttype=\"checkbox\"\n\t\t[class]=\"componentClass()\"\n\t\t[(ngModel)]=\"value\"\n\t\t[disabled]=\"disabled()\"\n\t\t[attr.name]=\"name()\"\n\t\t(change)=\"handleChange()\"\n\t\t(blur)=\"handleBlur()\"\n\t/>\n\t{{ label() }}\n</label>\n", dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: CheckboxComponent, decorators: [{
type: Component,
args: [{ selector: 'st-checkbox', imports: [FormsModule], providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: CheckboxComponent,
multi: true,
},
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<label class=\"fieldset-label text-base-content font-body\">\n\t<input\n\t\ttype=\"checkbox\"\n\t\t[class]=\"componentClass()\"\n\t\t[(ngModel)]=\"value\"\n\t\t[disabled]=\"disabled()\"\n\t\t[attr.name]=\"name()\"\n\t\t(change)=\"handleChange()\"\n\t\t(blur)=\"handleBlur()\"\n\t/>\n\t{{ label() }}\n</label>\n" }]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { CheckboxComponent };
//# sourceMappingURL=sixbell-telco-sdk-components-forms-checkbox.mjs.map