custom-html-gallery / components /likert-scale.json
freddyaboulton's picture
Add manifest.json and individual component files
dcdc07a verified
{
"id": "likert-scale",
"name": "Likert Scale",
"description": "Agreement scale from Strongly Disagree to Strongly Agree",
"author": "gradio",
"tags": [
"input",
"survey",
"scale"
],
"category": "input",
"html_template": "<div class=\"likert-container\">\n <div class=\"likert-question\">${question}</div>\n <div class=\"likert-scale\">\n ${['Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'].map((label, i) => `\n <label class=\"likert-option ${value === i + 1 ? 'selected' : ''}\">\n <input type=\"radio\" name=\"likert\" value=\"${i + 1}\" ${value === i + 1 ? 'checked' : ''} />\n <span class=\"likert-dot\"></span>\n <span class=\"likert-label\">${label}</span>\n </label>\n `).join('')}\n </div>\n</div>",
"css_template": ".likert-container { padding: 8px 0; }\n.likert-question { font-weight: 600; margin-bottom: 16px; font-size: 15px; }\n.likert-scale { display: flex; justify-content: space-between; gap: 4px; }\n.likert-option { display: flex; flex-direction: column; align-items: center; cursor: pointer; flex: 1; gap: 8px; }\n.likert-option input { display: none; }\n.likert-dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #d1d5db; transition: all 0.2s; }\n.likert-option:hover .likert-dot { border-color: #f97316; }\n.likert-option.selected .likert-dot { background: #f97316; border-color: #f97316; }\n.likert-label { font-size: 11px; text-align: center; color: #6b7280; line-height: 1.3; }",
"js_on_load": "const radios = element.querySelectorAll('input[type=\"radio\"]');\nradios.forEach(radio => {\n radio.addEventListener('change', () => {\n props.value = parseInt(radio.value);\n });\n});",
"default_props": {
"value": 0,
"question": "This component is easy to use"
},
"python_code": "class LikertScale(gr.HTML):\n def __init__(self, question=\"Rate this item\", value=0, **kwargs):\n html_template = \"\"\"\n <div class=\"likert-container\">\n <div class=\"likert-question\">${question}</div>\n <div class=\"likert-scale\">\n ${['Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'].map((label, i) => `\n <label class=\"likert-option ${value === i + 1 ? 'selected' : ''}\">\n <input type=\"radio\" name=\"likert\" value=\"${i + 1}\" ${value === i + 1 ? 'checked' : ''} />\n <span class=\"likert-dot\"></span>\n <span class=\"likert-label\">${label}</span>\n </label>\n `).join('')}\n </div>\n </div>\n \"\"\"\n css_template = \"\"\"\n .likert-scale { display: flex; justify-content: space-between; }\n .likert-option { display: flex; flex-direction: column; align-items: center; cursor: pointer; }\n .likert-dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #d1d5db; }\n .likert-option.selected .likert-dot { background: #f97316; border-color: #f97316; }\n \"\"\"\n js_on_load = \"\"\"\n const radios = element.querySelectorAll('input[type=\"radio\"]');\n radios.forEach(radio => {\n radio.addEventListener('change', () => {\n props.value = parseInt(radio.value);\n });\n });\n \"\"\"\n super().__init__(\n value=value, question=question,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load, **kwargs\n )\n\n def api_info(self):\n return {\"type\": \"integer\", \"minimum\": 0, \"maximum\": 5}"
}