import { BaseComponent } from "./ave-base-component.js"; class AveButton extends BaseComponent { static get observedAttributes() { return ['variant', 'size', 'disabled', 'loading', 'icon-only', 'type']; } constructor() { super(); this._handleClick = this._handleClick.bind(this); } // Property getters/setters get variant() { return this.getAttribute('variant') || 'primary'; } set variant(value) { this.setAttribute('variant', value); } get size() { return this.getAttribute('size') || 'default'; } set size(value) { this.setAttribute('size', value); } get disabled() { return this._getBooleanAttribute('disabled'); } set disabled(value) { this._setBooleanAttribute('disabled', value); } get loading() { return this._getBooleanAttribute('loading'); } set loading(value) { this._setBooleanAttribute('loading', value); } get iconOnly() { return this._getBooleanAttribute('icon-only'); } set iconOnly(value) { this._setBooleanAttribute('icon-only', value); } get type() { return this.getAttribute('type') || 'button'; } set type(value) { this.setAttribute('type', value); } setupEventListeners() { this._registerEvent('button', 'click', this._handleClick); } _handleClick(e) { if (this.disabled || this.loading) { e.preventDefault(); e.stopPropagation(); return; } this._dispatch('ave-click', { variant: this.variant, size: this.size, disabled: this.disabled, loading: this.loading }); } _getButtonClasses() { const baseClasses = [ 'inline-flex', 'items-center', 'justify-center', 'whitespace-nowrap', 'rounded-md', 'text-sm', 'font-medium', 'ring-offset-background', 'transition-colors', 'focus-visible:outline-none', 'focus-visible:ring-2', 'focus-visible:ring-ring', 'focus-visible:ring-offset-2', 'disabled:pointer-events-none', 'disabled:opacity-50' ]; // Size classes with improved spacing const sizeClasses = { 'sm': ['h-9', 'rounded-md', 'px-3', 'text-xs'], 'default': ['h-10', 'px-4', 'py-2'], 'lg': ['h-11', 'rounded-md', 'px-8'], 'icon': ['h-10', 'w-10'] }; // Enhanced variant classes with better color handling const variantClasses = { 'primary': [ 'bg-primary', 'text-primary-foreground', 'hover:bg-primary/90', 'shadow' ], 'secondary': [ 'bg-secondary', 'text-secondary-foreground', 'hover:bg-secondary/80', 'shadow-sm' ], 'destructive': [ 'bg-destructive', 'text-destructive-foreground', 'hover:bg-destructive/90', 'shadow-sm' ], 'outline': [ 'border', 'border-input', 'bg-background', 'hover:bg-accent', 'hover:text-accent-foreground' ], 'ghost': [ 'hover:bg-accent', 'hover:text-accent-foreground' ], 'link': [ 'text-primary', 'underline-offset-4', 'hover:underline' ] }; const size = this.iconOnly ? 'icon' : (this.size || 'default'); const variant = this.variant || 'primary'; const selectedSizeClasses = sizeClasses[size] || sizeClasses['default']; const selectedVariantClasses = variantClasses[variant] || variantClasses['primary']; return [ ...baseClasses, ...selectedSizeClasses, ...selectedVariantClasses ].join(' '); } render() { const buttonClasses = this._getButtonClasses(); const content = this.innerHTML || 'Button'; this.shadowRoot.innerHTML = ` `; this.setupEventListeners(); } } customElements.define('ave-button', AveButton);