@parallelogram-js/core 0.7.19

Progressive enhancement, one component at a time

Parallelogram adds behaviour to server-rendered HTML through data attributes and a small set of web components. Each component loads the first time a page uses it, and, if you want it, links can swap the page in place instead of reloading it.

Install

npm install @parallelogram-js/core

Start the framework

Register the components your pages use, and the framework loads each one the first time a page contains it.

import { Parallelogram } from '@parallelogram-js/core';

const app = Parallelogram.create({
  pageManager: { containerSelector: '[data-view="main"]' },
});

app.components
  .add('p-modal', () => import('@parallelogram-js/core/components/PModal'))
  .add('[data-toggle]', () => import('@parallelogram-js/core/components/Toggle'));

app.run();

The router is optional, and off unless you ask for it. Add router: {} and links swap the element marked data-view="main" in place instead of reloading the page, with the components inside it mounting and unmounting as it changes. Leave it out and every link is an ordinary link.

Enhancement components that need styles use the package stylesheet, @import '@parallelogram-js/core/styles';, or one file per component.

Components

An enhancement is behaviour added to markup you already have, through a data attribute: the element works without it and does more with it. A web component is an element of its own, which the browser upgrades when its module arrives. Each page below says which it is, and what its markup does before the module loads.

About these pages

Each component page is generated from the contract that sits beside the component's source, and a test checks every contract against the code. The examples are live: change their attributes, watch the events they send and copy the markup. This site runs on Parallelogram too, so following a link here uses the framework's own router.