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

type-presets

v0.2.8

Published

Tools for using type presets in CSS

Downloads

120

Readme

type-presets

CircleCI

Intention

Using typography throughout a complicated app gets complicated fast. I choose to trust the experts.

Having worked on several projects with the talented people at SuperFriendly, I've fully adopted their approach to typography, with some adaptations and tooling to make it easier.

The article linked above does a better job explaining everything than I could ever do, so I'll simply say that every project I've worked on benefits from creating an intentionally limited and explicit set of type presets which are the only way to assign typographical rules.

There are two concepts:

  1. typescales, which are explicit responsive rules that encapsulate font-size and line-height (the vertical space consumed by text)
  2. type presets, which are explicit combinations of a typescale, font-family, font-weight, text-transform, and letter-spacing to create a conceptual preset

The goal is to provide this set of tools in a variety of languages and use-cases such that it encourages the ecosystem on the whole to adopt. Check out examples below.

Installation

npm install type-presets

Usage

SCSS

Example

@use 'type-presets' as t with (
	$default-family: 'Arial, sans-serif',
	$typescales: (
		1: 12px (md: 14px, xl: 16px),
		2: 14px (lg: 20px),
	),
	$presets: (
		1: (scale: 1, spacing: .5),
		2: (scale: 1, family: 'Comic Sans', transform: uppercase),
		3: (scale: 2, family: 'Comic Sans', weight: 800),
	)
);

@include t.utility-classes($namespace: 'co');

h1, h2, h3 {
	@include t.type-preset(1);
}

p {
	@include t.type-preset(3);
}

.btn-primary {
	@include t.type-preset(2);
}

Which generates responsive media queries for scales, utility definitions for typescales and presets, and assign presets to a few components:

@media screen and (min-width: 0) {
	:root {
		--typescale-1-font-size: 12px;
		--typescale-1-line-height: 20px;
		--typescale-2-font-size: 14px;
		--typescale-2-line-height: 22px;
	}
}
@media screen and (min-width: 600px) {
	:root {
		--typescale-1-font-size: 12px;
		--typescale-1-line-height: 20px;
		--typescale-2-font-size: 14px;
		--typescale-2-line-height: 22px;
	}
}
@media screen and (min-width: 900px) {
	:root {
		--typescale-1-font-size: 14px;
		--typescale-1-line-height: 22px;
		--typescale-2-font-size: 14px;
		--typescale-2-line-height: 22px;
	}
}
@media screen and (min-width: 1200px) {
	:root {
		--typescale-1-font-size: 14px;
		--typescale-1-line-height: 22px;
		--typescale-2-font-size: 20px;
		--typescale-2-line-height: 28px;
	}
}
@media screen and (min-width: 1800px) {
	:root {
		--typescale-1-font-size: 16px;
		--typescale-1-line-height: 24px;
		--typescale-2-font-size: 20px;
		--typescale-2-line-height: 28px;
	}
}

.test-u-typescale-1 {
	font-size: var(--typescale-1-font-size) !important;
	line-height: var(--typescale-1-line-height) !important;
}

.test-u-typescale-2 {
	font-size: var(--typescale-2-font-size) !important;
	line-height: var(--typescale-2-line-height) !important;
}

.test-u-type-preset-1 {
	font-size: var(--typescale-1-font-size) !important;
	line-height: var(--typescale-1-line-height) !important;
	font-family: "Arial, sans-serif" !important;
	font-weight: normal !important;
	text-transform: none !important;
	letter-spacing: 0.5 !important;
}

.test-u-type-preset-2 {
	font-size: var(--typescale-1-font-size) !important;
	line-height: var(--typescale-1-line-height) !important;
	font-family: "Comic Sans" !important;
	font-weight: normal !important;
	text-transform: uppercase !important;
	letter-spacing: normal !important;
}

.test-u-type-preset-3 {
	font-size: var(--typescale-2-font-size) !important;
	line-height: var(--typescale-2-line-height) !important;
	font-family: "Comic Sans" !important;
	font-weight: 800 !important;
	text-transform: none !important;
	letter-spacing: normal !important;
}

h1, h2, h3 {
	font-size: var(--typescale-1-font-size);
	line-height: var(--typescale-1-line-height);
	font-family: "Arial, sans-serif";
	font-weight: normal;
	text-transform: none;
	letter-spacing: 0.5;
}

p {
	font-size: var(--typescale-2-font-size);
	line-height: var(--typescale-2-line-height);
	font-family: "Comic Sans";
	font-weight: 800;
	text-transform: none;
	letter-spacing: normal;
}

.btn-primary {
	font-size: var(--typescale-1-font-size) !important;
	line-height: var(--typescale-1-line-height) !important;
	font-family: "Comic Sans" !important;
	font-weight: normal !important;
	text-transform: uppercase !important;
	letter-spacing: normal !important;
}

API

All configuration is exposed via Sass module configuration - a full example is detailed below:

@use 'type-presets' with (
	$default-family: 'Arial, sans-serif',
	$default-weight: 500,
	$default-transform: uppercase,
	$default-spacing: 1.5,
	$line-height-scale: 10,

	$breakpoints: (
		small: 400px,
		med: 600px,
		largo: 1000px,
		extralargo: 2000px,
	),

	$typescales: (
		1: 12px (med: 14px, extralargo: (16px 32px)),
		2: (14px 18px) (largo: 20px),
	),
	$presets: (
		1: (scale: 1, spacing: .5),
		2: (scale: 1, family: 'Comic Sans', transform: uppercase),
		3: (scale: 2, family: 'Comic Sans', weight: 800),
	),
);