Skip to content

Getting started

These are dependency-free UI components written in TypeScript and compiled to ES5, targeting browsers back to IE10. Each component ships as its own file, so load only what you use.

The classes are the same either way: Modal in a module, ML.Modal on a page that loads a script.

The package ships ES modules (still ES5 syntax) and TypeScript declarations:

import { Modal } from '@mikewgd/myjs';
const modals = new Modal();
modals.init();

The helper functions the components are built from are exported too (see Helpers).

Every component and utility is a classic script that defines a global, ML. No bundler needed.

<link rel="stylesheet" href="css/modal.css">
<script src="js/modal.js"></script>
<script>
var modals = new ML.Modal();
modals.init();
</script>
  • js/<name>.js / .min.js contains one component or utility.
  • js/ml.js / .min.js contains all of them, and css/myjs.css the styles of every component.
  • Several single-component scripts can be loaded on the same page; they share one ML.
  • ML holds the classes, and nothing else. The helper functions are in the module build only.

The CSS only provides structure (positioning, show/hide). Colors, borders and spacing are up to your page, so each demo here is styled by this site.

A component has markup or CSS: a Modal, a Dropdown. A utility is behavior only: Ajax, Animate, Breakpoints. Both are classes with the same shape: settings in the constructor, init() to start, destroy() to stop.

Targets IE10 and newer. The output is ES5.