Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Critical | 9,722 | 1,162 | 121 | 2 months ago | 92 | September 16, 2022 | 35 | apache-2.0 | JavaScript | |
Extract & Inline Critical-path CSS in HTML pages | ||||||||||
Radium | 7,442 | 5,009 | 717 | 10 months ago | 73 | March 02, 2022 | 83 | mit | JavaScript | |
A toolchain for React component styling. | ||||||||||
Csstoinlinestyles | 5,702 | 48,054 | 214 | 7 days ago | 23 | December 08, 2021 | 31 | bsd-3-clause | PHP | |
CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very usefull when you're sending emails. | ||||||||||
Reactcss | 1,574 | 3,818 | 179 | 3 years ago | 26 | September 07, 2017 | 6 | mit | JavaScript | |
:lipstick: Inline Styles in JS | ||||||||||
Responsive Html Email Signature | 741 | 21 days ago | 16 | March 29, 2022 | 10 | mit | HTML | |||
✨ Template generator for (responsive) emails & email signatures | ||||||||||
Material Auto Rotating Carousel | 432 | 54 | 5 | 3 months ago | 28 | August 21, 2019 | 31 | mit | JavaScript | |
Introduce users to your app with this Material-style carousel. | ||||||||||
Reactscrollbar | 419 | 285 | 80 | 3 years ago | 22 | April 18, 2019 | 58 | mit | JavaScript | |
Scrollbar component for React | ||||||||||
Unistyle | 316 | 6 | 8 | 7 years ago | 9 | January 27, 2016 | 2 | JavaScript | ||
Write modular and scalable CSS using the next version of ECMAScript | ||||||||||
Babel Plugin Css In Js | 295 | 27 | 5 | 6 years ago | 15 | January 22, 2017 | 6 | mit | JavaScript | |
A plugin for Babel v6 which transforms inline styles defined in JavaScript modules into class names so they become available to, e.g. the `className` prop of React elements. While transforming, the plugin processes all JavaScript style definitions found and bundles them up into a CSS file, ready to be requested from your web server. | ||||||||||
Material Ui Image | 213 | 72 | 21 | 6 months ago | 33 | April 24, 2021 | 26 | mit | JavaScript | |
Material style image with loading animation |
yarn add radium
# or
npm install --save radium
Radium is a set of tools to manage inline styles on React elements. It gives you powerful styling capabilities without CSS.
Inspired by React: CSS in JS by vjeux.
Archived: This project is no longer maintained by Formidable. We are no longer responding to issues or pull requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!
Eliminating CSS in favor of inline styles that are computed on the fly is a powerful approach, providing a number of benefits over traditional CSS:
Despite that, there are some common CSS features and techniques that inline styles don't easily accommodate: media queries, browser states (:hover, :focus, :active) and modifiers (no more .btn-primary!). Radium offers a standard interface and abstractions for dealing with these problems.
When we say expressive, we mean it: math, concatenation, regex, conditionals, functions–JavaScript is at your disposal. Modern web applications demand that the display changes when data changes, and Radium is here to help.
For a short technical explanation, see How does Radium work?.
:hover
, :focus
, and :active
createClass
supportStart by wrapping your component class with Radium()
, like export default Radium(Component)
, or Component = Radium(Component)
, which works with classes, createClass
, and stateless components (functions that take props and return a ReactElement). Then, write a style object as you normally would with inline styles, and add in styles for interactive states and media queries. Pass the style object to your component via style={...}
and let Radium do the rest!
<Button kind="primary">Radium Button</Button>
import Radium from 'radium';
import React from 'react';
import color from 'color';
class Button extends React.Component {
static propTypes = {
kind: PropTypes.oneOf(['primary', 'warning']).isRequired
};
render() {
// Radium extends the style attribute to accept an array. It will merge
// the styles in order. We use this feature here to apply the primary
// or warning styles depending on the value of the `kind` prop. Since its
// all just JavaScript, you can use whatever logic you want to decide which
// styles are applied (props, state, context, etc).
return (
<button style={[styles.base, styles[this.props.kind]]}>
{this.props.children}
</button>
);
}
}
Button = Radium(Button);
// You can create your style objects dynamically or share them for
// every instance of the component.
var styles = {
base: {
color: '#fff',
// Adding interactive state couldn't be easier! Add a special key to your
// style object (:hover, :focus, :active, or @media) with the additional rules.
':hover': {
background: color('#0074d9')
.lighten(0.2)
.hexString()
}
},
primary: {
background: '#0074D9'
},
warning: {
background: '#FF4136'
}
};
As of v0.22.x
, Radium is built as an ECMAScript Modules-first project. We now have a package.json:module
entry pointing to our library files with import|export
statements instead of CommonJS require
s. We still support CommonJS require
s with a special package.json:main
entry pointing to root index.js
to smooth over this transition. The basic takeaways are:
If you are using ESM with webpack or @std/esm
with Node.js, imports like the following work fine without any gotchas:
import Radium from 'radium';
import Radium, {Style} from 'radium';
If you are using CommonJS with Node.js or [email protected] requires work like normal:
const Radium = require('radium');
const {Style} = require('radium');
If you are using CommonJS with [email protected]+, however, you must instead add .default
to the root Radium
object import:
const Radium = require('radium').default; // CHANGED: Must add `.default`
const {Style} = require('radium'); // Works as per normal
If you cannot change the require
statements directly (say Radium is included from a different library your project depends on) you can manually tweak the Radium import in your project's webpack configuration with the following:
resolve: {
alias: {
radium: require.resolve('radium/index');
}
}
which will allow const Radium = require('radium');
to still work. The configuration effectively forces webpack to point to code from package.json:main
(which points to /index.js
) instead of what is in package.json:module
.
Note: Radium uses Reflect
which is not supported in IE11. You will need to bring in a polyfill like CoreJs in order to support <IE11.
To see the universal examples:
npm install
npm run universal
To see local client-side only examples in action, do this:
npm install
npm run examples
Following is a short technical explanation of Radium's inner workings:
render
functionrender
onMouseEnter
for :hover
, wrapping existing handlers if necessarysetState
to update a Radium-specific field on the components state object:hover
, by looking up the element's key or ref in the Radium-specific stateYou can find a list of other tools, components, and frameworks to help you build with Radium on our wiki. Contributions welcome!
Please see CONTRIBUTING