from django_components import Component, register, types DESCRIPTION = "Use HTML fragments (partials) with HTMX, AlpineJS, or plain JS." @register("simple_fragment") class SimpleFragment(Component): """A simple fragment with JS and CSS.""" class Kwargs: type: str template: types.django_html = """
Fragment with JS and CSS (plain).
""" js: types.js = """ document.querySelector('#frag-text').textContent = ' JavaScript has run.'; """ css: types.css = """ .frag_simple { background: #f0f8ff; border: 1px solid #add8e6; padding: 1rem; border-radius: 5px; } """ @register("alpine_fragment") class AlpineFragment(Component): """A fragment that defines an AlpineJS component.""" class Kwargs: type: str # The fragment is wrapped in `