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

@ignota/susy.js

v0.2.0

Published

JavaScript power tools for web layout.

Downloads

39

Readme

@ignota/susy.js: JavaScript power tools for web layout.

Build Status

Susy.js is a JavaScript port of the powerful Susy layout toolkit for Sass. It makes the power and flexibility of Susy's venerable grid primitives available to your favorite CSS-in-JS solution---anything from Styled Components to inline React styles---so that you can build your own damn grids with your own damn tools.

Resources

Installation

yarn add @ignota/susy.js

Usage

import {
    at,
    configure,
    first,
    gutter,
    slice,
    span,
} from '@ignota/susy.js'

configure({
    columns: [1, 2, 1, 1, 3, 1, 3, 2, 1, 4],
    gutters: 0.5,
})

console.log(span(first(3), of(slice(6, at(3))))) // 44.44444444444444%
console.log(gutter(slice(6, at(3))))             // 3.7037037037037033%

Settings

The package exposes a function called configure that takes an object as its only argument. You can customize your default grid by setting the following keys:

  • columns. A list of columns, either unitless numbers (e.g., [1, 3, 5]), strings with CSS lengths (e.g., ['1em', '3em', '5em']), or a mix of both (e.g., [1, '3em', 5]). You may import the function repeat to quickly create symmetrical grids: e.g., repeat(10), repeat(10, '1em'), or ['120px', repeat(4), '120px'].
  • gutters. A unitless fraction as a number (e.g., 0.5) or an explicit width as a string (e.g., '1em').
  • spread and containerSpread. A string, either narrow, wide, or wider, that defines how grid elements and grid containers handle gutters. See the Oddbird blog for more details.

These configuration options may also be passed into the core Susy functions as their final argument.

Susy Functions

The core Susy API is exposed as three functions, gutter, slice, and span, which map to the Sass functions susy-gutter, susy-slice, and susy-span. These can be imported as named imports directly from the package root. All three accept a variadic argument list, which should start with a list of shorthand functions and may optionally end with an object containing settings to be applied to the current calculation.

An additional helper function, halfGutter, is also exposed; it returns half the width of a single gutter, handling the ugly conversion from a string to a number and back.

Shorthand

Susy's Sass implementation turns on a very friendly shorthand for defining grid spans and context:

$col-width: su-span(3 at 2);

Susy.js does its level best to preserve the friendliness of the API through a set of shorthand functions:

  • all
  • alpha(count)
  • at(location)
  • first(count)
  • last(count)
  • narrow
  • of(...shorthand)
  • omega(count)
  • setGutters(gutters)
  • wide
  • wider

Shorthand may also include bare numbers or arrays, which will be treated as column counts.

Examples

span(2)
span(2, of(6))
span(6, at(3))
span(first(3), of(slice(6, at(3))))
gutter()
gutter(6)
gutter(wider)
gutter(slice(6, at(3)))

Familiarity with the Sass syntax is highly recommended, and will make picking up the JavaScript version a more-or-less breeze.

SVG Grid Plugin

Susy.js also implement's Susy's SVG grid plugin:

import {
    svgGrid,
    wider,
} from '@ignota/susy.js'

<div style={{
    backgroundAttachment: 'scroll',
    backgroundImage: svgGrid(6, wider),
    backgroundRepeat: 'no-repeat',
}}>
    I'm a grid container!
</div>
<div style="background-attachment:scroll;background-image:url("data:image/svg+xml,<svg fill='url(%23susyjs-svg-gradient)' width='100%' xmlns='http://www.w3.org/2000/svg'><defs><linearGradient id='susyjs-svg-gradient' spreadMethod='pad' x1='0%' x2='100%' y1='0%' y2='0%'><stop offset='0%' style='stop-color:hsla(120, 50%, 50%, 0.5);' /><stop offset='100%' style='stop-color:hsla(120, 50%, 75%, 0.5);' /></linearGradient></defs><rect height='100%' width='12.903225806451612%' x='3.225806451612903%' /><rect height='100%' width='12.903225806451612%' x='19.35483870967742%' /><rect height='100%' width='12.903225806451612%' x='35.483870967741936%' /><rect height='100%' width='12.903225806451612%' x='51.612903225806456%' /><rect height='100%' width='12.903225806451612%' x='67.74193548387096%' /><rect height='100%' width='12.903225806451612%' x='83.87096774193547%' /></svg>");background-repeat:no-repeat;">
    I'm a grid container!
</div>

The function svgGrid accepts the same shorthand as the other Susy.js functions and returns the CSS data URL of an SVG illustration visualizing your grid's columns. There are two additional shorthand functions attached to svgGrid:

  • svgGrid.colors. Accepts either a single CSS color string (#9CC) for solid-colored columns or an array of same to construct a gradient. Defaults to ['hsla(120, 50%, 50%, 0.5)', 'hsla(120, 50%, 75%, 0.5)'].
  • svgGrid.offset. Pass in a CSS length to manually configure the default image offset so as to allow for grid edges.

Pass these in with the other shorthand functions to reconfigure the visual grid.