Git Product home page Git Product logo

px-text's Introduction

Overview

Px text is a small sass and js function that allows for the quick conversion of pixels to rem. Its primary purpose is to allow programmers to convert text sizes from pixel measurements into rem without requiring a calculator.

Install

npm install --save px-text

SASS

Import in sass

@import 'node_modules/px-text/index.scss';

Import using sass loader

@import 'px-text/index.scss';

Example

body {

font-size: px(18);

line-height: px(21);

}

Node and Styled Components

Import js

import {px} from 'px-text'

# OR

import px from 'px-text'

Example

import styled, { css } from 'styled-components'
import px from 'px-text'

const containerStyles = css`
	p {
		font-size: ${px(16)};
	}
`

const Container = styled.div`
    font-size: ${px(16)};
`

Testing

Running

npm test

should ouput the following


> [email protected] test
> mocha



  Running SASS Test
    The function for px conversion to rem
      √  px(16); Outputs 1rem
      √  px(18); Outputs 1.125rem
      √  px(32); Outputs 2rem

  Running JS Test
    The function for px conversion to rem
      √  px(16); Outputs 1rem
      √  px(18); Outputs 1.125rem
      √  px(32); Outputs 2rem
    The function for px conversion to rem when using the default export
      √  px(16); Outputs 1rem
      √  px(18); Outputs 1.125rem
      √  px(32); Outputs 2rem


  9 passing (5ms)

License

MIT https://github.com/JoueBien/px-text/blob/master/LICENSE

Notes

This library & documentation was originally written to work with the sass loader that vue 2 used. It should work with other frameworks but there are no guarantees that it will.

It is currently working with React, Svelte, Vue 2 and Vue 3. The 0.2.0 release is designed to work with more modern environments.

For vue 2 projects you may wish to use version 0.1.5 as it uses an earlier version of SASS.

If you know how to use it with other front end frameworks feel free to make a pull request or open an issue.

px-text's People

Contributors

jouebien avatar

Stargazers

 avatar

Watchers

 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.