html-tag-js

2.3.0 • Public • Published

html-tag-js

A simple library for creating and manipulating DOM using JavaScript DOM api with out of the box support for JSX like syntax.

Documentation

Installation

npm i html-tag-js

or directly import into browser

path/to/html-tag-js/dist/tag.js

Enable JSX like syntax

To enable JSX like syntax, use html-tag-js/tag-loader as loader in webpack.

module.exports = {
  module: {
    ...
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: ['html-tag-js/jsx/tag-loader.js'],
      },
      ...
    ],
  },
};

And in add following lines in babel configuration file.

{
  ...
  "plugins": [
    "html-tag-js/jsx/jsx-to-tag.js",
    "html-tag-js/jsx/syntax-parser.js",
    ...
  ],
  ...
}

Usage

To create elements, use tag function. It accepts tag name, options and children as arguments. Checkout tag for more details.

import 'html-tag-js/dist/polyfill'; // optional
// no need to import tag from 'html-tag-js'
// if you are using tag-loader
import tag from 'html-tag-js';

Cheat Sheet

Use Reactive to create reactive node

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 for more details.

import Reactive from 'html-tag-js/Reactive';

const count = Reactive(0);

document.body.append(
  <div>
    <h1>{count}</h1>
    <button onclick={() => count.value++}>Increment</button>
  </div>
);

Use Ref to get reference of the node

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 for more details.

import Ref from 'html-tag-js/Ref';

const ref = Ref(node => {
  console.log(node); // <h1>Hello</h1>
});

// Change style of the node before or after referencing
ref.style.color = 'red';

document.body.append(
  <div>
    <h1 ref={ref}>Hello</h1>
  </div>
);

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.3.049latest

Version History

VersionDownloads (Last 7 Days)Published
2.3.049
2.2.061
2.0.42
2.0.30
2.0.20
1.9.227
1.9.00
1.8.51
1.8.31
1.8.25
1.8.11
1.7.11
1.6.00
1.5.116
1.5.00
1.4.41
1.4.31
1.4.20
1.4.10
1.4.00
1.3.01
1.2.01
1.1.414
1.1.400
1.1.391
1.1.381
1.1.371
1.1.360
1.1.350
1.1.341
1.1.331
1.1.310
1.1.300
1.1.290
1.1.280
1.1.270
1.1.260
1.1.250
1.1.240
1.1.231
1.1.225
1.1.210
1.1.200
1.1.191
1.1.181
1.1.160
1.1.150
1.1.140
1.1.130
1.1.120
1.1.111
1.1.100
1.1.90
1.1.81
1.1.60
1.1.51
1.1.42
1.1.31
1.1.20
1.1.10
1.1.00
1.0.40
1.0.30
1.0.20
1.0.12
1.0.01
0.2.221
0.2.210
0.2.202
0.0.190
0.0.182
0.0.160
0.0.150
0.0.140
0.0.130
0.0.120
0.0.110
0.0.11

Package Sidebar

Install

npm i html-tag-js

Weekly Downloads

148

Version

2.3.0

License

MIT

Unpacked Size

72 kB

Total Files

11

Last publish

Collaborators

  • deadlyjack