Its pretty self explanatory and used for internal development of components that need to work within a very lightweight environment. Originally designed for the Atom IDE, so very much inspired by the Atom extensions.
Take a look at Element.
It accepts the following arguments (in order):
const element = new Element('div', 'my-class', 'My element!');
@param {type} string - type of dom node, default: 'div'.
@param {klass} string - class name.
@param {text} string - text content.
@param {opts} object - for adding addional params like data, attrs, children.
@returns {Element} Returns a instance of Element.
Sets or returns the text content
element.text('new text');
// <div class='my-class'>new text</div>
@param {text} string - optional - text.
Appends another component as a child
element.add(new Element('span'));
// <div class='my-class'><span></span></div>
@param {component} Element
Show the component; display: block
element.show();
Hide the component; display: none
element.hide();
Toggle the visibility of the component; triggers show()
or hide()
depending on the visibility.
Clear the innerHTML of the component; innerHTML = ''
element.clear();
clear()
and add()
a component
element.replace(new Element('p'));
// <div class='my-class'><p></p></div>
@param {component} Element
adds or removes a specific class string
element.toggleClass(`toggled`);
// <div class='my-class toggled'></div>
element.toggleClass(`toggled`);
// <div class='my-class'></div>
@param {className} string
overrides the className
element.className(`new-class`);
// <div class='new-class'></div>
@param {className} string
Adds a click
EventListener
element.onClick(() => console.log('click));
@param {fn} Function
Adds a double click
EventListener
element.onDblClick(() => console.log('click));
@param {fn} Function
Sets an attribute on the dom element
element.attr('store-id', 3);
// <div class='my-class' store-id='3'></div>
@param {key} string
@param {value} string
The same as setting innerHTML
element.insertTemplate(`<span></span>`);
// <div class='my-class'><span></span></div>
@param {template} string
Add a component as innerHTML
element.insertTemplate(new Element('span'));
// <div class='my-class'><span></span></div>
@param {component} Element
Append template
element.insertTemplate(`<span></span>`);
// <div class='my-class'><span></span></div>
@param {template} string
Append a component as innerHTML
element.insertTemplate(new Element('span'));
// <div class='my-class'><span></span></div>
@param {component} Element
There are other Elements.