All Projects → pluralsight → React Styleable

pluralsight / React Styleable

Licence: mit
React Component for portable styles

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Styleable

Rollup Plugin Styles
🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
Stars: ✭ 116 (-45.79%)
Mutual labels:  css-modules
Breko Hub
Babel React Koa Hot Universal Boilerplate
Stars: ✭ 145 (-32.24%)
Mutual labels:  css-modules
Typed Scss Modules
🎁 Generate type definitions (.d.ts) for CSS Modules using SCSS
Stars: ✭ 192 (-10.28%)
Mutual labels:  css-modules
React Boilerplate
React Boilerplate
Stars: ✭ 128 (-40.19%)
Mutual labels:  css-modules
React Starter Boilerplate Hmr
React starter boilerplate with React Fast Refresh, React 17 and Webpack 5
Stars: ✭ 137 (-35.98%)
Mutual labels:  css-modules
React Redux Universal Boilerplate
An Universal ReactJS/Redux Boilerplate
Stars: ✭ 165 (-22.9%)
Mutual labels:  css-modules
Universal React Redux
🧐 A sensible universal starter kit for React + Redux
Stars: ✭ 112 (-47.66%)
Mutual labels:  css-modules
Front End Guide
📚 Study guide and introduction to the modern front end stack.
Stars: ✭ 14,073 (+6476.17%)
Mutual labels:  css-modules
Gaikan
Declarative view styling in Swift. Inspired by CSS modules.
Stars: ✭ 139 (-35.05%)
Mutual labels:  css-modules
Typescript Webpack React Redux Boilerplate
React and Redux with TypeScript
Stars: ✭ 182 (-14.95%)
Mutual labels:  css-modules
Nextjs Ts
Opinionated Next JS project boilerplate with TypeScript and Redux
Stars: ✭ 134 (-37.38%)
Mutual labels:  css-modules
Dev Toolkit
Universal Development Toolkit for Javascript People
Stars: ✭ 134 (-37.38%)
Mutual labels:  css-modules
Babel Plugin React Css Modules
Transforms styleName to className using compile time CSS module resolution.
Stars: ✭ 1,989 (+829.44%)
Mutual labels:  css-modules
React Typescript Webpack2 Cssmodules Postcss
Simple Starter Template for React, TypeScript, postCSS, ITCSS, CSS-Modules, Webpack and Live Reloading (React Hot Loader 3)
Stars: ✭ 117 (-45.33%)
Mutual labels:  css-modules
Micron
a [μ] microInteraction library built with CSS Animations and controlled by JavaScript Power
Stars: ✭ 2,252 (+952.34%)
Mutual labels:  css-modules
Eslint Plugin Css Modules
Project status: NOT MAINTAINED; Checks that you are using the existent css/scss classes, no more no less
Stars: ✭ 115 (-46.26%)
Mutual labels:  css-modules
Es Css Modules
PostCSS plugin that combines CSS Modules and ES Imports
Stars: ✭ 165 (-22.9%)
Mutual labels:  css-modules
React Native Css Modules
Style React Native components using CSS, PostCSS, Sass, Less or Stylus.
Stars: ✭ 207 (-3.27%)
Mutual labels:  css-modules
Holy Grail Markup
All CSS methodologies compared examples at one place.
Stars: ✭ 197 (-7.94%)
Mutual labels:  css-modules
Css Modules Typescript Loader
Webpack loader to create TypeScript declarations for CSS Modules
Stars: ✭ 172 (-19.63%)
Mutual labels:  css-modules

react-styleable

Consistent, easy overrides for CSS Modules in React Components

Install

npm install react-styleable --save-dev

Usage

Styles in Props

react-styleable makes your styles from your CSS modules available on props.css.

Write your stylesheet with all the perks of css modules. For example:

.list {
  list-style: none;
  padding-left: 0;
  margin: 10px;
}
.item {
  outline: 1px solid red;
  padding: 10px;
}

Then in your reusable component, wrap your React.Component in react-styleable's higher-order component.

import styleable from 'react-styleable'

import css from './my-list.css'

class MyList extends React.Component {
  renderItem(item, i) {
    return (
      <li key={i} className={this.props.css.item}>{item}</li>
    )
  }
  renderList(items) {
    return items.map(this.renderItem)
  }
  render() {
    return (
      <ul className={this.props.css.list}>
        {this.renderList(this.props.items)}
      </ul>
    )
  }
}

export default styleable(css)(MyList)

Usage as a decorator is also nice:

@styleable(css)
class MyList extends React.Component { /* ... */ }

Your MyList component is now styled and ready to display!

Overriding Component Styles

This is the big payoff.

If you want to override this component's styles as the consumer, you can easily do so, through the same, consistent interface. First, define a new stylesheet:

.item {
  outline: 1px solid blue;
}

And use it to render MyList again, passing your new stylesheet via the props.css prop:

import MyList from './my-list'

import css from './client.css'

React.render(<MyList css={css} />, document.getElementById('app'))

Now the .items outline will be blue instead of the original red.

Composing Component Styles

If instead of just overriding the styles, you wanted to add to them with style composition, you can do that as well.

One method is via CSS modules' composes keyword. In your new stylesheet:

.item {
  composes: item from "./my-list.css";
  background: pink;
}

Now the original red outline will remain and a pink background will be present as well. This is the most surefire way to compose styles because it allows you to guarantee the order of the cascade.

But it has the downside of having to locate the original stylesheet location.

If you have enough assurances on the cascade order and selector specificity, all potential concerns, you can use the compose api via the react-styleable to accomplish the same thing (in [email protected]):

import MyList from './my-list'

import css from './client.css'

React.render(<MyList css={{ compose: css }} />, document.getElementById('app'))

Styled. Portable. Easily overridden. So, so good.

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].