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

set-line

v1.0.1

Published

Responsive line-height for the perfect vertical rhythm

Downloads

1

Readme

:memo: :fire: Responsive line-height for the perfect vertical rhythm

Live test: https://vnurich.github.io/set-line/

set-line is a config file reader (SASS-map) for clean and responsive vertical rhythm, focusing on root font-size and line-height for each necessary breakpoint. The element's alignment calculated by padding-top and margin-bottom properties. And the only value that will have to be considered manually is the cap-height which is the proportion number (~0.5-0.9) of the font-size.

An element can contain the following parameters

  • $line-height (important) - REMs (e.g. 2rem);
  • $font-size (important) - REMs (e.g. 2.4rem);
  • $cap-height (important) - the proporion of the font-size (e.g. 0.68), must be considered manually;
  • $space-top - default 0, the number of 'lines' above the element ('line' is equal to the current root line-height);
  • $space-bottom - same as $space-top, but below the element;
  • $font-weight - CSS standart font-weight parameter (e.g. normal, bold, lighter, bolder,inherit, 100, 200, 300, 400, 500, 600, 700, 800, 900);
  • $font-style - CSS standart font-style parameter (e.g. normal, italic, inherit);
  • $text-align - CSS standart text-align parameter (e.g. left, center, right, inherit);
  • $font-family - CSS standart list. Notice: must be prepared as a sass-map variable, for example: $font-family-serif: ('Merriweather', 'Times New Roman', 'serif').

Usage

Suppose that we have already imported set-line.scss and prepared the config-file.scss. Now all you need is just to set mixins like that:

html { @include set-line('root'); }
p { @include set-line('p'); }
h1 { @include set-line('h1'); }
.my-element { @include set-line('my-element'); }
/// etc...

That's it! For example your compiled css stylesheet with p element may look like this:

p { margin: 0; padding: 0; font-size: 1.4rem; line-height: 2rem; padding-top: 0.4rem; margin-bottom: 1.6rem; }

@media (min-width: 36em) { p { font-size: 1.6rem; line-height: 2.2rem; padding-top: 0.44rem; margin-bottom: 1.76rem; text-align: left; } }

@media (min-width: 48em) { p { font-size: 1.8rem; line-height: 2.8rem; padding-top: 0.728rem; margin-bottom: 2.072rem; } }

And you get your perfect vertical rhythm for each neccesary breakpoint!

Also we have two helpers which uses the config file data.

Function get-value() gets any value from the config file:

get-value('property-name', $for: 'element-name', $on: 'breakpoint-name');
/// for example
$my-var-one: get-value('line-height', $for: 'root', $on: 'tablet');
$my-var-two: get-value('font-size', $for: 'h1', $on: 'desktop');

Mixin set-breakpoint() creates @media(min-width: [val]) { [content] } wrapper:

@include set-breakpoint-for('tablet') { /*content*/ } // value taken from the config file
@include set-breakpoint-for(120rem) { /*content*/ } // value set manually. Can be rem/em/px

Getting started

Install and import lib

npm install set-line
@import 'set-line'; // import main lib
@import 'path/to/config'; // import main config file

$set-line-config: $my-set-line-config; // sass var name from your config file 
$set-line-default: 'my-mobile-first-breakpoint'; // root (default/mobile-first) device name from your config file

Prepare config file

First import fonts you need:

@import url('https://fonts.googleapis.com/css?family=Merriweather+Sans:300,300i,400,400i,700,700i,800,800i');

Set any font-family vars you want:

$font-family-serif: ('Merriweather', 'Times New Roman', 'serif');
$font-family-monospace: ('Courier', 'monospace');
/// etc...

Create base variable for your config:

$my-set-line-config: ();

And fill it with your settings. 'root' element containing 'font-size', 'breakpoint' and 'line-height' is important for each breakpoint. Here is an example:

$my-set-line-config: (
  'my-mobile-first-breakpoint': (
    'root': (
      'font-size': 62.5%,
      'breakpoint': 30em,
      'line-height': 2rem
    ),
    'p': (
      'font-size': 1.4rem,
      'cap-height': 0.8,
      'space-top': 0,
      'space-bottom': 1,
      'font-weight': 300,
      'font-style': normal,
      'text-align': justify,
      'font-family': $font-family-serif
    ),
    'my-element': (
      'font-size': 2rem,
      'cap-height': 0.64
    )
  ),
  'my-second-breakpoint': (
    'root': (
      'font-size': 62.5%,
      'breakpoint': 48em,
      'line-height': 2.8rem
    ),
    'p': (
      'font-size': 1.8rem,
      'cap-height': 0.74,
      'space-top': 0,
      'space-bottom': 1,
      'font-weight': 400,
      'font-style': normal,
      'text-align': left,
      'font-family': $font-family-serif
    ),
    'my-element': (
      'font-size': 2.8rem,
      'cap-height': 0.66
    )
  ),
  /// and so on...
);

Dev environment

Clone or download this repo:

git clone https://github.com/vnurich/set-line.git

Install dependencies:

npm install

Run local server (http://localhost:3000)

npm run dev

License

This project is licensed under the MIT License