• Stars
    star
    3,817
  • Rank 11,198 (Top 0.3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A powerful toolkit for building websites with beautiful design

Typography.js Build Status Coverage Status

A powerful toolkit for building websites with beautiful design.

Install

npm install typography

Demo/playground

https://kyleamathews.github.io/typography.js

Why

The goal of Typography.js is to provide a high-level elegant API for expressing typographic design intent.

Typography is a complex system of interrelated styles. 100s of style declarations on dozens of elements must be in harmonious order. Trying one design change can mean making dozens of tedious recalculations and CSS value changes. Creating new Typography themes with CSS feels hard.

Typography.js provides a vastly simpler way to define and explore typography designs.

You provide configuration to the Typography.js JS api and it uses its Typography engine to generate CSS for block and inline elements.

Typography.js makes it easy to create designs that are unique, personal, and custom to your project.

Themes & Plugins

  • themes: Typography.js themes are simple Javascript objects. As such they're easy to share across projects or even open source and share via NPM.
  • plugins: Plugins are functions that extend or modify the core Typography engine. They can change how headers are styled or add specialized styles e.g. for code or tables.

Sites that use Typography.js

Javascript usage

import Typography from 'typography'

const typography = new Typography({
  baseFontSize: '18px',
  baseLineHeight: 1.45,
  headerFontFamily: ['Avenir Next', 'Helvetica Neue', 'Segoe UI', 'Helvetica', 'Arial', 'sans-serif'],
  bodyFontFamily: ['Georgia', 'serif'],
  // See below for the full list of options.
})

// Output CSS as string.
typography.toString()

// Or insert styles directly into the <head> (works well for client-only
// JS web apps.)
typography.injectStyles()

Themes

We maintain 30 (and counting) themes that are ready to use on your next project. These are each published as separate NPM packages. Explore themes at http://kyleamathews.github.io/typography.js.

Using themes

Here's an example of how to use the Funston theme.

  1. First save the package to your project npm install --save typography-theme-funston
  2. Then import and pass into Typography when initializing.
import Typography from 'typography'
import funstonTheme from 'typography-theme-funston'

const typography = new Typography(funstonTheme)

Customizing themes

Themes are just javascript objects so it's easy to modify them as needed. For example, if you're using the Funston theme but want to increase the base font size slightly:

import Typography from 'typography'
import funstonTheme from 'typography-theme-funston'
funstonTheme.baseFontSize = '22px' // was 20px.

const typography = new Typography(funstonTheme)

Or you can use the imperative API overrideThemeStyles to directly set/override styles on a theme:

import Typography from 'typography'
import funstonTheme from 'typography-theme-funston'
funstonTheme.overrideThemeStyles = ({ rhythm }, options) => ({
  'h2,h3': {
    marginBottom: rhythm(1/2),
    marginTop: rhythm(2),
  }
})

const typography = new Typography(funstonTheme)

Published Typography.js Themes

Plugins

Plugins are functions that extend or modify the core typography engine. they can change how headers are styled or add specialized styles e.g. for code or tables. Currently there's one plugin available, typography-plugin-code.

To use the Code plugin, first install using NPM.

npm install --save typography-plugin-code

Then add to your theme before creating a new typography object.

import Typography from 'typography'
import CodePlugin from 'typography-plugin-code'
import sternGroveTheme from 'typography-theme-stern-grove'

sternGroveTheme.plugins = [
  new CodePlugin(),
]

const typography = new Typography(sternGroveTheme)

React.js helper components.

Typography.js includes two helper components for your React.js projects, TypographyStyle and GoogleFont. These are ideal for server-rendering.

  • TypographyStyle creates a style element and inserts the generated CSS for your theme.
  • GoogleFont creates the link element to include the Google Fonts & weights specified in your theme.

To use, first install the package npm install --save react-typography then import them into your html.js file.

import { TypographyStyle, GoogleFont } from 'react-typography'
// Best practice is to have a typography module
// where you define your theme.
import typography from 'utils/typography'

// Inside your React.js HTML component.
<html>
  <head>
    <TypographyStyle typography={typography} />
    <GoogleFont typography={typography} />
  </head>
  <body>
    // stuff
  </body>
</html>

Using with create-react-app

If you use the default create-react-app template, the above React.js solution will not work, and the typography.injectStyles() solution will not enable Google Fonts.. A workaround is to install typography-inject-fonts and do

import Typography from 'typography'
import funstonTheme from 'typography-theme-funston'
import injectFonts from 'typography-inject-fonts'

const typography = new Typography(funstonTheme)
typography.injectStyles()
injectFonts(typography)

API

Configuration

When creating a new instance of Typography, you can pass in a configuration object. All configuration keys are optional.

  • title: The theme title.
  • baseFontSize: The base font size in pixels, defaults to 16px.
  • baseLineHeight: The base line height using the css unitless number, defaults to 1.45.
  • scaleRatio: The "scale ratio" for the theme. This value is the ratio between the h1 font size and the baseFontSize. So if the scale ratio is 2 and the baseFontSize is 16px then the h1 font size is 32px.
{
  scaleRatio: 2,
}
  • googleFonts: An array specifying Google Fonts for this project.
googleFonts: [
  {
    name: 'Montserrat',
    styles: [
      '700',
    ],
  },
  {
    name: 'Merriweather',
    styles: [
      '400',
      '400i',
      '700',
      '700i',
    ],
  },
],
  • headerFontFamily: An array of strings specifying the font family stack for headers e.g. ['Helvetica', 'sans-serif']. Defaults to a system UI font stack.
  • bodyFontFamily: An array of strings specifying the font family stack for the body, defaults to ['georgia', 'serif'].
  • headerColor: A css color string to be set on headers. Defaults to inherit.
  • bodyColor: A css color string to be set for body text. Defaults to hsl(0,0%,0%,0.8).
  • headerWeight: Specify the font weight for headers. Defaults to bold.
  • bodyWeight: Specify the font weight for body text. Defaults to normal.
  • boldWeight: Specify the font weight for "bold" (b, strong, dt, th) elements. Defaults to bold.
  • blockMarginBottom: Specify the default margin-bottom for block elements. Defaults to one "rhythm unit" (i.e. the height of the base line height).
  • includeNormalize: Include normalize.css. Normalize.css is an excellent project which works to normalize the base browser CSS across browsers and serves as an excellent foundation for Typography.js. We include normalize.CSS by default but if you're already including it elsewhere in your project, you can disable including it here by passing false.
  • overrideStyles: Imperative API for directly adding to or overriding auto-generated styles. It's called with a Vertical Rhythm object, the options object, and the algorithmically generated styles.
overrideStyles: ({ adjustFontSizeTo, rhythm }, options, styles) => ({
  h1: {
    fontFamily: ['Montserrat', 'sans-serif'].join(','),
  },
  blockquote: {
    ...adjustFontSizeTo('19px'),
    color: gray(41),
    fontStyle: 'italic',
    paddingLeft: rhythm(13/16),
    marginLeft: rhythm(-1),
    borderLeft: `${rhythm(3/16)} solid ${gray(10)}`,
  },
  'blockquote > :last-child': {
    marginBottom: 0,
  },
})
  • overrideThemeStyles: This has the same function signature as overrideStyles but should be used in place of overrideStyles when using a 3rd-party theme so as to not delete the theme's own overrideStyles function.
overrideThemeStyles: ({ rhythm }, options, styles) => ({
  'h2,h3': {
    marginBottom: rhythm(1/2),
    marginTop: rhythm(2),
  }
})

Related

Developing Typography.js

Typography.js is a monorepo facilitated by Lerna.

TODO: document constants + compass-vertical-rhythm + using typgraphy.js for inline styles.

=======

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

More Repositories

1

typefaces

NPM packages for Open Source typefaces
CSS
2,603
star
2

react-headroom

Hide your header until you need it
JavaScript
1,818
star
3

react-spinkit

A collection of loading indicators animated with CSS for React
CSS
1,491
star
4

docker-nginx

Nginx Docker image for easy hosting of static sites
Nginx
337
star
5

react-gravatar

React component for rendering a gravatar profile image
JavaScript
278
star
6

coffee-react-quickstart

Quickstart for building React single page apps using Coffeescript, Gulp, Webpack, and React-Router
CoffeeScript
254
star
7

superagent-bluebird-promise

Add promise support to superagent using Bluebird
CoffeeScript
183
star
8

element-resize-event

Library to make it easy to listen for element resize events
JavaScript
176
star
9

react-sparkline

React component for rendering simple sparklines
CoffeeScript
147
star
10

blog

my blog!
JavaScript
124
star
11

react-markdown-textarea

Component for React to create textareas for entering Markdown with built-in preview inspired by Github's design
CoffeeScript
120
star
12

trpc-crdt

tRPC integrations for CRDTs: CRDT-native RPC calls
TypeScript
116
star
13

react-micro-bar-chart

React component for micro bar-charts rendered with D3
CoffeeScript
112
star
14

react-retina-image

React component for serving high-resolution images to devices with retina displays
CoffeeScript
109
star
15

facebook-export

Tools to help administer your Facebook groups
CoffeeScript
100
star
16

react-responsive-grid

Power tools for building responsive layouts with React
CoffeeScript
91
star
17

react-component-gallery

React component for creating an evenly spaced gallery of children components
CoffeeScript
88
star
18

react-icon-factory

Simply add icon SVGs and the react icon factory will manufacture a custom icon component!
JavaScript
66
star
19

cjsx-loader

coffee-react-transform loader module for webpack
Makefile
53
star
20

react-smart-time-ago

Show relative "time ago" dates for anything in last two weeks and absolute dates from then on back
JavaScript
33
star
21

react-component-width-mixin

React mixin which sets width as state variable and updates as component changes shape
JavaScript
29
star
22

react-simple-table

For when you just want a table
CoffeeScript
23
star
23

isRetina

Simple function which determines if your code is running on a high DPR device or not
JavaScript
23
star
24

gatsby-starter-theme-ui

Fork of the Gatsby default starter but with theme-ui
JavaScript
19
star
25

react-autoupdate-time

Renders a <time> element that autoupdates at a configurable interval
CoffeeScript
19
star
26

og_mailinglist

Drupal Module that converts individual Organic Groups into mailing lists.
PHP
18
star
27

compass-vertical-rhythm

A port-in-progress of the Compass vertical rhythm library
CoffeeScript
18
star
28

check-gatsby-caching

Checks if your Gatsby site's cache-control headers are correct and optimized
JavaScript
18
star
29

Fuzzymatcher.js

Fuzzymatching library optimized for powering auto-complete widgets
JavaScript
18
star
30

docker-nginx-reverse-proxy-ssl

Docker image for creating simple reverse proxy with ssl termination
Shell
17
star
31

linux-config

my personal config files
Vim Script
16
star
32

color-pairs-picker

Given a color, it picks pleasing and well contrasted background and foreground colors
CoffeeScript
14
star
33

react-page-width

React mixin so a component can always know the current page width
CoffeeScript
13
star
34

Eduglu-Chatroom

Awesome Drupal-groups aware Chatroom built on Node.js
JavaScript
12
star
35

toml-loader

TOML loader module for webpack
JavaScript
11
star
36

makersgtd

Yet Another GTD Single Page App
CoffeeScript
10
star
37

engagement

Track when a user is engaging with a page
CoffeeScript
9
star
38

docker-nodejs-base

Base for building node.js web apps. Node.js, Ruby, Bundler, etc.
9
star
39

hapi-rethinkdb-thinky

Hapi plugin that automatically loads your Thinky models for RethinkDB
CoffeeScript
9
star
40

modularscale

Calculate a modular scale
CoffeeScript
9
star
41

image-exists

Check if an image exists
JavaScript
8
star
42

aiocalendar

All-in-one calendar feature built in Drupal
JavaScript
8
star
43

gray-percentage

Convenience function to get a gray value by percentage e.g. gray(60) -> "hsl(0,0%,60%)"
CoffeeScript
8
star
44

react-component-starter

Quickstart for creating a Coffeescript React component with examples
JavaScript
8
star
45

phpmailer

a temporary (hopefully) fork of PHPMailer to work on some changes we need for OG Mailinglist. The issue for our changes can be found at http://sourceforge.net/tracker/?func=detail&aid=3080711&group_id=26031&atid=385707
PHP
7
star
46

react-ghost-button

A simple react-ghost-button
CoffeeScript
7
star
47

gatsby-starter-building-blog

Gatsby v2 starter with colors taken from a photo of a building in Berkeley, CA
JavaScript
6
star
48

Journal

Backbone.js / Node.js multi-user journal app
CoffeeScript
6
star
49

gatsby-theme-cooper-hewitt

JavaScript
6
star
50

gatsby-starter-theme-cooper-hewitt

Starter for gatsby-theme-cooper-hewitt
JavaScript
6
star
51

gatsby-starter-blog-child-theme

Starter for creating a child theme for gatsby-theme-blog
JavaScript
6
star
52

react-html-elements-styleguide

React styleguide component
JavaScript
6
star
53

react-message

React component for showing status messages
CoffeeScript
6
star
54

eduglu_features

Core eduglue features
PHP
5
star
55

Family-History-Distro-features

Features for the Family History Drupal Distro
PHP
5
star
56

create-gatsby-fs-routes

wee prototype
JavaScript
5
star
57

eduglu_make

Drush Make file for eduglu
4
star
58

reactive-static-generation-benchmarks

Benchmarks for testing Reactive Static Generation vs SSG/SSR
TypeScript
4
star
59

docker-xelatex

Docker container with Xelatex and high quality free fonts installed
Shell
4
star
60

index-gatsby-blog-demo

Gatsby starter for a Contentful project.
JavaScript
4
star
61

gatsby-plugin-emoji-cursor

Gatsby plugin to add emjois which trail behind your cursor
JavaScript
4
star
62

brunch-backbone-widgets

Reusable Widgets for apps built with Backbone.js + Brunch + Sass/Compass
JavaScript
4
star
63

lmdb-backed-array

LMDB-backed array implementation for node.js for lowering memory usage for huge arrays.
JavaScript
4
star
64

every-second

A Gatsby site which which updates a time counter every second
CSS
4
star
65

hapi-dynamic-scope

Create dynamic route scopes based on information in the request
JavaScript
4
star
66

gatsby-plugin-inspector

Use Node.js inspector API to sample CPU/memory of a Gatsby build
JavaScript
4
star
67

gatsby-shopify-wordpress-demo

A Gatsby starter using the latest Shopify plugin showcasing a store with product overview, individual product pages, and a cart
JavaScript
4
star
68

backbone.js-practice

JavaScript
3
star
69

agility-gatsby-starter2

A sample GatsbyJS website using the Agility CMS Gatsby source plugin
3
star
70

gatsby-starter-shopify

A Gatsby starter using the latest Shopify plugin showcasing a store with product overview, individual product pages, and a cart
JavaScript
3
star
71

Family-History-distro-HTML-mockup

mockup yo
JavaScript
3
star
72

eduglu_profile

Install profile (think distro) for Drupal
3
star
73

test-recipes

some API ideas
JavaScript
3
star
74

gatsby-starter-theme-hyde

Starter for gatsby-theme-hyde
JavaScript
3
star
75

gatsby-cli-exploration

exploring some ideas for new UI for gatsby cli
JavaScript
3
star
76

reactjs-twitter-stream-example

Example React.js / Node.js app that streams tweets
JavaScript
3
star
77

hapi-death

Help Hapi.js die gracefully by intercepting SIGINT and SIGTERM and calling server.stop()
JavaScript
3
star
78

familyhistorydistro

Drupal Family History Distro
PHP
3
star
79

fun-with-fauna

JavaScript
2
star
80

atrium_book

port of atrium_book to Eduglu, KIT-complient, likely soon to be superceeded by new atrium_book version
PHP
2
star
81

BYU-Starter-Drupal-Profile

.make file and .profile file for a basic BYU Drupall install
2
star
82

hapi-influx

Hapi plugin to create a shared InfluxDB client
CoffeeScript
2
star
83

gc-functions-test

JavaScript
2
star
84

image-processing-benchmark

CSS
2
star
85

notesfromquarantinechurch-blog

JavaScript
2
star
86

react-flickr-example

Flickr search page build with React
CSS
2
star
87

gatsby-source-airtable-demo

TypeScript
2
star
88

bug-report-123

JavaScript
2
star
89

Drupal-Flot

Fork of Drupal flot module to keep track of patches / changes I make
PHP
2
star
90

sanity-kitchen-sink

Kitchen Sink
JavaScript
2
star
91

trello-flow

Create a Cumulative Flow Diagram from your Trello Board(s)
CoffeeScript
2
star
92

file-upload-tests

Testing the fastest way to upload files w/ Node.js on Linux
JavaScript
2
star
93

agility-gatsby-starter

A sample GatsbyJS website using the Agility CMS Gatsby source plugin
2
star
94

preview-testing

Gatsby starter for a Contentful project from the community.
JavaScript
2
star
95

react-simple-form-inline-styles

Simple inline styles for React forms
CoffeeScript
2
star
96

agility-starter-2

JavaScript
2
star
97

gatsby-site

Gatsby Site
JavaScript
2
star
98

the-nope-game

thenopegame.com (or whatever the domain will be)
JavaScript
2
star
99

static-query-bug-repo

JavaScript
2
star
100

my-new-contentful-blog

Gatsby starter for a Contentful project from the community.
JavaScript
2
star