mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-11 13:23:02 -05:00
feat(challenge33): add new challenge about decoupling
This commit is contained in:
4
libs/decoupling/brain/src/index.ts
Normal file
4
libs/decoupling/brain/src/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export {
|
||||
BtnDisabledDirective,
|
||||
ButtonState,
|
||||
} from './lib/button-disabled.directive';
|
||||
20
libs/decoupling/brain/src/lib/button-disabled.directive.ts
Normal file
20
libs/decoupling/brain/src/lib/button-disabled.directive.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/* eslint-disable @angular-eslint/directive-selector */
|
||||
/* eslint-disable @angular-eslint/no-host-metadata-property */
|
||||
import { Directive, WritableSignal, signal } from '@angular/core';
|
||||
|
||||
export type ButtonState = 'enabled' | 'disabled';
|
||||
|
||||
@Directive({
|
||||
selector: 'button[btnDisabled]',
|
||||
standalone: true,
|
||||
host: {
|
||||
'(click)': 'toggleState()',
|
||||
},
|
||||
})
|
||||
export class BtnDisabledDirective {
|
||||
state: WritableSignal<ButtonState> = signal('enabled');
|
||||
|
||||
toggleState() {
|
||||
this.state.set(this.state() === 'enabled' ? 'disabled' : 'enabled');
|
||||
}
|
||||
}
|
||||
8
libs/decoupling/brain/src/test-setup.ts
Normal file
8
libs/decoupling/brain/src/test-setup.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
|
||||
globalThis.ngJest = {
|
||||
testEnvironmentOptions: {
|
||||
errorOnUnknownElements: true,
|
||||
errorOnUnknownProperties: true,
|
||||
},
|
||||
};
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
Reference in New Issue
Block a user