• Stars
    star
    3,659
  • Rank 11,574 (Top 0.3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

inline css for react et al

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

More Repositories

1

markdown-in-js

inline markdown for react/jsx
JavaScript
788
star
2

react-act-examples

Notes and examples on ReactTestUtils.act(...)
JavaScript
517
star
3

glam

crazy good css in your js
JavaScript
504
star
4

css-suspense

css loading for react
JavaScript
310
star
5

rakt

fast websites, by default
JavaScript
292
star
6

ratpack

ready. set. go!
JavaScript
198
star
7

freezus

magic component for transitions between screens
JavaScript
188
star
8

bs-nice

css-in-reason
OCaml
182
star
9

react-modules

code splitting as a component
JavaScript
171
star
10

react-springs

react+rebound
JavaScript
91
star
11

react-tpl

abusing the platform
JavaScript
81
star
12

favre

jsx -> favicon
JavaScript
75
star
13

react-lazy-ssr-workers

react 18's streams running on cloudflare workers
JavaScript
67
star
14

react-redux-saga

react components for redux-saga
JavaScript
67
star
15

disto

mildly opinionated flux
JavaScript
65
star
16

react-ease

animations for react
JavaScript
53
star
17

glamor-stream

streaming inline glamor for your html
JavaScript
50
star
18

esjest-transform

A fast jest transform
JavaScript
45
star
19

y-workers

A Yjs backend on Cloudflare Workers
CSS
36
star
20

react-state

localized react state component
JavaScript
34
star
21

es-grid-kiss

es6 tagged literals + css grids
JavaScript
33
star
22

jsxn

jsx notation for json trees
JavaScript
32
star
23

require.import

sync-friendly code splits for webpack
JavaScript
26
star
24

react-superagent

universal ajax as a react component
JavaScript
26
star
25

react-loadscript

script tag as a react component
JavaScript
25
star
26

kv

a fast, immutable key-value store
JavaScript
24
star
27

routah

yet another router for react
JavaScript
22
star
28

iso-gol

conway's game of life, projected onto isometric 3d space in css
JavaScript
21
star
29

vite-plugin-react-jsx

A Vite plugin that enhances jsx transformation for React
TypeScript
18
star
30

glamor-inline

inlined css in your html
JavaScript
15
star
31

hotrod

JavaScript
12
star
32

babel-macros

macros for babel. I think.
12
star
33

react-router-modules

react-modules + react-router + ๐ŸŒˆ
JavaScript
12
star
34

pretty.fly

yet another async thing
JavaScript
12
star
35

proposal-error-assert

Error.assert() proposal for ECMAScript
TypeScript
11
star
36

oia

yet another lisp that compiles to javascript
JavaScript
9
star
37

xen

jsx+generators+p5.js
JavaScript
9
star
38

react-animated-web-bootleg

JavaScript
9
star
39

asyncstorage-mock

a mock for react-native's asyncstorage api. useful for testing.
JavaScript
9
star
40

falcro

falcor + react. hype!
JavaScript
7
star
41

built-devtools

chrome's devtools frontend, built.
JavaScript
7
star
42

react-debounce

debounce as a component
JavaScript
7
star
43

itree

trees with immutable.js
JavaScript
7
star
44

css-in-js-workshop

css, in your js, in your head, in your heart
JavaScript
6
star
45

max-payge

for max, because he asked
JavaScript
6
star
46

threepointone

VALUE
JavaScript
5
star
47

vite-jest

A configuration for runing jest tests inside vite
TypeScript
5
star
48

react-timing

timing as a component
JavaScript
4
star
49

twain

dynamic tweening engine
JavaScript
4
star
50

dahi

kefir, for js-csp
HTML
4
star
51

react-act-example

For Jason - https://twitter.com/CarrickJason/status/1171156605234077696
JavaScript
4
star
52

myxtape

content management systems for the new world
JavaScript
4
star
53

genno

async transforms / flow control with js-csp
JavaScript
3
star
54

riki

evil markup for documents
JavaScript
3
star
55

k

build systems, revisited
JavaScript
3
star
56

disto-example

disto examples, with hot loading of stores/views
CSS
3
star
57

prpl-with-react-example

whatevs dawg
JavaScript
2
star
58

shuffle

do the dom shuffle
JavaScript
2
star
59

progress

progress bar, alรก youtube
JavaScript
2
star
60

react-metronome

tick-tock as a component
CSS
2
star
61

bus

global event bus
JavaScript
2
star
62

vure

2
star
63

disto-hot-loader

hot load disto/flux stores
JavaScript
2
star
64

fn

tiny lib of functional helpers for personal projects
JavaScript
2
star
65

traced

JavaScript
2
star
66

times

functional times/map.
JavaScript
1
star
67

sandbox

sandboxed modules, ala YUI
JavaScript
1
star
68

iso

isometric math helpers
JavaScript
1
star
69

rust_project

Rust
1
star
70

game-of-life

generic game of life algorithm implementation in javascript
JavaScript
1
star
71

braid

experiments in clojurescript
JavaScript
1
star
72

lepton-labs-multiplayer

TypeScript
1
star
73

iso-grid

JavaScript
1
star
74

beam

funky get/set styles. WORK IN PROGRESS.
JavaScript
1
star
75

glamor-perf

HTML
1
star
76

async-act-test-21-11

Created with CodeSandbox
JavaScript
1
star
77

react-redux-optimist

react bindings for redux-optimist
JavaScript
1
star
78

zoui

HTML
1
star
79

Sangam

Static asset package generation and management
JavaScript
1
star
80

native-markup

JavaScript
1
star
81

scripts

useful (to me)
Ruby
1
star
82

oiarepl

a repl for oia
JavaScript
1
star
83

claw

css transforms without the heartache
JavaScript
1
star