tagu-tagu 3.2.3 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +177 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,6 +72,183 @@ Modify(document.body, {
|
|
|
72
72
|
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
#### `html` initializer
|
|
76
|
+
[JSFiddle](https://jsfiddle.net/do_the_simplest/6p9jh45L/2/)
|
|
77
|
+
```typescript
|
|
78
|
+
import { div } from "tagu-tagu";
|
|
79
|
+
|
|
80
|
+
// Element: innerHTML
|
|
81
|
+
function HtmlExample() {
|
|
82
|
+
return div({ html: `<button>Hello World!</button>` });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
document.body.appendChild(HtmlExample());
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### `css` initializer
|
|
90
|
+
[JSFiddle](https://jsfiddle.net/do_the_simplest/mfLutvnc/1/)
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { button } from "tagu-tagu";
|
|
94
|
+
|
|
95
|
+
// element.style.setProperty
|
|
96
|
+
function CssExample() {
|
|
97
|
+
return button({
|
|
98
|
+
css: { width: "300px", height: "300px" },
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
document.body.appendChild(CssExample());
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### `attr` initializer
|
|
106
|
+
[JSFiddle](https://jsfiddle.net/do_the_simplest/r8a423pw/1/)
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { input } from "tagu-tagu";
|
|
110
|
+
|
|
111
|
+
// Element: setAttribute
|
|
112
|
+
function AttrExample() {
|
|
113
|
+
return input({
|
|
114
|
+
attr: { type: "color" },
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
document.body.appendChild(AttrExample());
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### `prop` initializer
|
|
122
|
+
[JSFiddle](https://jsfiddle.net/do_the_simplest/mc38ksqw/1/)
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { option, select } from "tagu-tagu";
|
|
126
|
+
|
|
127
|
+
// Element: setAttribute
|
|
128
|
+
function AttrExample() {
|
|
129
|
+
return select([option("One"), option("Two"), option("Three")], {
|
|
130
|
+
prop: { selectedIndex: 1 },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
document.body.appendChild(AttrExample());
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### `on` initializer
|
|
138
|
+
[JSFiddle](https://jsfiddle.net/do_the_simplest/Lsjmw263/)
|
|
139
|
+
```typescript
|
|
140
|
+
import { button } from "tagu-tagu";
|
|
141
|
+
|
|
142
|
+
// Element: addEventListener
|
|
143
|
+
function OnExample() {
|
|
144
|
+
return button("Click Me", { on: { click: () => alert("Hello!") } });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
document.body.appendChild(OnExample());
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### `$` initializer
|
|
151
|
+
[JSFiddle](https://jsfiddle.net/do_the_simplest/b8roj7wx/1/)
|
|
152
|
+
```html
|
|
153
|
+
<form>
|
|
154
|
+
<div>Name: <input id="name"></div>
|
|
155
|
+
<div>Age: <input id="age"></div>
|
|
156
|
+
<button id="submit">Submit</button>
|
|
157
|
+
</form>
|
|
158
|
+
<script type="module" src="index.ts"></script>
|
|
159
|
+
```
|
|
160
|
+
```typescript
|
|
161
|
+
import { Modify, style } from "tagu-tagu";
|
|
162
|
+
|
|
163
|
+
// Element: querySelector
|
|
164
|
+
function $Example() {
|
|
165
|
+
Modify("form", {
|
|
166
|
+
$: {
|
|
167
|
+
"#name": { prop: { defaultValue: "Einstein" } },
|
|
168
|
+
"#age": { attr: { type: "number" }, prop: { defaultValue: 26 } },
|
|
169
|
+
"#submit": [
|
|
170
|
+
style({
|
|
171
|
+
"#submit": {
|
|
172
|
+
background: "blue",
|
|
173
|
+
color: "white",
|
|
174
|
+
border: "none",
|
|
175
|
+
"border-radius": "10px",
|
|
176
|
+
},
|
|
177
|
+
"#submit:hover": {
|
|
178
|
+
background: "skyblue",
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
$Example();
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### `$$` initializer
|
|
190
|
+
[JSFiddle](https://jsfiddle.net/do_the_simplest/gqe5378t/1/)
|
|
191
|
+
```html
|
|
192
|
+
<meta charset="utf-8">
|
|
193
|
+
<div>
|
|
194
|
+
<h1>Unfertilized Eggs</h1>
|
|
195
|
+
<button>🥚</button>
|
|
196
|
+
<button>🥚</button>
|
|
197
|
+
<button>🥚</button>
|
|
198
|
+
<button>🥚</button>
|
|
199
|
+
<button>🥚</button>
|
|
200
|
+
</div>
|
|
201
|
+
<div id="fertilized">
|
|
202
|
+
<h1>Click!</h1>
|
|
203
|
+
<button>🥚</button>
|
|
204
|
+
<button>🥚</button>
|
|
205
|
+
<button>🥚</button>
|
|
206
|
+
<button>🥚</button>
|
|
207
|
+
<button>🥚</button>
|
|
208
|
+
</div>
|
|
209
|
+
<script type="module" src="index.ts"></script>
|
|
210
|
+
```
|
|
211
|
+
```typescript
|
|
212
|
+
import { Modify } from "tagu-tagu";
|
|
213
|
+
|
|
214
|
+
// Element: querySelectorAll
|
|
215
|
+
function $$Example() {
|
|
216
|
+
Modify("#fertilized", {
|
|
217
|
+
$$: {
|
|
218
|
+
button: {
|
|
219
|
+
on: {
|
|
220
|
+
click: (e) => {
|
|
221
|
+
(e.target as HTMLButtonElement).textContent = "🐣";
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
$$Example();
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
#### Callback initializer
|
|
233
|
+
[JSFiddle](https://jsfiddle.net/do_the_simplest/tfj8uqa7/3/)
|
|
234
|
+
```typescript
|
|
235
|
+
import { button, div } from "tagu-tagu";
|
|
236
|
+
|
|
237
|
+
function InitializerCallbackExample() {
|
|
238
|
+
return div([
|
|
239
|
+
div([
|
|
240
|
+
div([
|
|
241
|
+
button("Deep", (button) =>
|
|
242
|
+
console.log("debug:", button, "is created!"),
|
|
243
|
+
),
|
|
244
|
+
]),
|
|
245
|
+
]),
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
document.body.appendChild(InitializerCallbackExample());
|
|
250
|
+
```
|
|
251
|
+
|
|
75
252
|
### `If`
|
|
76
253
|
|
|
77
254
|
```typescript
|