2.1.1 • Published 4 years ago

natural-scale v2.1.1

Weekly downloads
148
License
MIT
Repository
github
Last release
4 years ago

Natural Scale

NPM downloads Circle CI Status Code Climate Support Me

Natural Scale is a JavaScript utility that makes creating beautiful, natural systems of scale a cinch. It's especially useful for creating a consistent Type Scale accross your UI, but can be used in a veriety of ways.

Example of a Type Scale in action from type-scale.com

type-scale.com Example

Basic Usage

import { Scale, Ratio } from "natural-scale";

// Create a Scale instance
const Step = Scale({ interval: Ratio.GOLDEN_RATIO, unit: "rem" });

// Use it!
const headingSize = Step(4);
const subheadingSize = Step(3, "em"); // Optionally, you can override the unit of measure
const bodySize = Step(2);

Works with your stuff

natural-scale works great with your favorite UI Libraries like React and Vue.

With React

import React from 'react';
import { render } from 'react-dom';
import * as glamorous from 'glamorous';
import { Scale, Ratio } from 'natural-scale';

const Step = Scale({interval: Ratio.MINOR_THIRD, unit: 'rem'});

const Title = glamorous.h1({
  fontSize: Step(5);
});

const SubTitle = glamorous.h2({
  fontSize: Step(4);
});

const Body = glamorous.p({
  fontSize: Step(3);
});


function App() {
  return (
    <>
      <Title>Hey there!</Title>
      <SubTitle>I'm a subtitle</SubTitle>
      <Body>And I'm the body. I’m long- actually, not too long. Medium length.</Body>
    </>
  );
}

render(<App />, document.body);

With React Native

Native looks for unitless scales. To help out, we'll pass in a base font size too

import React from "react";
import { Text, View } from "react-native";
import { Scale, Ratio } from "natural-scale";
const Step = Scale({ interval: Ratio.MINOR_THIRD, base: 16 });

const styles = StyleSheet.create({
  container: {
    backgroundColor: "#ddd"
  },
  message: {
    fontSize: Step(5)
  }
});

export default () => {
  <View style={styles.container}>
    <Text style={styles.message}>Welcome!</Text>
  </View>;
};

Intervals

I've included some common intervals used in standard musical tuning systems. The following intervals can be used like so:

import { Scale, Ratio } from "natural-scale";
const Step = Scale({ interval: Ratio.MINOR_SECOND });

const step1 = Step(1); // 0.702
const step3 = Step(3); // 0.888
const step7 = Step(7); // 1.423
Standard Intervals
NameAPI NamePitch RatioInterval
Minor secondMINOR_SECOND16/151.067
Major SecondMAJOR_SECOND9/81.125
Minor ThirdMINOR_THIRD6/51.2
Major ThirdMAJOR_THIRD5/41.25
Perfect FourthPERFECT_FOURTH4/31.333
Augmented FourthAUGMENTED_FOURTH45/321.414
Perfect FifthPERFECT_FIFTH3/21.5
Minor SixthMINOR_SIXTH8/51.6
Major SixthMAJOR_SIXTH5/31.667
Minor SeventhMINOR_SEVENTH16/91.778
Major SeventhMAJOR_SEVENTH15/81.875
Perfect OctavePERFECT_OCTAVE2/12
Golden RatioGOLDEN_RATIO1/φ1.618

Custom Interval

Of course you are free to experiment and find a scale that works well for you.

import { Scale } from "natural-scale";
const Step = Scale({ interval: 2.125, unit: "rem" });

const step1 = Step(1); // 0.104em
const step3 = Step(3); // 0.47em
const step7 = Step(7); // 9.595em
2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago