Download components/code-explanation.js from Abmacode12/codewhale-the-dev-dashboard: direct link, hf CLI and curl.
- Browser
- Download file 3.85 kB
-
https://huggingface.co/spaces/Abmacode12/codewhale-the-dev-dashboard/resolve/main/components/code-explanation.js
- Command line
-
hf download hf://spaces/Abmacode12/codewhale-the-dev-dashboard/components/code-explanation.js
-
curl -L -o code-explanation.js https://huggingface.co/spaces/Abmacode12/codewhale-the-dev-dashboard/resolve/main/components/code-explanation.js
3.85 kB
| class CustomCodeExplanation extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this.attachShadow({ mode: 'open' }); | |
| } | |
| connectedCallback() { | |
| this.render(); | |
| } | |
| static get observedAttributes() { | |
| return ['explanation', 'generated-code']; | |
| } | |
| attributeChangedCallback(name, oldValue, newValue) { | |
| if (oldValue !== newValue) { | |
| this.render(); | |
| } | |
| } | |
| render() { | |
| const explanation = this.getAttribute('explanation') || 'Select a tool to generate code and see explanations'; | |
| const generatedCode = this.getAttribute('generated-code') || '// No code generated yet'; | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| :host { | |
| display: block; | |
| } | |
| .header { | |
| display: flex; | |
| align-items: center; | |
| margin-bottom: 1.5rem; | |
| } | |
| .header i { | |
| margin-right: 0.75rem; | |
| color: #3b82f6; | |
| } | |
| .header h2 { | |
| font-size: 1.25rem; | |
| font-weight: 600; | |
| color: #1e293b; | |
| } | |
| .explanation-box { | |
| background-color: #f8fafc; | |
| border-radius: 0.5rem; | |
| padding: 1.5rem; | |
| margin-bottom: 1.5rem; | |
| border: 1px solid #e2e8f0; | |
| } | |
| .code-box { | |
| background-color: #1e293b; | |
| color: #f8fafc; | |
| border-radius: 0.5rem; | |
| padding: 1.5rem; | |
| font-family: monospace; | |
| white-space: pre-wrap; | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| .code-box::before { | |
| content: 'CODE'; | |
| position: absolute; | |
| top: 0; | |
| right: 0; | |
| background-color: #3b82f6; | |
| color: white; | |
| font-size: 0.75rem; | |
| padding: 0.25rem 0.5rem; | |
| border-bottom-left-radius: 0.5rem; | |
| } | |
| .code-tabs { | |
| display: flex; | |
| margin-bottom: -1px; | |
| } | |
| .code-tab { | |
| padding: 0.5rem 1rem; | |
| background-color: #e2e8f0; | |
| border: 1px solid #cbd5e1; | |
| border-bottom: none; | |
| border-radius: 0.375rem 0.375rem 0 0; | |
| margin-right: 0.25rem; | |
| cursor: pointer; | |
| } | |
| .code-tab.active { | |
| background-color: #1e293b; | |
| color: white; | |
| border-color: #1e293b; | |
| } | |
| </style> | |
| <div class="header"> | |
| <i data-feather="book-open"></i> | |
| <h2>Explication du Code</h2> | |
| </div> | |
| <div class="explanation-box"> | |
| ${explanation} | |
| </div> | |
| <div class="code-tabs"> | |
| <div class="code-tab active">CSS</div> | |
| <div class="code-tab">HTML</div> | |
| <div class="code-tab">JS</div> | |
| </div> | |
| <div class="code-box"> | |
| ${generatedCode} | |
| </div> | |
| `; | |
| feather.replace(); | |
| } | |
| } | |
| customElements.define('custom-code-explanation', CustomCodeExplanation); |