-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Button component with directive
- Loading branch information
Showing
10 changed files
with
61 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Directive, ElementRef, OnInit } from '@angular/core'; | ||
|
||
@Directive({ | ||
selector: 'button[appBtn][main], a[appBtn][main], button[appBtn]:not([main]), a[appBtn]:not([main])', | ||
standalone: true, | ||
}) | ||
export class BtnDirective implements OnInit { | ||
private readonly baseClasses = ['h-12', 'inline-flex', 'items-center', 'rounded-lg', 'px-5', 'py-2.5', 'gap-2', 'text-sm', 'font-medium']; | ||
|
||
private readonly mainClasses = ['bg-primary-700', 'text-white', 'hover:bg-primary-800', 'focus:ring-primary-300', 'dark:bg-primary-600', 'dark:hover:bg-primary-700']; | ||
|
||
private readonly defaultClasses = [ | ||
'border', | ||
'border-gray-200', | ||
'bg-white', | ||
'text-gray-900', | ||
'hover:bg-gray-100', | ||
'hover:text-primary-700', | ||
'dark:border-gray-600', | ||
'dark:bg-gray-800', | ||
'dark:text-gray-400', | ||
'dark:hover:bg-gray-700', | ||
'dark:hover:text-white', | ||
]; | ||
|
||
constructor(private el: ElementRef<HTMLButtonElement | HTMLAnchorElement>) {} | ||
|
||
get main(): boolean { | ||
return this.el.nativeElement.hasAttribute('main'); | ||
} | ||
|
||
ngOnInit() { | ||
const element = this.el.nativeElement; | ||
|
||
element.setAttribute('type', 'button'); | ||
|
||
this.baseClasses.forEach((cls) => element.classList.add(cls)); | ||
|
||
const variantClasses = this.main ? this.mainClasses : this.defaultClasses; | ||
variantClasses.forEach((cls) => element.classList.add(cls)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters