inline css for react et al
Branch: master
Clone or download
threepointone Merge pull request #317 from bvaughn/docs-nested-example
Added example to child-selectors of using Glamor-generated class names
Latest commit 667b480 Sep 11, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Merge pull request #317 from bvaughn/docs-nested-example Sep 11, 2017
examples new react for testing streaming Aug 1, 2017
new lose babel runtime, sketch for streaming work Jul 24, 2017
perf some tests, misc Oct 29, 2016
src expose inserted css rules when server rendering Aug 13, 2017
tests fix server tests Jul 24, 2017
webpack scope hoisting, lose es6 build Jul 21, 2017
.babelrc upgrade all dependencies Jul 21, 2017
.editorconfig Add .editorconfig file Aug 28, 2016
.gitignore updated README Feb 17, 2017
.stylelintrc move stuff around Oct 25, 2016
.travis.yml try to fix travis Nov 30, 2016
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Jul 20, 2017
CONTRIBUTING.md Stylesheet::replace(index, rule), ::delete(index) Oct 18, 2016
LICENSE Add a LICENSE file Mar 20, 2017
README.md "fix" local testing, :fullscreen support Jul 20, 2017
aphrodite.d.ts added typings Sep 9, 2016
aphrodite.js - extract stylesheet into own module Aug 23, 2016
babel-hoist.js prep package for babel hoist Dec 28, 2016
babel.js prepping for css literals Nov 21, 2016
index.d.ts add typings for plugins, speedy, flush, css.keyframes, css.fontFace Sep 5, 2017
inline.js land glamor/inline Jul 23, 2017
jsxstyle.d.ts added typings Sep 9, 2016
jsxstyle.js recover 4k by using local react/lib/CSSPropertyOperations (!) Aug 22, 2016
ous.d.ts Update ous.d.ts Sep 10, 2016
ous.js *glamorous*!!! first cut Aug 8, 2016
package.json Fix: Add server.d.ts to NPM bundle Sep 1, 2017
react.d.ts add support for propMerge() in react package Oct 27, 2016
react.js react integration! Aug 10, 2016
reset.js include reset at base Aug 8, 2016
server.d.ts Add typings for glamor/server Aug 7, 2017
server.js - extract stylesheet into own module Aug 23, 2016
styled.js some some Nov 21, 2016
utils.d.ts added typings Sep 9, 2016
utils.js - extract stylesheet into own module Aug 23, 2016
yarn.lock new react for testing streaming Aug 1, 2017

README.md

glamor

Join the chat at https://gitter.im/glamor-css/Lobby

build status

css in your javascript

npm install glamor --save

usage

import { css } from 'glamor'

// make css rules
let rule = css({
  color: 'red',
  ':hover': {
    color: 'pink'
  },
  '@media(min-width: 300px)': {
    color: 'green',
    ':hover': {
      color: 'yellow'
    }
  }
})

// add as data attributes
<div {...rule} {...another}>
  zomg
</div>

// or as classes
<div className={`${rule} ${another}`}>
  zomg
</div>

// merge rules for great justice
let mono = css({
  fontFamily: 'monospace'
})

let bolder = css({
  fontWeight: 'bolder'
})

<div {...css(mono, bolder)}>
  bold code!
</div>

motivation

This expands on ideas from @vjeux's 2014 css-in-js talk. We introduce an api to annotate arbitrary dom nodes with style definitions ("rules") for, um, the greater good.

features

  • fast / efficient, with a fluent api
  • framework independent
  • adds vendor prefixes / fallback values
  • supports all the pseudo :classes/::elements
  • @media queries
  • @supports statements
  • @font-face / @keyframes
  • escape hatches for parent / child / contextual selectors
  • dev helper to simulate pseudo classes like :hover, etc
  • server side / static rendering
  • tests / coverage
  • experimental - write real css, with syntax highlighting and linting

(thanks to BrowserStack for providing the infrastructure that allows us to run our build in real browsers.)

docs

extras

speedy mode

there are two methods by which the library adds styles to the document -

  • by appending css 'rules' to a browser backed stylesheet. This is really fast, but has the disadvantage of making the styles uneditable in the devtools sidebar.
  • by appending text nodes to a style tag. This is fairly slow, but doesn't have the editing drawback.

as a compromise, we enable the former 'speedy' mode NODE_ENV=production, and disable it otherwise. You can manually toggle this with the speedy() function.

characteristics

while glamor shares most common attributes of other inline style / css-in-js systems, here are some key differences -

  • uses 'real' stylesheets, so you can use all css features.
  • rules can be used as data-attributes or classNames.
  • simulate pseudo-classes with the simulate helper. very useful, especially when combined when hot-loading and/or editing directly in devtools.
  • really fast, by way of deduping rules, and using insertRule in production.

todo

profit, profit

I get it