Skip to content

Commit 3f9ce86

Browse files
committed
Added class-components and more
1 parent a039c3a commit 3f9ce86

25 files changed

+2481
-326
lines changed

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
- [Create Element](#create-element)
88
- [Animator](#animator)
99
- [Web-Components](#web-components)
10-
10+
- [Typescript Component](#typescript-class-component)
11+
- [Typescript Component](#javascript-class-component)
1112

1213
- [JDOM-Template](#jdom-template) Create Projects with JS-Template Strings with reactivity
1314
- [Reactivity](#reactivity)
@@ -130,6 +131,53 @@ $r('my-component', MyComponent)
130131
</script>
131132
```
132133

134+
# Typescript Class-Component
135+
136+
```ts
137+
import { html, JDOMComponent } from 'jdomjs'
138+
import { CustomElement, State } from "jdomjs/decorator.ts";
139+
140+
@CustomElement('example-component')
141+
class ExampleComponent extends JDOMComponent {
142+
@State()
143+
private name: Hook<String> = 'John'
144+
145+
@Computed(s => [s.name])
146+
private greetings() {
147+
return comp`Hello ${this.name}`
148+
}
149+
150+
render() {
151+
return html`
152+
<input :bind=${this.name}>
153+
<h1>${this.greetings}</h1>
154+
`
155+
}
156+
}
157+
```
158+
159+
# Javascript Class-Component
160+
```ts
161+
import { html, JDOMComponent, $r } from 'jdomjs'
162+
163+
class ExampleComponent extends JDOMComponent {
164+
private name = new Hook('John')
165+
166+
private greetings() {
167+
return comp`Hello ${this.name}`
168+
}
169+
170+
render() {
171+
return html`
172+
<input :bind=${this.name}>
173+
<h1>${this.greetings()}</h1>
174+
`
175+
}
176+
}
177+
178+
$r('example-component', ExampleComponent)
179+
```
180+
133181
# JDOM-Template
134182
```js
135183
import { html } from 'jdomjs'

dist/jdom.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example.html

Lines changed: 0 additions & 244 deletions
This file was deleted.

examples/dom-manipulation/index.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Document</title>
9+
</head>
10+
<body>
11+
12+
<div id="todo-app">
13+
<input type="text" id="new-task" placeholder="Add a new task and press Enter"/>
14+
<button id="add-task">Add Task</button>
15+
<ul id="tasks-list"></ul>
16+
</div>
17+
18+
<script type="module">
19+
import { $, $n, html } from '../../index.js';
20+
21+
// Function to create a new task item
22+
function createTask(text) {
23+
const li = $n('li').text(text);
24+
25+
const button = $n('button')
26+
.text('Remove')
27+
.click(() => li.remove());
28+
29+
li.append(button);
30+
31+
return li;
32+
}
33+
34+
// Adding a task
35+
function addTask() {
36+
const input = $('#new-task');
37+
const taskText = input.val().trim();
38+
39+
if (taskText) {
40+
const tasksList = $('#tasks-list');
41+
tasksList.append(
42+
createTask(taskText)
43+
);
44+
45+
input.val(''); // Clear input after adding
46+
}
47+
}
48+
49+
// Binding actions
50+
$('#add-task').click(addTask);
51+
$('#new-task').on('keypress', (e) => {
52+
if (e.key === 'Enter') addTask();
53+
});
54+
</script>
55+
56+
</body>
57+
</html>

0 commit comments

Comments
 (0)