import { Component, Input, Output, EventEmitter, signal } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Block, ButtonProps } from '../../../core/models/block.model'; import { ButtonConfigModalComponent } from './button-config-modal.component'; @Component({ selector: 'app-button-block', standalone: true, imports: [CommonModule, ButtonConfigModalComponent], template: `
{{ props.label || 'Button' }} @if (showConfig()) { }
` }) export class ButtonBlockComponent { @Input({ required: true }) block!: Block; @Output() update = new EventEmitter(); showConfig = signal(false); ngOnInit() { // If new button (empty label), open config immediately if (!this.props.label) { this.showConfig.set(true); } } get props(): ButtonProps { return this.block.props; } getButtonClasses(): string { const classes: string[] = []; // Size switch (this.props.size) { case 'small': classes.push('px-3 py-1.5 text-xs'); break; case 'large': classes.push('px-6 py-3 text-base'); break; default: classes.push('px-4 py-2 text-sm'); break; // medium } // Shape if (this.props.shape === 'pill') { classes.push('rounded-full'); } else if (this.props.shape === 'rounded') { classes.push('rounded-lg'); } else { classes.push('rounded-md'); // default/square } // Variant / Style if (this.props.variant === '3d') { classes.push('border-b-4 border-black/20 active:border-b-0 active:translate-y-1'); } else if (this.props.variant === 'shadow') { classes.push('shadow-lg hover:shadow-xl hover:-translate-y-0.5'); } else if (this.props.variant === 'outline') { classes.push('border-2'); } return classes.join(' '); } getBgColor(): string { if (this.props.variant === 'outline') return 'transparent'; return this.props.backgroundColor || '#3b82f6'; } getTextColor(): string { if (this.props.variant === 'outline') { return this.props.backgroundColor || '#3b82f6'; } // Simple contrast check could be added here, assuming white for now for colored buttons return '#ffffff'; } onClick(event: MouseEvent) { // Prevent navigation in editor event.preventDefault(); } openConfig(event: MouseEvent) { event.stopPropagation(); this.showConfig.set(true); } closeConfig() { this.showConfig.set(false); } onSaveConfig(newProps: ButtonProps) { this.update.emit(newProps); this.showConfig.set(false); } }