All Projects → andreypopp → React Css Components

andreypopp / React Css Components

Define React presentational components with CSS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Css Components

React Ssr Setup
React Starter Project with Webpack 4, Babel 7, TypeScript, CSS Modules, Server Side Rendering, i18n and some more niceties
Stars: ✭ 678 (-1.6%)
Mutual labels:  webpack, css-modules
Seek Style Guide
Living style guide for SEEK, powered by React, webpack, CSS Modules and Less.
Stars: ✭ 302 (-56.17%)
Mutual labels:  webpack, css-modules
React
Extremely simple boilerplate, easiest you can find, for React application including all the necessary tools: Flow | React 16 | redux | babel 6 | webpack 3 | css-modules | jest | enzyme | express + optional: sass/scss
Stars: ✭ 244 (-64.59%)
Mutual labels:  webpack, css-modules
Typescript Webpack React Redux Boilerplate
React and Redux with TypeScript
Stars: ✭ 182 (-73.58%)
Mutual labels:  webpack, css-modules
Sku
Front-end development toolkit
Stars: ✭ 403 (-41.51%)
Mutual labels:  webpack, css-modules
Front End Guide
📚 Study guide and introduction to the modern front end stack.
Stars: ✭ 14,073 (+1942.53%)
Mutual labels:  webpack, css-modules
linaria-styled
Zero-runtime CSS in JS library for building React components
Stars: ✭ 17 (-97.53%)
Mutual labels:  css-modules, css-in-js
Breko Hub
Babel React Koa Hot Universal Boilerplate
Stars: ✭ 145 (-78.96%)
Mutual labels:  webpack, css-modules
Reshadow
Markup and styles that feel right
Stars: ✭ 343 (-50.22%)
Mutual labels:  css-in-js, css-modules
Kratos Boilerplate
🔥 A simple boilerplate for creating statics PWA using Webpack, Pug, PostCSS and CSS Modules
Stars: ✭ 308 (-55.3%)
Mutual labels:  webpack, css-modules
Css Modules Typescript Loader
Webpack loader to create TypeScript declarations for CSS Modules
Stars: ✭ 172 (-75.04%)
Mutual labels:  webpack, css-modules
Nyancss
🌈 Write plain CSS while reaping benefits of CSS-in-JS
Stars: ✭ 544 (-21.04%)
Mutual labels:  webpack, css-modules
React Redux Universal Boilerplate
An Universal ReactJS/Redux Boilerplate
Stars: ✭ 165 (-76.05%)
Mutual labels:  webpack, css-modules
Modular Css
A streamlined reinterpretation of CSS Modules via CLI, API, Browserify, Rollup, Webpack, or PostCSS
Stars: ✭ 234 (-66.04%)
Mutual labels:  webpack, css-modules
Es Css Modules
PostCSS plugin that combines CSS Modules and ES Imports
Stars: ✭ 165 (-76.05%)
Mutual labels:  webpack, css-modules
jess
If you like CSS, Less, Sass, and/or CSS modules, you're gonna want to star this repo.
Stars: ✭ 26 (-96.23%)
Mutual labels:  css-modules, css-in-js
React Pages Boilerplate
Deliver react + react-router application to gh-pages
Stars: ✭ 134 (-80.55%)
Mutual labels:  webpack, css-modules
Dev Toolkit
Universal Development Toolkit for Javascript People
Stars: ✭ 134 (-80.55%)
Mutual labels:  webpack, css-modules
React Redux Boilerplate
Awesome React Redux Workflow Boilerplate with Webpack 4
Stars: ✭ 307 (-55.44%)
Mutual labels:  webpack, css-modules
Augur Ui
Augur UI
Stars: ✭ 412 (-40.2%)
Mutual labels:  webpack, css-modules

React CSS components

Join the chat at https://gitter.im/andreypopp/react-css-components Travis build status npm

Table of Contents

Motivation

Define React presentational components with CSS (or even SASS or Less if you like).

The implementation is based on CSS modules. In fact React CSS Components is just a thin API on top of CSS modules.

NOTE: The current implementation is based on Webpack but everything is ready to be ported onto other build systems (generic API is here just not yet documented). Raise an issue or better submit a PR if you have some ideas.

Installation & Usage

Install from npm:

% npm install react-css-components style-loader css-loader

Configure in webpack.config.js:

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.react.css$/,
        loader: 'react-css-components',
      }
    ]
  }
  ...
}

Now you can author React components in Styles.react.css:

Label {
  color: red;
}

Label:hover {
  color: white;
}

And consume them like regular React components:

import {Label} from './styles.react.css'

<Label /> // => <div class="<autogenerated classname>">...</div>

Base components

DOM components

By default React CSS Components produces styled <div /> components. You can change that by defining base: property:

FancyButton {
  base: button;
  color: red;
}

Now <FancyButton /> renders into <button />:

import {FancyButton} from './styles.react.css'

<FancyButton /> // => <button class="<autogenerated classname>">...</button>

Composite components

In fact any React component which accepts className props can be used as a base. That means that React CSS Components can be used as theming tool for any UI library.

Example:

DangerButton {
  base: react-ui-library/components/Button;
  color: red;
}

Variants

Variants is a mechanism which allows defining component styling variants.

Named variants

You can define additional styling variants for your components:

Label {
  color: red;
}

Label:emphasis {
  font-weight: bold;
}

They are compiled as CSS classes which then can be controlled from JS via variant prop:

<Label variant={{emphasis: true}} /> // sets both classes with `color` and `font-weight`

JavaScript expressions

You can define variants which are conditionally applied if JS expression against props evaluates to a truthy value.

Example:

Label {
  color: red;
}

Label:prop(mode == "emphasis") {
  font-weight: bold;
}

Note that any free variable references a member of props, thus in JS mode becomes props.mode in the example above.

They are compiled as CSS classes as well. JS expressions within prop(..) are used to determine if corresponding CSS classes should be applied to DOM:

<Label mode="emphasis" /> // sets both classes with `color` and `font-weight`

Customizing CSS loading

By default React CSS components loads CSS using style-loader!css-loader loader chain. That could be configured differently using loadCSS loader parameter.

This could be used to enable features such as CSS extraction, processing stylesheets with PostCSS/Autoprefixer or even authoring stylesheets with SASS or LESS.

CSS extraction

See the complete example which configures extract-text-webpack-plugin to extract stylesheets to a separate chunk.

Using with SASS/SCSS/LESS/Stylus/...

See the complete example which uses SASS/SCSS to create React components.

Using with PostCSS (including autoprefixer)

See the complete example which configures PostCSS with Autoprefixer to automatically add vendor prefixes to stylesheets.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].