{ "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": "
\n
${question}
\n
\n ${['Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'].map((label, i) => `\n \n `).join('')}\n
\n
", "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
\n
${question}
\n
\n ${['Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'].map((label, i) => `\n \n `).join('')}\n
\n
\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}" }