Skip to content

defx/mosaic

Repository files navigation

Mosaic

Accelerate your UI development

🚧 Please kindly note that this project is a work in progress. 🚧

Mosaic allows authors to write once and run anywhere

Mosaic enables UI behaviour to be described using a combination of functional programming and declarative configuration, separating behaviour from presentation to ensure maximum reusability.

Mosaic enables teams to focus on UI presentation

Get a head start on UI development by leveraging UI behaviour that is highly performant, accessible, and fully tested straight out of the box, letting you focus on your project presentation.

npm gzip size

Example

The following configuration implements the Accordion pattern:

let counter = 0;

export const Accordion = () => {
  const id = counter++;
  return {
    state: {
      openPanel: 0,
    },
    actions: {
      togglePanel: (state, i) => ({
        ...state,
        openPanel: state.openPanel === i ? -1 : i,
      }),
    },
    elements: [
      {
        selectAll: "button[accordion-toggle]",
        attribute: (state, i) => ({
          id: `trigger_${id}_${i}`,
          ariaControls: `panel_${id}_${i}`,
          ariaExpanded: state.openPanel === i,
        }),
        on: {
          click: "togglePanel",
        },
      },
      {
        selectAll: "[accordion-panel]",
        attribute: (state, i) => ({
          id: `panel_${id}_${i}`,
          ariaLabelledby: `trigger_${id}_${i}`,
          hidden: state.openPanel !== i,
          role: "region",
        }),
      },
    ],
  };
};

Install

cdn

import { define } from "https://unpkg.com/mosaic";

npm

> npm i mosaic

About

Accelerate your UI development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published