Giter VIP home page Giter VIP logo

shevy's Introduction

Shevy

A simple, configurable Sass library for typography with perfect vertical rhythm.

Demo

Check out the demo

Installation

Shevy is a Sass library, and thus requires Sass to be installed on your machine and and some means of compiling Sass down to CSS. I leave the details of that setup to you.

Copy From Source

One way to add Shevy to your project is to copy from source. If you want to add this to a project, copy the core/ directory into the appropriate location in your app.

$ cp -R core/ path/to/your/project

Then @import the _shevy.scss file into your project.

@import 'core/shevy';

Be sure to place this before any call to Shevy mixins and functions so that the Sass compiles without error.

NPM

You can install Shevy as an NPM module with:

npm install --save shevy

Once installed, you can proceed to include the core/_shevy.scss file in your project. It will likely be nested a directory or so deeper than directly copying from source, so be sure you get your path correct. Something like this:

@import '../../node_modules/shevy/core/shevy';

At this time (October 2016), I have not attempted to use Shevy with any JS-to-CSS configuration such as requiring it in a Webpack module. Thus, I have no recommendations for how to use it in that way... yet.

Bower

You can install Shevy as a Bower component:

bower install --save shevy

Similar to the NPM installation, this will install the project in another directory, so be sure to get your path correct when trying to import it.

@import '../../bower_components/shevy/core/shevy';

Ruby on Rails

If you are using Ruby on Rails and would like to add Shevy to your project, you're in luck. Shevy is also a Ruby Gem. In your Gemfile add:

gem 'shevy'

Then run:

$ bundle install

Once the gem is installed, add Shevy to your project by adding:

@import 'shevy';

Once again, be sure to place this before any call to Shevy mixins or functions so that the Sass compiles without error.

Usage

Shevy comes packaged with default settings. So the simplest usage of Shevy is to call a few mixins.

@include headings;
@include body;
@include content;

This will output styles for all headings (h1 to h6), several content tags (p, ol, ul, and pre), and set font-size and line-height for the body tag. However, you may find that the default settings don't suit your project. Shevy allows you to configure settings globally and/or at the component level. Here's how:

Global

Shevy mixins take a Sass map as one of the arguments. The default map is the $shevy map ($shevy is always defined, even if you don't define your own). Thus, to make global changes to your configuration, simply define your own $shevy map to override the default settings. Like so:

$shevy: (
  base-font-size: 14px,
  base-line-height: 1.5,
  base-font-scale: (2.5, 2.1, 1.8, 1.5, 1.25, 1),
  margin-bottom: true,
  proximity: false,
  proximity-factor: .85
);

Then, @include the headings, body, and content mixins in your code

@include headings;
@include body;
@include content;

Now marvel at your beautiful typography. Assuming you've put something on the page. You have put something on the page, haven't you?

Component Level

You can also pass a custom map into the headings and paragraph mixin. This should enable you to make custom typography per module or responsive typography per breakpoint.

Define a new Shevy map:

$shevy-small: (
  base-font-size: 12px,
  base-line-height: 1.3,
  base-font-scale: (2, 1.8, 1.6, 1.4, 1.2, 1)
);

Then call the any of the mixins, passing your new settings map as an argument:

.my_component {
  @include headings($shevy-small);
  @include content($shevy-small);
}

Defaults

$shevy: (
    base-font-size: 1em,
    base-line-height: 1.5,
    base-font-scale: (3, 2.5, 2, 1.5, 1.25, 1),
    margin-bottom: true,
    proximity: false,
    proximity-factor: .85
);

base-font-size

The base-font-size key is intended to be the standard font-size for the project. font-scale multiplies its value against the base-font-size.

base-line-height

The base-line-height is the standard line-height. If this is set in pixels, this will be the base-spacing value for Shevy. If it is provided as a factor, such as 1.5, it will be multiplied by the base-font-size to generate the base-spacing value.

base-font-scale

This is a Sass list of factors to multiply by the base-font-size to generate the font-sizes for headings and paragraphs (if a paragraph-scale is not provided).

margin-bottom

By default, margin bottoms are added to all typography to maintain the vertical rhythm. However, you may wish to remove these. In that case, setting margin-bottom: false in your map will set the margin-bottom property to 0 for each element.

proximity

In design, there is a phenomenon known as the proximity effect where our minds group things together that are close in spatial relation. Turning on proximity will enable you to apply a proximity factor to the margin-bottoms and base-spacing outputs, in effect, drawing content closer together. You might find this more aesthetically pleasing than strictly following the baseline.

proximity-factor

Proximity factor is a factor with which to adjust the base spacing of your typography without affecting the line-height spacing. This value will be multiplied against the calculated base-spacing value, if proximity is set to true in your settings map.

Functions

There are several public functions available to the developer to use as they please. Here is a list of them:

  • base-font-size(), with alias bsf()
  • base-font-unit(), with alias bfu()
  • base-line-height(), with alias blh()
  • line-height-spacing(), with alias lhs()
  • base-spacing(), with alias bs()
  • settings()

base-font-size

base-font-size() will return the base-font-size setting in the $shevy map, or the map passed to the function as an argument.

base-font-unit

base-font-unit() will determine whether the measurements have been defined in px, em, or rem and return the correct unit type. A map can be passed to the function as an argument.

base-line-height

base-line-height() will return the base-line-height setting in the $shevy map, or the map passed to the function as an argument.

line-height-spacing

line-height-spacing() calculates the line-height spacing of the vertical rhythm by multiplying the base font size by the base line-height. A factor may be passed to the argument to return multiples or dividends of the line-height spacing.

base-spacing

base-spacing() calculates the base spacing of the vertical rhythm by multiplying the base font size by the base line-height, with the additional math to handle proximity, thus differentiating it from the line-height-spacing() function. A factor may be passed to the argument to return multiples or dividends of the base-spacing.

Example:

.button {
  padding: bs(.5) bs(2);
}

A map of settings can be passed as the second argument to adjust the output.

settings

settings() is a function utilized by Shevy to merge a map with the $shevy-defaults map. This ensures that the current map has all the settings it should. The user can use this to create new maps on the fly if they desire, though there isn't much of a purpose for that just yet.

Support

Currently, Shevy supports px, em, and rem usage. Additional support for other measurement units may be added in the future.

License

The MIT License (MIT)

Copyright (c) 2016 Kyle Shevlin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

shevy's People

Contributors

321zeno avatar kyleshevlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

shevy's Issues

unclear docs: base-spacing and line-height-spacing

I understand there's magic behind using base-spacing which I prefer just using exclusively for spacing. I don't know when I should be using line-height-spacing as it doesn't buy me the magic of calculating proximity. Can there be an example use case for preferring to use line-height-spacing?

Make list of content elements customizable

Hi,

When using the @include content mixin, it would be nice to be able to customize the list of elements.
By default it's just p, ol, ul, pre, but usually I need more : dl, figure, etc.
So I end up doing it by hand instead of using that mixin.

Maybe there could be a second parameter to the mixin, or another property in the $shevy-defaults variable ?

Publish on npm

It would be very helpful if this module is also published on npm.

Proximity and Proximity-Factor Enhancement

After reading this blog by Zell: http://zellwk.com/blog/wrong-about-vertical-rhythm/, I thought it would be useful to apply this "proximity principle" to Shevy. While I am disappointed that the article did not share any specific mathematics that support why this is important, I cannot deny that there are times where strictly following a baseline is not as aesthetically pleasing as the mathematics would suggest.

Thus, I am going to add proximity (Boolean) and proximity-factor (Float) to the default $shevy map. The first will turn proximity mathematics on or off, likely defaulting to off. The second will be used to determine what percentage of the base-spacing to apply. For example, if a factor of 0.75 is provided, then the spacing between content elements (and possibly headings, will see if proximity is useful there as well) will be 75% of what it would otherwise be. This should enable the user the ability to fine tune the spacing of their typography.

Examples / Demos

Hello there! I love this SASS library and I am using it for three sites.
I have recommended it to be added to Famolus/awesome-scss, but they said it is lacking a demo and examples.

I see you have a GitHub Page for this project. Why don't you add this to the README and project description? On top, you could add vertical lines to the page to show the correctness of the vertical rhythm.

I'm just suggesting this as appearing in one of those awesome-* lists gives a lot of traffic and stars.

Use with modular scale

hy my friend and thanks to this great plugin.
Now my question. I#m using modular scale and would like to assign base font scale in this way:

base-font-scale: ((ms(6), ms(5), ms(4), ms(3), ms(2), ms(1))

but it's not working

messageOriginal: cannot compare numbers with incompatible units
relativePath: FeSource/Vendor/shevy/core/shevy/_mixins.scss

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.