Git Product home page Git Product logo

elemental's Introduction

Elemental Library Documentation

Overview

The Elemental Library is a lightweight, flexible JavaScript library for creating and managing HTML elements programmatically. It provides a fluent API for building complex user interfaces in a more expressive and less verbose way.

Installation

To use Elemental in your project, you need to include the library in your project files:

yarn add @elementalui/elemental

or

npm install @elementalui/elemental

Usage

Class: Elemental

The Elemental class is the core of the library, allowing the creation and manipulation of HTML elements.

Properties

  • type: ElementType - The type of the HTML element.
  • parent: Elemental<any> | HTMLElement | null - The parent of the element, which can be another Elemental instance or a regular HTML element.
  • children: ElementalArray<any> - A collection of child Elemental instances.
  • onUnmount: undefined | ((element: Elemental<T>) => void) - A function that is called when the element is unmounted.

Methods

  • constructor(type: ElementType, classes: ClassArray, attributes: AttributeObject): Creates a new Elemental instance with the specified type, classes, and attributes.
  • update(classes: ClassArray, attributes: AttributeObject): Updates the element with new classes and attributes.
  • text(text: string): Sets the text content of the element.
  • innerHTML(html: string): Sets the inner HTML of the element.
  • replaceClasses(remove: ClassArray | string, add: ClassArray | string): Replaces certain classes with new ones.
  • setAttribute(key: string, value: string): Sets an attribute on the element.
  • on(event: string, func: () => void): Adds an event listener to the element.
  • off(event: string, func: () => void): Removes an event listener from the element.
  • init(func: (element: Elemental<T>) => void): Initializes the element with a custom function.
  • getElement(): Returns the underlying HTML element.
  • appendTo(parent: HTMLElement | Elemental<any>): Appends the element to a parent.
  • append(elementOrElements: Elemental<any> | Elemental<any>[]): Appends one or more Elemental instances as children.
  • remove(): Removes the element and its children from the DOM.
  • query(selector: string): Returns a collection of child elements that match the selector.
  • id(elementId: string): Sets the ID of the element.
  • ref(refObject: RefObject<T>): Associates the element with a reference object.
  • addRules(rules: Rule[]): Add methods to be invoked when the elements' classes change.
  • removeRules(rules: Rule[]): Removes CSS rules from the element.
  • getValue(): Gets the value of the element if it's an input or textarea.
  • setValue(value: string): Sets the value of the element if it's an input or textarea.

Examples

Take a look at the TODO app included in the repository for complete and concrete examples!

To create elements, you can use either the ElementalFactory class, or create them manually:

const app = ElementalFactory.DIV(['container']).append([
  ElementalFactory.H1(['title']).text('Elemental App'),
  ElementalFactory.P(['paragraph']).text('Hello World')
]);

app.appendTo(document.querySelector('#root'));

Contributions

Contributions to the Elemental Library are welcome. Please follow the project's contribution guidelines for submitting issues or pull requests.

License

Please refer to the project's license for usage rights and limitations.

elemental's People

Contributors

kingerez avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.