Skip to content

Commit

Permalink
refactor: button component
Browse files Browse the repository at this point in the history
add output event click
  • Loading branch information
lannodev committed Mar 14, 2024
1 parent 6c10d65 commit 6be20d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/app/modules/auth/pages/sign-in/sign-in.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class SignInComponent implements OnInit {

constructor(private readonly _formBuilder: FormBuilder, private readonly _router: Router) {}

onClick() {
console.log('Button clicked');
}

ngOnInit(): void {
this.form = this._formBuilder.group({
email: ['', [Validators.required, Validators.email]],
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/components/button/button.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<button [ngClass]="classes">
<button (click)="onButtonClick()" [ngClass]="classes">
<ng-content></ng-content>
</button>
9 changes: 8 additions & 1 deletion src/app/shared/components/button/button.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, input } from '@angular/core';
import { Component, EventEmitter, OnInit, Output, input } from '@angular/core';
import { CommonModule } from '@angular/common';
import { cx } from '../../utils/ckassnames';

Expand All @@ -25,6 +25,8 @@ export class ButtonComponent implements OnInit {
transform: (value: boolean | string) => (typeof value === 'string' ? value === '' : value),
});

@Output() buttonClick = new EventEmitter<void>();

public classes: string = '';

baseClasses =
Expand Down Expand Up @@ -76,6 +78,7 @@ export class ButtonComponent implements OnInit {
};

constructor() {}

ngOnInit(): void {
this.classes = cx(
this.baseClasses,
Expand All @@ -85,4 +88,8 @@ export class ButtonComponent implements OnInit {
this.full() ? 'w-full' : '',
);
}

onButtonClick() {
this.buttonClick.emit();
}
}

0 comments on commit 6be20d8

Please sign in to comment.