Spaces:
Running
Running
Download components/alert.js from Mustavi/flowforge-admin-portal: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/spaces/Mustavi/flowforge-admin-portal/resolve/main/components/alert.js
- Command line
-
hf download hf://spaces/Mustavi/flowforge-admin-portal/components/alert.js
-
curl -L -o alert.js https://huggingface.co/spaces/Mustavi/flowforge-admin-portal/resolve/main/components/alert.js
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); |