button.component.ts
angular/examples/week01-02/src/app/ui/button.component.ts
// @ts-nocheck
import { Component, Input } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'ui-button',
standalone: true,
imports: [CommonModule],
template: `
<button
class="btn"
[attr.aria-label]="ariaLabel || label"
[disabled]="disabled"
[ngClass]="variant"
type="button"
>
<ng-content></ng-content>
<span *ngIf="useLabelFallback">{{ label }}</span>
</button>
`,
styles: [
`
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
border: none;
font-weight: 600;
cursor: pointer;
transition: transform 150ms ease, box-shadow 150ms ease;
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.primary {
background: #2563eb;
color: white;
box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
}
.secondary {
background: #f3f4f6;
color: #1f2937;
}
.ghost {
background: transparent;
color: #111827;
border: 1px solid currentColor;
}
`,
],
})
export class ButtonComponent {
@Input() label = 'Click me';
@Input() variant: 'primary' | 'secondary' | 'ghost' = 'primary';
@Input() disabled = false;
@Input() ariaLabel?: string;
@Input() useLabelFallback = false;
}
Bài viết liên quan
server.js
server.js — javascript source code from the angular learning materials (angular/comprehensive-demo/server/server.js).
Đọc bài viết →app.component.ts
app.component.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.component.ts).
Đọc bài viết →app.config.ts
app.config.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.config.ts).
Đọc bài viết →app.routes.ts
app.routes.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.routes.ts).
Đọc bài viết →auth.guard.ts
auth.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/auth.guard.ts).
Đọc bài viết →role.guard.ts
role.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/role.guard.ts).
Đọc bài viết →