Skip to content

Commit a988d1f

Browse files
author
Ajit Kumar
committed
v2.0.0
1 parent c745750 commit a988d1f

19 files changed

+885
-255
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change log html-tag-js
22

3+
## 2.0.0
4+
5+
- Removed `tag.use` method instead use `html-tag-js/Reactive` to create reactive node. E.g. `const count = Reactive(0);`
6+
- Now you can pass `onref` callback to `Ref(onrefCallback)` constructor to get reference of the node.
7+
- Supports promise in children. E.g. `<div>{Promise.resolve('hello')}</div` will render `<div>hello</div>`
8+
39
## 1.4.0
410

511
- Filter out null and undefined node from children

README.md

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# html-tag-js
22

3-
A simple library for creating and manipulating DOM using JavaScript DOM api.
4-
See
3+
A simple library for creating and manipulating DOM using JavaScript DOM api with out of the box support for JSX like syntax.
54

65
## Documentation
76

@@ -17,54 +16,87 @@ or directly import into browser
1716
path/to/html-tag-js/dist/tag.js
1817
```
1918

19+
### Enable JSX like syntax
20+
21+
To enable JSX like syntax, use `html-tag-js/tag-loader` as loader in webpack.
22+
23+
```json
24+
module.exports = {
25+
module: {
26+
...
27+
rules: [
28+
{
29+
test: /\.jsx?$/,
30+
exclude: /node_modules/,
31+
use: ['html-tag-js/jsx/tag-loader.js'],
32+
},
33+
...
34+
],
35+
},
36+
};
37+
```
38+
39+
And in add following lines in babel configuration file.
40+
41+
```json
42+
{
43+
...
44+
"plugins": [
45+
"html-tag-js/jsx/jsx-to-tag.js",
46+
"html-tag-js/jsx/syntax-parser.js",
47+
...
48+
],
49+
...
50+
}
51+
```
52+
2053
### Usage
2154

22-
#### es6
55+
To create elements, use `tag` function. It accepts tag name, options and children as arguments. Checkout [tag](./docs/tag.md) for more details.
2356

2457
```javascript
58+
import 'html-tag-js/dist/polyfill'; // optional
59+
// no need to import tag from 'html-tag-js'
60+
// if you are using tag-loader
2561
import tag from 'html-tag-js';
26-
import 'html-tag-js/dist/polyfill'; //Important (only once);
2762
```
2863

29-
##### usage
64+
### Cheat Sheet
3065

31-
```javascript
32-
//creating element with options
33-
const span = tag('span', {
34-
textContent: 'This is span tag',
35-
className: 'myspan',
36-
id: 'span1',
37-
});
66+
#### Use `Reactive` to create reactive node
3867

39-
//create element with child
40-
const div = tag('div', {
41-
child: span,
42-
});
68+
To create a reactive node, use `Reactive` constructor. It accepts initial value and returns an object with `value` property to get/set the value and `onChange` callback to listen for value changes. Checkout [Reactive](./docs/reactive.md) for more details.
4369

44-
const elements = [el1, el2, el3];
70+
```javascript
71+
import Reactive from 'html-tag-js/Reactive';
4572

46-
//append child(s)
47-
div.append(...elements);
73+
const count = Reactive(0);
4874

49-
//easily get any child of parent element using get method which
50-
//takes query selector string as argument
51-
div.get('#span1');
75+
document.body.append(
76+
<div>
77+
<h1>{count}</h1>
78+
<button onclick={() => count.value++}>Increment</button>
79+
</div>
80+
);
81+
```
5282

53-
//get all element
54-
//return array of html elements
55-
div.getAll('span');
83+
#### Use `Ref` to get reference of the node
5684

57-
// --or--
85+
To get reference of the node, use `Ref` constructor. It accepts a callback function which will be called with the node as argument. Checkout [Ref](./docs/ref.md) for more details.
5886

59-
tag.get('body');
60-
tag.getAll('.mydiv');
87+
```javascript
88+
import Ref from 'html-tag-js/Ref';
6189

62-
//parse html string
90+
const ref = Ref(node => {
91+
console.log(node); // <h1>Hello</h1>
92+
});
6393

64-
//returns html element
65-
const el = tag.parse('<div class="mydiv"></div>');
66-
console.log(el);
94+
// Change style of the node before or after referencing
95+
ref.style.color = 'red';
6796

68-
//return html element collection
69-
const el2 = tag.parse('<div class="mydiv"></div><p class="myp">');
97+
document.body.append(
98+
<div>
99+
<h1 ref={ref}>Hello</h1>
100+
</div>
101+
);
70102
```

dist/Ref.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.

dist/polyfill.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.

0 commit comments

Comments
 (0)