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

fo-mason

v1.0.0

Published

fo-mason is a css-grid based masonry layout tool built with sass. No javascript required!

Downloads

4

Readme

fo-mason

fo-mason is a css-grid based masonry layout tool built with sass. No javascript required!

In the future css will have native masonry support. you can read more about that here.

However this package works in browsers right now without additional javascript.

Why?

To have fun and flex my understanding of css-grid, obviously.

The Method

I think this picture explains how it works nicely.

2021-08-14_21-35

We create columns and rows and define the size of the rows as 1/3 of the columns. We let each brick span 3 to 6 rows and you have a fo-masonry layout.

This is some simplified sass to give you the gist of what is under the hood.

$brick: 20rem
$cuts: 3

.mason
    --cuts: #{$cuts}
    --brick-span: 0
    
    display: grid    
    justify-content: center
    grid-auto-flow: row dense

.mason-vertical
    grid-template-columns: repeat(auto-fill, #{$brick})
    grid-auto-rows: $brick / $cuts

.mason-auto > *:nth-child(2n)
    --brick-span: 2
.mason-auto > *:nth-child(3n)
    --brick-span: 1

.mason-vertical > *
    grid-row-end: span calc(var(--brick-span) + var(--cuts))

Limitations

The size of each brick is adjustable but somewhat ridged. The brick size must be a multiple of the row size. And bricks don't dynamically expand with their content.

Usage

After installing just drop in a .mason class and pick either .mason-horizontal or .mason-vertical then add a .mason-auto class.

<div class="mason mason-vertical mason-auto">
  <div class="brick">...</div>
  <div class="brick">...</div>
  <div class="brick">...</div>
  ...
</div>  

You can define the brick-size manually with a brick-size attribute. The default setting of 0 defines a 1x1 square brick, 3 makes the brick slightly larger then a 1x2 rectangle. The brick-size can also take negative values.

<div class="mason mason-horizontal">
  <div brick-size="0">...</div>
  <div brick-size="-2">...</div>
  <div brick-size="3">...</div>
  <div brick-size="1">...</div>
  ...
</div>  

Installation & Configuration

npm

npm install fo-mason

After installing it you can adjust the configuration like so:

@use 'path/to/node_modules/fo-mason' with (
    $gap: 1em,
    $brick: 16em,
    $cuts: 2,
    $auto: (
        '3n-1': 1,
        '4n': 2,
        '5n+1': 3
    )
);

Experimenting

You can experiment by cloning the repo and hosting the demo/ folder with something like live-server.

Use npm run demo to apply your changes to the styling in the demo.

This tool was built with some of the newer sass features available in DartSass. If your using LibSass then you will need to make some adjustments or install a DartSass package. Unfortunately as of writing this, the live sass compiler available in vscode uses LibSass. Jekyll and Rails also currently uses LibSass.