Spaces:
Running
Running
| class KpiForm extends HTMLElement { | |
| connectedCallback() { | |
| this.attachShadow({ mode: 'open' }); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| .kpi-form { | |
| @apply bg-white rounded-lg shadow-md p-6 mb-6; | |
| } | |
| .form-title { | |
| @apply text-xl font-semibold text-gray-800 mb-4; | |
| } | |
| .form-group { | |
| @apply mb-4; | |
| } | |
| label { | |
| @apply block text-sm font-medium text-gray-700 mb-1; | |
| } | |
| input, select, textarea { | |
| @apply w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500; | |
| } | |
| .submit-btn { | |
| @apply w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200; | |
| } | |
| </style> | |
| <div class="kpi-form"> | |
| <h3 class="form-title">Update Daily KPI</h3> | |
| <form id="kpiForm"> | |
| <div class="form-group"> | |
| <label for="kpiDate">Date</label> | |
| <input type="date" id="kpiDate" required> | |
| </div> | |
| <div class="form-group"> | |
| <label for="kpiMetric">KPI Metric</label> | |
| <select id="kpiMetric" required> | |
| <option value="">Select Metric</option> | |
| <option value="productivity">Productivity</option> | |
| <option value="quality">Quality</option> | |
| <option value="efficiency">Efficiency</option> | |
| <option value="attendance">Attendance</option> | |
| </select> | |
| </div> | |
| <div class="form-group"> | |
| <label for="kpiValue">Value</label> | |
| <input type="number" id="kpiValue" min="0" max="100" required> | |
| </div> | |
| <div class="form-group"> | |
| <label for="kpiNotes">Notes</label> | |
| <textarea id="kpiNotes" rows="3"></textarea> | |
| </div> | |
| <button type="submit" class="submit-btn">Submit KPI</button> | |
| </form> | |
| </div> | |
| `; | |
| this.shadowRoot.getElementById('kpiForm').addEventListener('submit', (e) => { | |
| e.preventDefault(); | |
| const newKpi = { | |
| date: this.shadowRoot.getElementById('kpiDate').value, | |
| metric: this.shadowRoot.getElementById('kpiMetric').value, | |
| value: parseFloat(this.shadowRoot.getElementById('kpiValue').value), | |
| notes: this.shadowRoot.getElementById('kpiNotes').value, | |
| timestamp: new Date().toISOString() | |
| }; | |
| this.dispatchEvent(new CustomEvent('kpi-submitted', { detail: newKpi })); | |
| this.shadowRoot.getElementById('kpiForm').reset(); | |
| }); | |
| } | |
| } | |
| customElements.define('kpi-form', KpiForm); |