This commit is contained in:
Tizian.Breuch
2025-09-09 16:09:28 +02:00
parent 5601cd0110
commit b97fc21024
17 changed files with 645 additions and 249 deletions

View File

@@ -0,0 +1,107 @@
/* Stile, die NUR für diese Button-Komponente gelten */
:host {
display: inline-block; /* Sorgt für korrektes Layout-Verhalten */
}
/* Basis-Stil für alle Buttons */
.btn {
position: relative; /* Wichtig für den Ripple-Effekt */
overflow: hidden; /* Verhindert, dass der Ripple über den Button hinausgeht */
border: none;
border-radius: var(--border-radius-md);
cursor: pointer;
font-weight: 600;
padding: 0.6rem 1.2rem;
transition: all 0.2s ease-out;
/* Stellt sicher, dass der Inhalt (Text/Icon) zentriert ist */
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
}
.btn:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: var(--box-shadow-md);
}
.btn:active:not(:disabled) {
/* Kleiner "Drück"-Effekt beim aktiven Klick */
transform: translateY(0);
box-shadow: var(--box-shadow-sm);
}
/* Farbvarianten */
.btn-primary {
background: var(--color-primary-gradient);
color: #fff;
}
.btn-secondary {
background-color: var(--color-surface);
color: var(--color-text);
border: 1px solid var(--color-border);
}
.btn-stroked {
background-color: transparent;
color: var(--color-primary);
border: 1px solid var(--color-primary);
}
.btn-flat {
background-color: transparent;
color: var(--color-primary);
box-shadow: none; /* Flat-Buttons haben keinen Schatten */
}
.btn-icon {
background-color: transparent;
color: var(--color-text-light);
width: 40px;
height: 40px;
padding: 0;
border-radius: 50%;
box-shadow: none;
}
.btn-icon:hover:not(:disabled) {
background-color: var(--color-border);
transform: none; /* Kein Hover-Effekt für Icon-Buttons */
box-shadow: none;
}
.btn-icon-danger:hover:not(:disabled) {
background-color: #fee2e2;
color: var(--color-danger);
}
:host-context(body.dark-theme) .btn-icon-danger:hover:not(:disabled) {
background-color: #991b1b;
}
/* Deaktivierter Zustand */
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
box-shadow: none;
}
/* Modifikatoren */
.btn-full-width {
width: 100%;
}
/* Klick-Effekt (Ripple) */
.ripple {
position: absolute;
border-radius: 50%;
transform: scale(0);
animation: ripple-effect 0.6s linear;
background-color: rgba(255, 255, 255, 0.7);
}
.btn-secondary .ripple, .btn-stroked .ripple, .btn-flat .ripple, .btn-icon .ripple {
background-color: rgba(0, 0, 0, 0.1);
}
@keyframes ripple-effect {
to {
transform: scale(4);
opacity: 0;
}
}

View File

@@ -1,17 +1,16 @@
<button
[type]="type"
[type]="submitType"
[disabled]="disabled"
class="btn"
[class.btn-primary]="color === 'primary'"
[class.btn-secondary]="color === 'secondary'"
[class.btn-stroked]="color === 'stroked'"
[class.btn-flat]="color === 'flat'"
[class.btn-icon]="color === 'icon' || color === 'icon-danger'"
[class.btn-icon-danger]="color === 'icon-danger'"
[class.btn-primary]="buttonType === 'primary'"
[class.btn-secondary]="buttonType === 'secondary'"
[class.btn-stroked]="buttonType === 'stroked'"
[class.btn-flat]="buttonType === 'flat'"
[class.btn-icon]="buttonType === 'icon' || buttonType === 'icon-danger'"
[class.btn-icon-danger]="buttonType === 'icon-danger'"
[class.btn-full-width]="fullWidth"
[attr.data-tooltip]="tooltip"
>
<!-- HIER IST DIE KORREKTUR: Binding an [svgColor] statt [iconColor] -->
[attr.data-tooltip]="tooltip">
<app-icon *ngIf="iconName" [name]="iconName" [svgColor]="svgColor"></app-icon>
<ng-content></ng-content>
</button>

View File

@@ -1,4 +1,4 @@
import { Component, Input } from '@angular/core';
import { Component, Input, ElementRef, Renderer2, HostListener } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IconComponent } from '../icon/icon.component';
@@ -7,21 +7,48 @@ type ButtonColor = 'primary' | 'secondary' | 'stroked' | 'flat' | 'icon' | 'icon
@Component({
selector: 'app-button',
standalone: true,
imports: [
CommonModule,
IconComponent
],
imports: [CommonModule, IconComponent],
templateUrl: './button.component.html',
styleUrl: './button.component.css'
})
export class ButtonComponent {
@Input() color: ButtonColor = 'primary';
@Input() type: 'button' | 'submit' = 'button';
@Input() buttonType: ButtonColor = 'primary';
@Input() submitType: 'button' | 'submit' = 'button';
@Input() disabled = false;
@Input() fullWidth = false;
@Input() tooltip: string | null = null;
@Input() iconName: string | null = null;
// --- HIER IST DIE KORREKTUR: Umbenennung zu svgColor ---
@Input() svgColor: string | null = null; // Farbe des SVG-Inhalts im Button
@Input() svgColor: string | null = null;
constructor(private el: ElementRef, private renderer: Renderer2) {}
// HostListener fängt Klick-Events direkt auf dem Host-Element (<app-button>) ab
@HostListener('click', ['$event'])
onClick(event: MouseEvent) {
if (this.disabled) {
return;
}
const button = this.el.nativeElement.querySelector('.btn');
if (!button) return;
// Entferne alte Ripple-Effekte
const existingRipple = button.querySelector('.ripple');
if (existingRipple) {
existingRipple.remove();
}
// Erzeuge den Ripple-Effekt
const circle = this.renderer.createElement('span');
const diameter = Math.max(button.clientWidth, button.clientHeight);
const radius = diameter / 2;
this.renderer.setStyle(circle, 'width', `${diameter}px`);
this.renderer.setStyle(circle, 'height', `${diameter}px`);
this.renderer.setStyle(circle, 'left', `${event.clientX - button.offsetLeft - radius}px`);
this.renderer.setStyle(circle, 'top', `${event.clientY - button.offsetTop - radius}px`);
this.renderer.addClass(circle, 'ripple');
this.renderer.appendChild(button, circle);
}
}