Giter VIP home page Giter VIP logo

aneekrahman / jstyling Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 12.28 MB

JStyling is a library which can do Styling totally inside of JavaScript. React.JS inspired object passing in as the styling. No more having to make everything look gibberish inside your JS file to update or set the styling.

License: MIT License

HTML 15.77% JavaScript 84.23%
javascript css style styling styling-css-in-js styling-css css-in-js ui ui-components syntax script-styling only-one-file

jstyling's Introduction

- I don't hate css files, but you just won't need them anymore.

NPM Version NPM Downloads

Intro

You won't ever need a CSS file every again! Why not just do everything in JavaScript!

This is a library which can do Styling totally inside of JavaScript.

React.JS inspired object passing in as the styling, and CSS like element selection! No more having to make everything look gibberish inside your JS file for styling.

What's new in v1.0.13

  • Ability to animate using .animate()
  • Write raw CSS in JS using .setStyle()

Example

Code for this inside example/client.js (Check out how simple it is!)

Intro Code Example

// Style it! Keep it Neat & Clean
JS("button").style({
  backgroundColor: "transparent",
  backgroundImage: "linear-gradient(rgba(0,0,0,.02), rgba(0,0,0,.03))",
  border: "1px solid rgba(0,0,0,.05)",
  color: "#006edb",
  padding: ".5em 1.6em",
  borderRadius: ".5em",
  boxShadow: "0px 1px 3px rgba(0,0,0,0.04)",
});

Also help the development by reporting any bugs. Feel free to contribute to this project. Thanks โค

Benefits

  • Easy and readable syntax
  • IT'S JUST ONE JS FILE, NO CSS
  • Extremely lightweight: Only 1.2kB (500B gzipped!)

CDN

<script src="https://unpkg.com/[email protected]/src/jstyling.js">

NPM Installation

npm i jstyling

Docs

.style()

Set the styling using this method:

// You pass in a JavaScript Object to .style({})
JS("button").style({
  backgroundColor: "transparent",
  backgroundImage: "linear-gradient(rgba(0,0,0,.02), rgba(0,0,0,.03))",
  border: "1px solid rgba(0,0,0,.05)",
  color: "#006edb",
  padding: ".5em 1.6em",
  borderRadius: ".5em",
  boxShadow: "0px 1px 3px rgba(0,0,0,0.04)",
});

Select any elements just like you would in CSS:

JS("h4").style(style); // Every h4
JS("#hero").style(style); // Just #hero
JS("ul li").style(style); // Children of ul

// Also DOMElements work!
const element = document.querySelector("p");
JS(element).style(style);

Reapply new styles on callbacks:

// Set a transition to get the animation effect!
JS("#hero").style({
  width: "100%",
  height: "500px",
  backgroundColor: "orange",
});

document
  .querySelector("button")
  .addEventListener("mousedown", () => {

  JS("#hero").style({
    style.transform = "translateX(30px)"
  });
});

.animate()

If you want to animate an element, you should use this method.

JS("#button3").animate({
  styles: {
    backgroundColor: "#006edb",
    height: "500px",
  },
  duration: 1000,
  ease: "ease-in-out",
});

.animate() takes in an Object with these parameters:

  1. styles: - Pass in a styling Object consisting all of your styles you want to animate in.
  2. duration: - Duration of the animation in integer miliseconds.
  3. ease: - The transition-timing-function easing as string. All of the CSS easing work

.setStyle()

If you feel like you can't access anything from the JavaScript Style Object, you can always use this method to write the CSS, inside of JavaScript of course.

// Use backticks as they can give you multi-line strings!
JS().setStyle(`
  * {
    font-family: Arial
  }
  h2::after{
    content: "hello"
  }
`);

Styling Options

JS("#indentifier").style({
  // Your styles go here!
  maxHeight: "",
  fontSize: "",
  color: "",
  // ...
  // Remember, it's all camelCase
});

The full list of all the options are the same as vanilla javascript. You can follow this useful guide for all the possible options:

w3schools.com

jstyling's People

Contributors

aneekrahman 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.