npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

brique

v1.0.13

Published

Create cascading layout grids like Pinterest with the power of CSS Grid Layout.

Downloads

16

Readme

Brique.js

Create cascading layout grids like Pinterest with the power of CSS Grid Layout.

Documentation

Getting Started

  1. Install
  2. Instantiate
  3. HTML markup example
  4. Parameters
  5. Properties
  6. Methods
  7. Responsive grid

Install

$ npm i brique --save

Instantiate

TypeScript

import { Brique } from './node_modules/brique/lib';

const refGrid = document.getElementById('grid');
new Brique(refGrid);

JavaScript ES6

HTML script tag requires the type="module" attribute.

<script type="module" src="scripts/main.js"></script>

Create the grid in the JavaScript file (scripts/main.js) and import the esm version of the library (index.esm.js).

import { Brique } from './node_modules/brique/lib/index.esm.js';

const refGrid = document.getElementById('grid');
new Brique(refGrid);

HTML markup example

<div id="grid">
    <div>
        <h2>Box 1</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </div>
    <div>
        <h2>Box 2</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut laboret.</p>
    </div>
    <div>
        <h2>Box 3</h2>
    </div>
    <div>
        <h2>Box 4</h2>
        <p>Lorem ipsum dolor sit amet.</p>
    </div>
    <div>
        <h2>Box 5</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.</p>
    </div>
</div>

Parameters

3 parameters can be passed to the Brique class.

new Brique(gridElement, options, observeGridResize);

gridElement: HTMLElement

Target HTML element which is the container for grid items.

options: BriqueOptions (Optional)

| Property | Type | Required | Description | | --- | --- | --- | --- | | columns | number | true | Number of columns | | columnGap | string | false | Spacing between columns | | rowGap | string | false | Spacing between row |

Example

const refGrid = document.getElementById('grid');
const options = {
    columns: 4,
    rowGap: '24px',
    columnGap: '16px',
};

new Brique(refGrid, options);

observeGridResize: boolean (Optional)

The default value for this parameter is true.

If the value is true, the grid items will be updated when the viewport is resized.

If the value is false, the grid will never be updated when the viewport is resized.

Properties

Default options

Static property which returns the options defined by default in the Brique class.

Brique.DEFAULT_OPTIONS;

itemElements: HTMLElement[]

Reference array of HTML elements of all grid items.

Methods

update()

Update the rendering of the entire grid on demand.

briqueGrid.update();

updateItems()

Update the rendering of the grid items on demand.

briqueGrid.updateItems();

updateOnResize()

Update the dimension of grid items when the grid element is resized.

const refGrid = document.getElementById('grid');
const briqueGrid = new Brique(refGrid);

briqueGrid.updateOnResize();

stopUpdateOnResize()

Stop update the dimension of grid items when the grid element is resized.

briqueGrid.stopUpdateOnResize();

getOptions(): BriqueOptions

Return current options object.

briqueGrid.getOptions(); // output: { columns: 3, rowGap: '32px', columnGap: '32px'}

setOptions(options)

Change all properties of options object.

briqueGrid.setOptions({
    columns: 5
});

updateOptions(updatedOptions)

Updates only changed properties.

briqueGrid.updateOptions({
    columns: 5
});

Can be used to create a responsive grid.

destroy()

Removes all events listened to on the HTML elements handled by the Brique class.

The destroy() method must be called when the grid is removed from HTML.

Responsive grid

Update options object on media queries change.

const refGrid = document.getElementById('grid');
const mediaQueryMobile = window.matchMedia('(max-width: 767px)');

const getColumnsNumber = () => mediaQueryMobile.matches ? 2 : 3;

const briqueGrid = new Brique(refGrid, {
    columns: getColumnsNumber(),
    columnGap: '32px',
    rowGap: '32px',
});

mediaQueryMobile.addEventListener('change', () => {
    briqueGrid.updateOptions({
        columns: getColumnsNumber(),
    });
});