1.0.3 • Published 4 years ago

@newtek-software/create_element v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Introduction

This create element utility takes works very similar to the React createComponent, but you don't need React to use this. You can rapidly build UI's with full control of data and state management

Zero dependencies

Setup

  1. npm i @newtek-software/create_element
  2. import create_element from '@newtek-software/create_element'

Usage

It's incredibly easy to use and makes for clean and concise code. No more having to decide whether to write in HTML or JS

create_element(tagName, HTMLELement Properties, children)

Examples

export default class LoginForm {
  constructor() {
        return create_element('form', {
            onsubmit: ev => {
                ev.preventDefault();
                this.submit();
            }
        }, [
            create_element('div', 'mb-2', [
                create_element('label', {
                    className: this.label_class,
                    innerText: 'Username',
                }),
                create_element('input', {
                    className: this.input_class,
                    name: 'username',
                    required: true,
                })
            ]),
            create_element('div', 'mb-2', [
                create_element('label', {
                    className: this.label_class,
                    innerText: 'Password',
                }),
                create_element('input', {
                    className: this.input_class,
                    required: true,
                    name: 'password',
                    type: 'password'
                })
            ]),
            create_element('button', {
                innerText: 'Submit',
                className: this.submit_btn_class
            }),
        ])
    }
}