GithubHelp home page GithubHelp logo

glennsl / bs-css Goto Github PK

View Code? Open in Web Editor NEW

This project forked from giraud/bs-css

0.0 2.0 0.0 550 KB

statically typed DSL for writing css in reason.

License: ISC License

JavaScript 96.99% OCaml 2.99% HTML 0.03%

bs-css's Introduction

bs-css

statically typed DSL for writing css in reason.

Bs-css is a statically typed interface to Glamor

Installation

npm install --save bs-css

In your bsconfig.json, include "bs-css" in the bs-dependencies.

Usage

module Theme = {
  open Css;
  let textColor = hex("333");
  let basePadding = px(15);
};

let styles = Css.({
  "card": style([
    backgroundColor(white),
    boxShadow(~y=3, ~blur=5, rgba(0, 0, 0, 0.3)),
    padding(Theme.basePadding)
  ]),
  "title": style([
    fontSize(rem(1.5)),
    color(Theme.textColor),
    marginBottom(Theme.basePadding)
  ])
});

<div className=styles##card>
  <h1 className=styles##title> (ReasonReact.stringToElement("Hello")) </h1>
</div>

Merging css rules

You can merge css rules using merge

let text_primary = style([ color(white) ]);
let small = style([ fontSize(px(10)) ]);


<p className=merge([ text_primary, small ])> ...

bs-css will make sure that rules are merged in the correct order, managing nesting and precedence for you.

Global css

You can defined global css rules with global

Css.(
  global("body", [margin(px(0))])
);

Css.(
  global("h1, h2, h3", [color(rgb(33, 33, 33))])
);

Keyframes

define animation keyframes;

let bounce = Css.keyframes([
  ("0%", [ transform( scale(0.1, 0.1) ),  opacity(0.0) ]),
  ("60%", [ transform( scale(1.2, 1.2) ),  opacity(1.0) ]),
  ("100%", [ transform( scale(1.0,1.0) ), opacity(1.0) ])
]);

let styles = css([
  animationName(bounce),
  animationDuration(2000),
  width(px(50)),
  height(px(50)),
  backgroundColor(rgb(255, 0, 0))
]);

// ...
<div className=styles>
  (ReasonReact.stringToElement("bounce!"))
</div>

Development

npm run start

Where is the documentation?

Its on its way! until then you can check out css.rei.

Thanks

Thanks to glamor which is doing all the heavi lifting. Thanks to bs-glamor which this repo was forked from. Thanks to elm-css for dsl design inspiration.

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.