0.0.1 • Published 6 years ago

neutrine-utils v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

neutrine-utils

Utility components and hepers for React.

npm npm npm pr

NOTE: this package is on development.

Installation

Use npm to install this package:

$ npm install --save neutrine-utils

API

classNames(...values)

A small utility to join classNames. The classNames function takes any number of arguments, that should be a string or an array of strings. Other values will be ignored.

import {classNames} from "neutrine-utils";

classNames("foo", "bar"); // --> "foo bar"
classNames(["foo", "bar"]); // --> "foo bar"
classNames(["foo"], ["bar", null]); // --> "foo bar"
classNames("foo", null, "bar"); // --> "foo bar"

hyperscript(component, props, ..children)

A parser for React.createElement. Returns a React element.

  • component: a React component or a HTML tag string.
  • props: an object with the properties of the element.
  • children: a string, a React element or an array of React elements or strings.
import React from "react";
import {hyperscript as h} from "neutrine-utils";

export default class Example extends React.Component {
    render() {
        let children = [
            h("div", {}, "Div element"),
            h("span", {className: "text-red"}, "Red text"),
            h("div", {className: "h1"}, "Heading 1")
        ];
        return h("div", {id: "example"}, children);
    }
}

ready(fn)

Executes the provided function fn when the DOM becomes ready. This utility is similar to jQuery's ready method.

import {ready} from "neutrine-utils";

//Execute this function when the DOM is ready
ready(function () {
    console.log("DOM is ready");
});

License

Released under the MIT LICENSE.

0.0.1

6 years ago