Skip to content
PatternslibPublic

About

Library for quickly applying rich interaction patterns without the need to write any JavaScript.

Topics

Resources

Contributing

Stars

107 stars

Watchers

16 watching

Forks

Latest commit

 

History

6,987 Commits

Folders and files

Repository files navigation

Patterns

Build Status

Patterns is a toolkit that enables designers to build rich interactive prototypes without the need for writing any JavaScript. All functionality is triggered by classes and other attributes in the HTML, without abusing the HTML as a programming language. Accessibility, SEO and well structured HTML are core values of Patterns.

Changelog

See the Changelog at GitHub.

Browser support

Patterns aims to support at least the two latest major versions of all popular browsers:

  • Apple Safari
  • Google Chrome
  • Firefox

Other browser version may work too, but are not actively tested against.

Development installation requirements

Make sure, you have these requirements installed:

We use pnpm as package manager. You don't need to install it globally - the Makefile runs it via npx pnpm.

Development installation

The following commands install all dependencies and build the bundle in the dist directory, which contains Patterns and all its dependencies:

git clone https://github.com/Patternslib/Patterns.git
cd Patterns
make

Alternatively, you can download a bundle at patternslib.com.

To start the development server, use make serve or npx yarn start and access the demo pages via http://localhost:3001/. The files are watched and the bundle re-built on changes. You can access the bundle directly at http://localhost:3001/bundle.min.js.

Makefile targets

The Makefile includes the shared Makefile from @patternslib/dev, which provides most of the targets. On a fresh checkout, run make install first - after that, all the shared targets are available.

User targets

Target Description
make, make all Build the bundle and the CSS.
make install Install the dependencies with pnpm and set up the commitlint commit-msg git hook.
make update Update pnpm and the dependencies on a new dependencies-update branch, creating separate commits for each step.
make clean-dist Remove the dist/ directory.
make clean Remove dist/, node_modules/ and the bundle analysis files stats.json and stats.html.
make lint, make eslint Lint the src/ directory with ESLint.
make format, make prettier Format all files with Prettier.
make check, make test Run ESLint, then the Jest tests.
make serve, make start Start the webpack development server on http://localhost:3001/.
make watch Build a development bundle and rebuild it on changes.
make bundle Unlink any linked dependencies, reinstall and build the production bundle in dist/.
make build Build the bundle and the CSS.
make css Compile _sass/_patterns.scss to style/patterns.css.
make depends-parser Regenerate the pat-depends expression parser from src/lib/depends_parse.pegjs.
make release-major Release a new major version and update the Patternslib.com website.
make release-minor Release a new minor version and update the Patternslib.com website.
make release-patch Release a new patch version and update the Patternslib.com website.
make prerelease-alpha Release a new alpha pre-release.
make prerelease-beta Release a new beta pre-release.

To create GitHub releases, add a GITHUB_TOKEN to a .env file. The Makefile reads .env automatically. See release-it GitHub releases and GitHub tokens.

For more details, see the @patternslib/dev README.

Layout

The individual patterns are located in their own folders in ./src/pat/.

Each pattern folder contains some or all of the following files:

  • index.html which contains HTML markup that shows a demonstration of the pattern.
  • documentation.md which is a Markdown file that documents the pattern's purpose, how to use it and how to configure it.
  • A javascript file which implements the pattern's functionality.
  • A Sass (.scss) file which provides the CSS associated with the pattern.

To compile the Sass files to style/patterns.css, run make css. The Sass compiler is installed with the development dependencies.

How to demo patterns

To demo the patterns, simply type make serve to install the necessary dependencies and to start a simple Node.js HTTP server.

You can then visit http://localhost:3001 to see a site with demos.

Alternatively, patterns can also be demoed through the Patternslib.com website, which is open-source. The code and setup instructions are here.

Contributing fixes

To develop on Patterns, clone the repository and set it's push-url to your fork:

git remote set-url --push origin <url_to_your_fork>

Create a branch for the feature/bug you are working on:

git checkout -b <feature>

For inclusion use either a GitHub pull request or create a ticket with a url to your external repository.

Please read our contribution notes and read our code style guide.

Running tests

The simplest way to run the tests are to use make:

make check

This will install all required packages, lint the code with ESLint and run the tests with Jest.

Debugging tests

Eventually add to tests:

import "core-js/stable";
import "regenerator-runtime/runtime";

Then:

node --inspect-brk node_modules/.bin/jest --runInBand ./src/pat/tooltip/tooltip.test.js

Connect in chrome via:

chrome://inspect

You can pass Jest any parameter it accepts, like -t TESTPATTERN::

node --inspect-brk node_modules/.bin/jest --runInBand ./src/pat/tooltip/tooltip.test.js -t will.be.closed.when

Enabling log messages

To facilitate debugging you can change the default log level through the URL query string by adding loglevel options.

  • http://www.example.com/?loglevel=DEBUG changes the default log level to DEBUG.
  • http://www.example.com/?loglevel-inject=DEBUG changes the log level for just the inject pattern to DEBUG.
  • http://www.example.com/?loglevel=ERROR&loglevel-inject=INFO changes the standard log level error, but enables messages at the INFO level for the inject pattern.

Patternslib global variables

There are some global variables that are available and can be used to make global settings or access otherwise hidden objects.

Global variable Purpose Default
window.__patternslib_import_styles Whether to import pattern-specific styles false
window.__patternslib_patterns_blacklist A list of patterns that should not be loaded. []
window.__patternslib_registry Global access to the Patternslib registry object. -
window.__patternslib_registry_initialized True, if the registry has been initialized. false
window.__patternslib_registry_initializing True, while the registry waits for Module Federation remotes before the initial scan. undefined
window.__patternslib_mf_initialized Promise provided by the Module Federation helper of @patternslib/dev, resolved once all remote bundles are initialized. The registry waits for it before the initial scan. undefined
window.__patternslib_mf_init_timeout Maximum time in milliseconds the registry waits for Module Federation remotes before scanning anyway. 5000

Bundle analysis

These targets build the production bundle with webpack and analyze the resulting stats.json. stats.json is rebuilt when pnpm-lock.yaml changes. To force a rebuild, remove it or run make clean.

Target Description
make analyze-bundle-dependencies Show why each package was included in the bundle, using whybundled.
make analyze-bundle-treemap Show the bundle as treemap, using webpack-bundle-analyzer.
make analyze-bundle-sunburst Render the bundle as sunburst chart into stats.html and open it in the browser, using webpack-visualizer.

To open stats.html with a specific browser, pass the OPEN variable, e.g. make analyze-bundle-sunburst OPEN=firefox.

Organisations and projects which use Patternslib

  • Overstroom ik?, a website which informs Dutch citizens of their risk of flooding. It was introduced and highly praised by the Dutch minister of infrastructure and environment, Melanie Schultz.
  • OiRA, an online risk assessment tool, created for the Occupational Health and Safety Agency (OSHA) of the European Union.
  • Staralliance uses Patternslib in their intranet.
  • Plone CMS via Mockup, which is built upon Patternslib.
  • Quaive Intranet uses Patternslib.

Interactive HTML/CSS prototypes made with Patternslib

  • The Patternslib.com website uses Patternslib and is based upon a prototype, which can be found here.

About

Library for quickly applying rich interaction patterns without the need to write any JavaScript.

Topics

Resources

Contributing

Stars

107 stars

Watchers

16 watching

Forks

Releases

Packages

Used by

Contributors

Languages