From 0ce306483831ccb4102360cb59f68adfa7331f0d Mon Sep 17 00:00:00 2001 From: Bryan Cunningham Date: Mon, 30 Jun 2025 08:57:20 -0400 Subject: [PATCH] WIP --- .../src/checkbox/checkbox.component.ts | 15 ++++--- .../form-control/form-control.abstraction.ts | 41 +++++++++++++++++-- .../form-control/form-control.component.html | 4 +- .../form-control/form-control.component.ts | 29 +++++++++---- .../src/radio-button/radio-input.component.ts | 15 ++++--- 5 files changed, 81 insertions(+), 23 deletions(-) diff --git a/libs/components/src/checkbox/checkbox.component.ts b/libs/components/src/checkbox/checkbox.component.ts index 079ede287cc..67958eb3d62 100644 --- a/libs/components/src/checkbox/checkbox.component.ts +++ b/libs/components/src/checkbox/checkbox.component.ts @@ -1,6 +1,6 @@ // FIXME: Update this file to be type safe and remove this and next line // @ts-strict-ignore -import { Component, HostBinding, Input, Optional, Self } from "@angular/core"; +import { Component, ElementRef, HostBinding, Input, Optional, Self } from "@angular/core"; import { NgControl, Validators } from "@angular/forms"; import { BitFormControlAbstraction } from "../form-control"; @@ -10,7 +10,7 @@ import { BitFormControlAbstraction } from "../form-control"; template: "", providers: [{ provide: BitFormControlAbstraction, useExisting: CheckboxComponent }], }) -export class CheckboxComponent implements BitFormControlAbstraction { +export class CheckboxComponent extends BitFormControlAbstraction { @HostBinding("class") protected inputClasses = [ "tw-appearance-none", @@ -80,7 +80,12 @@ export class CheckboxComponent implements BitFormControlAbstraction { "indeterminate:disabled:before:tw-bg-text-muted", ]; - constructor(@Optional() @Self() private ngControl?: NgControl) {} + constructor( + elementRef: ElementRef, + @Optional() @Self() private ngControl?: NgControl, + ) { + super(elementRef); + } @HostBinding("style.--mask-image") protected maskImage = @@ -98,7 +103,7 @@ export class CheckboxComponent implements BitFormControlAbstraction { set disabled(value: any) { this._disabled = value != null && value !== false; } - private _disabled: boolean; + // private _disabled: boolean; @Input() get required() { @@ -109,7 +114,7 @@ export class CheckboxComponent implements BitFormControlAbstraction { set required(value: any) { this._required = value != null && value !== false; } - private _required: boolean; + // private _required: boolean; get hasError() { return this.ngControl?.status === "INVALID" && this.ngControl?.touched; diff --git a/libs/components/src/form-control/form-control.abstraction.ts b/libs/components/src/form-control/form-control.abstraction.ts index 4c0a543e672..44b2ce0df7f 100644 --- a/libs/components/src/form-control/form-control.abstraction.ts +++ b/libs/components/src/form-control/form-control.abstraction.ts @@ -1,8 +1,41 @@ // FIXME: Update this file to be type safe and remove this and next line + +import { ElementRef } from "@angular/core"; +// import { NgControl } from "@angular/forms"; + // @ts-strict-ignore export abstract class BitFormControlAbstraction { - disabled: boolean; - required: boolean; - hasError: boolean; - error: [string, any]; + _disabled: boolean; + get disabled(): boolean { + return this._disabled; + } + set disabled(value: boolean) { + this._disabled = value; + } + _required: boolean; + get required(): boolean { + return this._required; + } + set required(value: boolean) { + this._required = value; + } + _hasError: boolean; + get hasError(): boolean { + return this._hasError; + } + set hasError(value: boolean) { + this._hasError = value; + } + _error: [string, any]; + get error(): [string, any] { + return this._error; + } + set error(value: [string, any]) { + this._error = value; + } + _elementRef: ElementRef; + + constructor(elementRef: ElementRef) { + this._elementRef = elementRef; + } } diff --git a/libs/components/src/form-control/form-control.component.html b/libs/components/src/form-control/form-control.component.html index 735e375a29a..9fca28fa6f2 100644 --- a/libs/components/src/form-control/form-control.component.html +++ b/libs/components/src/form-control/form-control.component.html @@ -1,11 +1,11 @@