Mustavi's picture
bro this is so incomplete and please follow our design system attached
4c5c9a2 verified
Raw History Blame Contribute Delete
2 kB
class CustomAlert extends HTMLElement {
connectedCallback() {
const type = this.getAttribute('type') || 'info';
const message = this.getAttribute('message') || '';
const dismissible = this.hasAttribute('dismissible');
let icon, bgColor, textColor;
switch(type) {
case 'success':
icon = 'check-circle';
bgColor = 'bg-green-100';
textColor = 'text-green-800';
break;
case 'error':
icon = 'alert-circle';
bgColor = 'bg-red-100';
textColor = 'text-red-800';
break;
case 'warning':
icon = 'alert-triangle';
bgColor = 'bg-yellow-100';
textColor = 'text-yellow-800';
break;
default:
icon = 'info';
bgColor = 'bg-primary-100';
textColor = 'text-primary-800';
}
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
.alert {
padding: 0.75rem 1rem;
border-radius: 0.375rem;
display: flex;
align-items: center;
margin-bottom: 1rem;
}
.alert-icon {
margin-right: 0.75rem;
flex-shrink: 0;
}
.alert-content {
flex: 1;
}
.alert-dismiss {
margin-left: 0.75rem;
cursor: pointer;
flex-shrink: 0;
}
</style>
<div class="alert ${bgColor} ${textColor}">
<div class="alert-icon">
<i data-feather="${icon}"></i>
</div>
<div class="alert-content">
<slot>${message}</slot>
</div>
${dismissible ? `
<div class="alert-dismiss" id="dismiss">
<i data-feather="x"></i>
</div>
` : ''}
</div>
`;
if (dismissible) {
this.shadowRoot.getElementById('dismiss').addEventListener('click', () => {
this.remove();
});
}
}
}
customElements.define('custom-alert', CustomAlert);