Coder Social home page Coder Social logo

andreasbm / pixel-perfect Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 160 KB

A pixel perfect SCSS stylesheet. Spiced with themeable mixins, custom CSS variables and other cool stuff you can handpick from.

Home Page: https://pixel-perfect-39e99.firebaseapp.com/

TypeScript 15.99% HTML 23.75% CSS 56.44% JavaScript 3.81%

pixel-perfect's Introduction

Pixel Perfect

Version Downloads

pixel-perfect

A pixel perfect SCSS stylesheet (demo: https://pixel-perfect-39e99.firebaseapp.com/). Spiced with themeable mixins, custom CSS variables and other cool stuff you can handpick from.

Pixel perfect definition:

Each pixel is intentionally being used to the fullest for the sharpest, cleanest look.

How to use

๐Ÿ‘ Step 1: Install Pixel Perfect

$ npm i pixel-perfect --save

๐Ÿ™Œ Step 2: Import the library

@import "~pixel-perfect/pixel-perfect.scss";

๐Ÿ‘ Step 3: Include the layout

You can include everything from the layout.

@include pp-layout();

Or you can handpick the styles you want. Let's say you only want the grid and the typography.

@include pp-grid();
@include pp-typography();

๐Ÿ‘Œ Step 4: Create a theme for your app

Create a theme (or multiple themes) for your app.

@mixin light-theme() {
  @include css-vars(pp-palette("primary", $pp-yellow));
  @include css-vars(pp-palette("accent", $pp-orange));
  @include css-vars(pp-palette("warn", $pp-red));
  @include css-vars(pp-palette("error", $pp-orange));
  @include css-vars(pp-palette("success", $pp-black-dirty));
  @include css-vars((
    --navbar-color: white,
    --navbar-bg: map-get($pp-yellow, 500),
    --app-text: black,
    --app-bg: white
  ));
}

Include the mixins in your stylesheet. You could for example scope the themes in classes to quickly switch between themes on runtime.

.theme-light {
  @include light-theme();
}

.theme-dark {
  @include dark-theme();
}

You might be wondering what variables the css-vars(pp-palette(...)) spits out. The palette function spits out all the nessesary key-value pairs for the palette. Look below what variables we are talking about.

$pp-blue: (
  500: #4581F6,
  400: light-color(#4581F6),
  600: dark-color(#4581F6),
  contrast: (
    500: $white-87-opacity,
    400: $white-87-opacity,
    600: $white-87-opacity
  )
);

@include css-vars(pp-palette("primary", $pp-blue), $root: true);

:root {
  --primary-default: pp-map-get($colors, $default)
  --primary-lighter: pp-map-get($colors, $lighter),
  --primary-darker: pp-map-get($colors, $darker),
  --primary-default-contrast: pp-contrast($colors, $default),
  --primary-lighter-contrast: pp-contrast($colors, $lighter),
  --primary-darker-contrast: pp-contrast($colors, $darker)
  
  --primary-500: pp-map-get($colors, 500),
  --primary-500-contrast: pp-contrast($colors, 500)
  
  --primary-600: pp-map-get($colors, 600),
  --primary-600-contrast: pp-contrast($colors, 600)
  
  --primary-400: pp-map-get($colors, 400),
  --primary-400-contrast: pp-contrast($colors, 400)
}

๐Ÿค˜ Step 5: Decide whether you want custom CSS variables or SASS variables.

The variables can be used in your stylesheets by using the var(args...) function. If you want the primary default color you could grab it by using var(--primary-default). The theming in pixel-perfect uses custom CSS variables out of the box. Unfortunately, not all browsers support custom CSS variables yet (See current state). Therefore you can set the flag $css-vars-use-native: false; to tell pixel-perfect to use SASS variables instead. We recommend that you use custom CSS variables to get all the sweet benefits and either serve a seperate stylesheet for browsers without custom CSS variables or use polyfills.

If you want to deactivate you can do the following by extracting all of your theme related sass into one mixin that you can reuse with different variables:

// Deactive custom CSS variables :,(
$css-vars-use-native: false;

.theme-light {
  @include light-theme();
  @include demo-theme();
}

.theme-dark {
  @include dark-theme();
  @include demo-theme();
}

๐Ÿ’ช Step 6: Customize the variables (optional)

Its possible to customize most of the variables used in pixel-perfect.

@import "~pixel-perfect/pixel-perfect.scss";

$font-size-h1: 20rem;
$font-size-h2: 17rem;

$space-s: 5rem;
$space-m: 10rem;
$space-l: 15rem;
...

๐Ÿ‘Š Step 7: Create your app-theme

Here is an example of what your theme could look like.

@mixin demo-theme() {
  body {
    color: var(--app-text);
    background: var(--app-bg);
  }
}

๐Ÿ”ฅ SCSS naming

Go from general to concrete in the naming. Examples could be "property-element" or "property-state".

$font-size-base-screen-l:   17px !default;

$font-size-l:   px-to-rem(18) !default;
$font-size-m:   px-to-rem(15) !default; 

$font-size-h1:  px-to-rem(50) !default;
$font-size-h2:  px-to-rem(32) !default;

$font-weight-h1:  $font-weight-bold !default;
$font-weight-h2:  $font-weight-thin !default;

$space-screen-s: px-to-rem(20) !default;

Its fine to use the module name (eg. "button") as prefix.

$button-border: none !default;
$button-border-radius: px-to-rem(6) !default;

$button-font-size: $font-size-h4 !default;
$button-line-height: 100% !default;
$button-transition: all 200ms ease !default;

๐Ÿš€ Mixin overview

Heres an overview of some of the sweet mixins that can generate classes for you.

@include pp-normalize();
@include pp-color-classes();
@include pp-elevation-classes();

@mixin pp-layout() {
	@include pp-normalize();
	@include pp-global();
	@include pp-typography();
	@include pp-grid();
}

@mixin pp-layout-helpers() {
  @include pp-layout-helpers-padding();
  @include pp-layout-helpers-margin();
  @include pp-layout-helpers-display();
  @include pp-layout-helpers-alignment();
}

๐ŸŒˆ License

MIT

pixel-perfect's People

Contributors

andreasbm avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.