Mosaic
Mosaic is a declarative front-end JavaScript library for building user interfaces!
const name = "Mosaic";
html`<h1>Welcome to ${name}!</h1>`
Demo
Here is an example of a simple Mosaic application. All you need is an index.html file and an index.js file. For a more detailed example, run the project inside the "example" folder.
index.html:
<html>
<head>
<title>My Mosaic App</title>
</head>
<div id='root'></div>
<script src='https://unpkg.com/mosaic-framework@latest/dist/index.js'></script>
<script type="text/javascript" src='./index.js'></script>
</html>
index.js:
// Import Mosaic
import Mosaic, { html } from 'mosaic-framework';
// Create components
Mosaic({
name: 'my-label',
data: {
text: ''
},
view: self => {
return html`
<h2>${ self.data.text }</h2>
<p>This is a custom label component!</p>
${self.descendants}
`;
}
});
const app = Mosaic({
name: 'my-app',
element: 'root',
data: {
title: "Mosaic App"
},
sayHello: function() {
console.log("Hello World!!");
console.log("This component is ", this);
},
view: function() {
return html`
<h1>This is a ${this.data.title}!</h1>
<p>Click below to print a message!</p>
<button onclick="${this.sayHello}">Click Me!</button>
<my-label text='Welcome to Mosaic!'>
Awesome, right?
</my-label>
`;
}
});
// Paint the Mosaic onto the page.
app.paint();
Installation
The easiest way to use Mosaic is to first install the npm package by using:
npm install --save mosaic-framework
yarn add mosaic-framework --save
or with a script tag.
<script src='https://unpkg.com/mosaic-framework@latest/dist/index.js'></script>
(Optional) For fast builds and hot reloading, install the build tool "Parcel." This is not required, though, as Mosaic uses built-in JavaScript features. This means that no build tool is required, but any may be used if it helps the overall project structure.
npm install --save-dev parcel-bundler
Now you are ready to use Mosaic!
Author
- Year: 2019
- Programmer: Adeola Uthman
- Languages/Tools: JavaScript, TypeScript, Parcel