| { | |
| "id": "colored-checkbox-group", | |
| "name": "Colored Checkbox Group", | |
| "description": "Multi-select checkbox group with custom colors per option", | |
| "author": "gradio", | |
| "tags": [ | |
| "input", | |
| "checkbox", | |
| "color" | |
| ], | |
| "category": "input", | |
| "html_template": "<div class=\"colored-checkbox-container\">\n ${label ? `<label class=\"container-label\">${label}</label>` : ''}\n <div class=\"colored-checkbox-group\">\n ${choices.map((choice, i) => `\n <label class=\"checkbox-label\" data-color-index=\"${i}\">\n <input type=\"checkbox\" value=\"${choice}\" ${(value || []).includes(choice) ? 'checked' : ''}>\n ${choice}\n </label>\n `).join('')}\n </div>\n</div>", | |
| "css_template": ".colored-checkbox-container { border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; }\n.container-label { display: block; margin-bottom: 12px; font-weight: 600; }\n.colored-checkbox-group { display: flex; flex-direction: column; gap: 6px; }\n.checkbox-label { display: flex; align-items: center; cursor: pointer; padding: 4px 0; }\n.checkbox-label input { margin-right: 8px; }\n${choices.map((choice, i) => `.checkbox-label[data-color-index=\"${i}\"] { color: ${colors[i]}; }`).join(' ')}", | |
| "js_on_load": "const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\ncheckboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n props.value = Array.from(checkboxes)\n .filter(cb => cb.checked)\n .map(cb => cb.value);\n });\n});", | |
| "default_props": { | |
| "value": [], | |
| "choices": [ | |
| "Apple", | |
| "Banana", | |
| "Cherry" | |
| ], | |
| "colors": [ | |
| "#dc2626", | |
| "#eab308", | |
| "#dc2626" | |
| ], | |
| "label": "Select fruits" | |
| }, | |
| "python_code": "class ColoredCheckboxGroup(gr.HTML):\n def __init__(self, choices, *, value=None, colors, label=None, **kwargs):\n html_template = \"\"\"\n <div class=\"colored-checkbox-container\">\n ${label ? `<label>${label}</label>` : ''}\n <div class=\"colored-checkbox-group\">\n ${choices.map((choice, i) => `\n <label class=\"checkbox-label\" data-color-index=\"${i}\">\n <input type=\"checkbox\" value=\"${choice}\"\n ${(value || []).includes(choice) ? 'checked' : ''}>\n ${choice}\n </label>\n `).join('')}\n </div>\n </div>\n \"\"\"\n css_template = \"\"\"\n .colored-checkbox-group { display: flex; flex-direction: column; gap: 6px; }\n .checkbox-label { display: flex; align-items: center; cursor: pointer; }\n ${choices.map((choice, i) =>\n `.checkbox-label[data-color-index=\"${i}\"] { color: ${colors[i]}; }`\n ).join(' ')}\n \"\"\"\n js_on_load = \"\"\"\n const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\n checkboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n props.value = Array.from(checkboxes)\n .filter(cb => cb.checked)\n .map(cb => cb.value);\n });\n });\n \"\"\"\n super().__init__(\n value=value or [], choices=choices,\n colors=colors, label=label,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load, **kwargs\n )" | |
| } |