Add component: H T M L Accordion
#2
by
abidlabs HF Staff - opened
- components/h-t-m-l-accordion.json +17 -0
- manifest.json +7 -0
components/h-t-m-l-accordion.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": "h-t-m-l-accordion",
|
| 3 |
+
"name": "H T M L Accordion",
|
| 4 |
+
"description": "",
|
| 5 |
+
"author": "",
|
| 6 |
+
"tags": [],
|
| 7 |
+
"html_template": "\n <section class='acc ${open ? \"open\" : \"\"}'>\n <button class='acc-btn' type='button'>\n <span>${title_html}</span>\n <span class='acc-icon'>\u25be</span>\n </button>\n <div class='acc-body'></div>\n </section>\n @children\n ",
|
| 8 |
+
"css_template": "\n border: 1px solid var(--border-color-primary);\n border-radius: var(--radius-md);\n overflow: hidden;\n margin-bottom: 10px;\n .acc-btn { width: 100%; border: none; text-align: left; padding: 10px 12px; display: flex; justify-content: space-between; background: var(--background-fill-primary); color: var(--body-text-color); cursor: pointer; }\n .acc-body { display: none; padding: 12px; background: var(--background-fill-primary); }\n .acc.open .acc-body { display: block; border-top: 1px solid var(--border-color-primary); }\n .acc.open .acc-icon { transform: rotate(180deg); }\n ",
|
| 9 |
+
"js_on_load": "\n const root = element.querySelector('.acc');\n const button = element.querySelector('.acc-btn');\n const body = element.querySelector('.acc-body');\n if (!root || !button || !body) return;\n\n if (!element.dataset.movedChildren) {\n const nodes = Array.from(element.children).filter((node) => node !== root);\n nodes.forEach((node) => {\n if (node === body) return;\n if (node.contains(body) || body.contains(node)) return;\n body.appendChild(node);\n });\n element.dataset.movedChildren = \"1\";\n }\n\n if (!button.dataset.boundClick) {\n button.addEventListener('click', () => root.classList.toggle('open'));\n button.dataset.boundClick = \"1\";\n }\n ",
|
| 10 |
+
"default_props": {
|
| 11 |
+
"value": "",
|
| 12 |
+
"title_html": "<b>Section 1</b> <span style='color:#2563eb;'>HTML title</span>",
|
| 13 |
+
"open": true
|
| 14 |
+
},
|
| 15 |
+
"python_code": "class HTMLAccordion(gr.HTML):\n def __init__(self, title_html: str, open: bool = False, **kwargs):\n html_template = \"\"\"\n <section class='acc ${open ? \"open\" : \"\"}'>\n <button class='acc-btn' type='button'>\n <span>${title_html}</span>\n <span class='acc-icon'>\u25be</span>\n </button>\n <div class='acc-body'></div>\n </section>\n @children\n \"\"\"\n css_template = \"\"\"\n border: 1px solid var(--border-color-primary);\n border-radius: var(--radius-md);\n overflow: hidden;\n margin-bottom: 10px;\n .acc-btn { width: 100%; border: none; text-align: left; padding: 10px 12px; display: flex; justify-content: space-between; background: var(--background-fill-primary); color: var(--body-text-color); cursor: pointer; }\n .acc-body { display: none; padding: 12px; background: var(--background-fill-primary); }\n .acc.open .acc-body { display: block; border-top: 1px solid var(--border-color-primary); }\n .acc.open .acc-icon { transform: rotate(180deg); }\n \"\"\"\n js_on_load = \"\"\"\n const root = element.querySelector('.acc');\n const button = element.querySelector('.acc-btn');\n const body = element.querySelector('.acc-body');\n if (!root || !button || !body) return;\n\n if (!element.dataset.movedChildren) {\n const nodes = Array.from(element.children).filter((node) => node !== root);\n nodes.forEach((node) => {\n if (node === body) return;\n if (node.contains(body) || body.contains(node)) return;\n body.appendChild(node);\n });\n element.dataset.movedChildren = \"1\";\n }\n\n if (!button.dataset.boundClick) {\n button.addEventListener('click', () => root.classList.toggle('open'));\n button.dataset.boundClick = \"1\";\n }\n \"\"\"\n super().__init__(\n title_html=title_html,\n open=open,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load,\n **kwargs,\n )\n",
|
| 16 |
+
"head": ""
|
| 17 |
+
}
|
manifest.json
CHANGED
|
@@ -150,5 +150,12 @@
|
|
| 150 |
"media"
|
| 151 |
],
|
| 152 |
"category": "display"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
}
|
| 154 |
]
|
|
|
|
| 150 |
"media"
|
| 151 |
],
|
| 152 |
"category": "display"
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"id": "h-t-m-l-accordion",
|
| 156 |
+
"name": "H T M L Accordion",
|
| 157 |
+
"description": "",
|
| 158 |
+
"author": "",
|
| 159 |
+
"tags": []
|
| 160 |
}
|
| 161 |
]
|