File size: 1,682 Bytes
dcdc07a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
  "id": "button-set",
  "name": "Button Set",
  "description": "Multiple buttons that trigger events with click data",
  "author": "gradio",
  "tags": [
    "input",
    "buttons",
    "events"
  ],
  "category": "input",
  "html_template": "<button id='A'>A</button>\n<button id='B'>B</button>\n<button id='C'>C</button>",
  "css_template": "button {\n    padding: 10px 20px;\n    background-color: #f97316;\n    color: white;\n    border: none;\n    border-radius: 8px;\n    cursor: pointer;\n    font-weight: 600;\n    margin-right: 8px;\n    transition: background 0.15s;\n}\nbutton:hover { background-color: #ea580c; }",
  "js_on_load": "const buttons = element.querySelectorAll('button');\nbuttons.forEach(button => {\n    button.addEventListener('click', () => {\n        trigger('click', {clicked: button.innerText});\n    });\n});",
  "default_props": {},
  "python_code": "button_set = gr.HTML(\n    html_template=\"\"\"\n    <button id='A'>A</button>\n    <button id='B'>B</button>\n    <button id='C'>C</button>\n    \"\"\",\n    css_template=\"\"\"\n    button {\n        padding: 10px 20px;\n        background-color: #f97316;\n        color: white; border: none;\n        border-radius: 8px; cursor: pointer;\n    }\n    button:hover { background-color: #ea580c; }\n    \"\"\",\n    js_on_load=\"\"\"\n    const buttons = element.querySelectorAll('button');\n    buttons.forEach(button => {\n        button.addEventListener('click', () => {\n            trigger('click', {clicked: button.innerText});\n        });\n    });\n    \"\"\"\n)\n\ndef on_button_click(evt: gr.EventData):\n    return evt.clicked\n\nbutton_set.click(on_button_click, outputs=clicked_box)"
}