mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 06:18:17 +00:00
Implement single file components
This commit is contained in:
parent
27521a5402
commit
70a2a01400
5 changed files with 238 additions and 24 deletions
25
sampleproject/components/greeting.py
Normal file
25
sampleproject/components/greeting.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from django_components import component
|
||||
|
||||
|
||||
@component.register("greeting")
|
||||
class greeting(component.Component):
|
||||
def get_context_data(self, greet, *args, **kwargs):
|
||||
return {"greet": greet}
|
||||
|
||||
template = """
|
||||
<div id="greeting">{{ greet }}</div>
|
||||
"""
|
||||
|
||||
css = """
|
||||
#greeting {
|
||||
display: inline-block;
|
||||
color: blue;
|
||||
font-size: 2em;
|
||||
}
|
||||
"""
|
||||
|
||||
js = """
|
||||
document.getElementById("greeting").addEventListener("click", (event) => {
|
||||
alert("Hello!");
|
||||
});
|
||||
"""
|
Loading…
Add table
Add a link
Reference in a new issue