Git Product home page Git Product logo

styletosheet's Introduction

styleToSheet

What

Dynamically style in Javascript during development, then export the generated styles as a static stylesheet.

Usage

After adding this script to the head-ele of the doc, the global variable styleToSheet will be available of which you can access all the properties defined below. The most important ones are:

Add a css-rule to stylesheet:

styleToSheet.addRule('div a', 'padding: 0; color: green;')

When you're done with styling, add this in your script and reload page to download the stylesheet for production:

styleToSheet.downloadStyles()

For comfortably reading the stylesheet at any point of development, display them in the body-ele:

styleToSheet.showStyles()

Optionally set a prefix for rule-selectors:

styleToSheet.prefix = '.prefixAllSelectorsWithThis'

Why

1.) Share script-variables with stylesheets, because we can then set a className on an ele and use it furtheron as a selector for the styling, and bind functions to eles with that className.

Note: It is possible to share CSS-vars with scripts, but
then again a script needs to know the property-name of
the css-var.

2.) Do everything in Javascript, no CSS-preprocessors like LESS or SASS, so one doesn't need to know about yet another tool, which saves time.

3.) Have a programmatical way to write CSS, as human-written CSS is prone to inconsistencies, such as rules which are declared several times or properties which are declared several times within a rule. Won't happen with this tool.

How

Contain a rules-object and modification-functions for it. Insert rules into stylesheet in head-ele on any modification. Provide function for downloading stylesheet.

Authors

Ida Ebkes [email protected] 2017

License

MIT, a copy is attached in this folder.

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.