materialhx

Extern interface, element builder, and wrapper library for Material Design Components (Web).
https://github.com/chfoo/materialhx/

To install, run:

haxelib install materialhx 0.35000.0 

See using Haxelib in Haxelib documentation for more information.

README.md

materialhx

materialhx is a extern interface, element builder, and wrapper library for Material Design Components (Web) for the Haxe programming language.

Quick Start

Install the library using:

    haxelib install materialhx

Include vanilla MDC styles and scripts into your HTML page:

<link href="/api/public/p/aHR0cHM6Ly91bnBrZy5jb20vbWF0ZXJpYWwtY29tcG9uZW50cy13ZWJAMC4zNS4xL2Rpc3QvbWF0ZXJpYWwtY29tcG9uZW50cy13ZWIuY3Nz" rel="stylesheet">
<link href="/api/public/p/aHR0cHM6Ly9mb250cy5nb29nbGVhcGlzLmNvbS9pY29uP2ZhbWlseT1NYXRlcmlhbCtJY29ucw" rel="stylesheet">
<script async src="/api/public/p/aHR0cHM6Ly91bnBrZy5jb20vbWF0ZXJpYWwtY29tcG9uZW50cy13ZWJAMC4zNS4xL2Rpc3QvbWF0ZXJpYWwtY29tcG9uZW50cy13ZWIuanM" type="text/javascript"></script>

Then include your Haxe JS output:

<script defer src="/api/public/p/aHR0cHM6Ly9saWIuaGF4ZS5vcmcvcC9teV9wcm9ncmFtLmpz" type="text/javascript"></script>

In your entry point, wait for MDC to load and then execute your code. For example:

if (Browser.document.readyState == "complete") {
    doThings();
} else {
    Browser.document.addEventListener("readystatechange", doThings);
}

Using the extern interfaces

You can initialize components using existing HTML elements with the extern interfaces. They are are located in the materialhx.mdc package.

This example adds a ripple to a button element:

import materialhx.mdc.ripple.MDCRipple;

// [...]

var button = Browser.document.createElement("button");
MDCRipple.attachTo(button);

HTML element builders and CSS class names

To help build and style elements programmatically, element builders are located in materialhx.html and style class names in materialhx.css.

This example shows building a button and styling it:

import materialhx.css.ButtonStyle.ButtonModifier;
import materialhx.html.ButtonBuilder;

// [...]

var button = ButtonBuilder.button();
button.classList.add(ButtonModifier.Raised);

Component wrapper widgets

The library also provides wrappers for the HTML elements and components called widgets. Widgets are tied to hierarchy of the DOM tree and represent units in a user interface. They are found in the materialhx.widget package.

This example creates a dialog, shows it, waits for a response, and cleans up the dialog:

import materialhx.mdc.dialog.MDCDialog;
import materialhx.widget.ContainerWidget;
import materialhx.widget.Dialog;

// [...]

var root = new ContainerWidget(Browser.document.body);
var dialog = new Dialog();

root.push(dialog);

dialog.setText("Discard draft?", "The draft will be deleted.");
dialog.setButtonText("Discard");

dialog.element.addEventListener(MDCDialogEvent.Accept, function () {
    storage.deleteDraft();
    dialog.dispose();
    root.remove(dialog);
});

dialog.show();

Learning more

To see more example usage, see the demo project in test/materialhx/Demo.hx. The demo can be built using haxe demo.hxml.

Widget interoperability with other frameworks

All the widgets in this library subclass from a generic Widget class. The Widget implements IWidgetNode which closely resembles a Haxe array interface to the DOM.

For widgets in this library to accept external widgets, external widgets need to implement IWidget which only requires a HTML element to be exposed.

Other icons, besides Material icons, can be used by implementing IIcon.

Contributors
chfoo
Version
0.35000.0
Published
8 years ago
License
Apache

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂