styled component for react & style-loader/usable

Related tags

CSS react-styled
Overview

react-styled

ES7 decorator for dynamic stylesheet usage w/ webpack

Build Status

install

$ npm install bloody-react-styled --save-dev

require

import styled from "bloody-react-styled"

API

@styled(styles) class

styled is a ES7 decorator that applies useable style only if at least one instance of the component it is attached to is in mounted, and removes it when there are no more instances.

how to

first, install style-loader, css-loader and possibility the loader of your choice for a pre/post-processor.

$ npm install --save-dev style-loader css-loader

to configure webpack for that, use in your webpack.config.js :

const config = {
  // ...
  module : {
    loaders : [
      // ...
      {
        test : /\.css$/,
        loaders: [
          // use the useable to only use the stylesheet when necessary
          "style/useable",
          "css",
          // example of css processor you might want to use
          "cssnext",
        ],
      },
    ],
  },
  // ...
}

then you can do

import React, {Component} from "react"
import styled from "bloody-react-styled"

import styles from "./styles.css"

@styled(styles)
class MyComponent extends Component {

  render() {
    return (
      <div className="MyComponent">
        will be styled!
      </div>
    )
  }
}

export default MyComponent

local stylesheets with css-loader

css

:local .default {
  padding: 1rem;
}

js

import React, {Component} from "react"
import styled from "bloody-react-styled"

import styles from "./styles.css"

@styled(styles)
class MyComponent extends Component {

  render() {
    const {locals} = styles
    return (
      <div className={locals.default}>
        will be styled!
      </div>
    )
  }
}

export default MyComponent

license

You might also like...

NES-style CSS Framework | ファミコン風CSSフレームワーク

NES-style CSS Framework | ファミコン風CSSフレームワーク

日本語 / 简体中文 / Español / Português / Русский / Français NES.css is a NES-style(8bit-like) CSS Framework. Installation Styles NES.css is available via ei

Jan 5, 2023

Deploying a React App (created using create-react-app) to GitHub Pages

Deploying a React App* to GitHub Pages * created using create-react-app Introduction In this tutorial, I'll show you how I deployed a React app—which

Dec 31, 2022

A package of small but beautiful React components from the planet, Pluto. 🔵 Get minimal components for your React based applications 😍

A package of small but beautiful React components from the planet, Pluto. 🔵 Get minimal components for your React based applications 😍

React Pluto Component Design System + UI Kit A package of small but beautiful React components from the planet Pluto. To install the latest version, r

Aug 8, 2022

Semantic is a UI component framework based around useful principles from natural language.

Semantic is a UI component framework based around useful principles from natural language.

Semantic UI Semantic is a UI framework designed for theming. Key Features 50+ UI elements 3000 + CSS variables 3 Levels of variable inheritance (simil

Dec 31, 2022

Tailwind Card Component

Tailwind Card Component

Next.Js Project Name : Tailwind Card Component This is just a card commponent using tailwind css. it just awesome. Technologies Next.Js React.Js Tailw

Dec 18, 2022

Pure CSS gauge component

Pure CSS gauge v0.2 Basic gauge component made with only CSS style rules. No SVG or canvas used in this component. This component can be easily themed

Oct 7, 2021

Fluent UI web represents a collection of utilities, React components, and web components for building web applications.

Fluent UI Web 🎉 🎉 🎉 Version 8 of @fluentui/react is now available on npm! 🎉 🎉 🎉 See the release notes for more info, and please file an issue if

Jan 4, 2023

React styling. Plain and simple.

Table of Contents Install Getting Started Usage API Install npm install react-classy Getting Started Classy makes styling React components composable,

Jan 1, 2023

Use CSS-in-JavaScript with themes for React without being tightly coupled to one implementation

Use CSS-in-JavaScript with themes for React without being tightly coupled to one implementation

react-with-styles Use CSS-in-JavaScript for your React components without being tightly coupled to one implementation (e.g. Aphrodite, Radium, or Reac

Dec 8, 2022
Comments
  • Change from `componentWillMount` to `componentDidMount`

    Change from `componentWillMount` to `componentDidMount`

    So we can make this compatible with Universal JS, we must ensure the styles code aren't run on the server side. As server executes componentWillMount, the better would be to change the useability check to the componentDidMount hook on the Component's life cycle.

    opened by cusspvz 6
  • Mount/Unmount count to avoid unstyling

    Mount/Unmount count to avoid unstyling

    I was thinking on writing a decorator which would enable or disable style/usable webpack modules on mount and unmount... Guess what, you already had! 🎯 THANKS! :D

    Just one thing, this could possibly have an issue. I was thinking on having my decorator with a sort of a counter, so it would only unload styles when there aren't components mounted.

    One brief example could be a button component, you could have one on a page header, if you enter a page where you have another, it will load styles again, but if you navigate outside of that page, the button o the header would be without styling. And I don't see where you're predicting that behavior on the code yet.

    opened by cusspvz 2
Owner
Matthias Le Brun
Head of Product Design @ BeOp Front-end developer
Matthias Le Brun
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress ?? Looking for v5? The master branch is un

styled-components 38k Dec 31, 2022
700+ Pure CSS, SVG & Figma UI Icons Available in SVG Sprite, styled-components, NPM & API

700+ Pure CSS, SVG & Figma UI Icons Available in SVG Sprite, styled-components, NPM & API

Astrit Malsija 8.9k Jan 2, 2023
CSS Loader

css-loader The css-loader interprets @import and url() like import/require() and will resolve them. Getting Started To begin, you'll need to install c

webpack-contrib 4.2k Jan 2, 2023
Dropbox’s (S)CSS authoring style guide

Dropbox (S)CSS Style Guide “Every line of code should appear to be written by a single person, no matter the number of contributors.” —@mdo General Do

Dropbox 890 Jan 4, 2023
A markdown based documentation system for style guides.

Hologram Hologram is a Ruby gem that parses comments in your CSS and helps you turn them into a beautiful style guide. There are two steps to building

Trulia, LLC. 2.2k Nov 12, 2022
Easily create and maintain style guides using CSS comments

mdcss lets you easily create and maintain style guides with CSS comments using Markdown. /*--- title: Buttons section: Base CSS --- Button styles c

Jonathan Neal 679 Oct 4, 2022
[ON HOLD] Living Style Guides Engine and Maintenance Environment for Front-end Components. Core repository.

[ON HOLD] SourceJS - Living Style Guide Platform The project been stale for a while and currently is in the [ON HOLD] state until we find new maintain

SourceJS 552 Nov 8, 2022
Automatically generate a style guide from your stylesheets.

StyleDocco StyleDocco generates documentation and style guide documents from your stylesheets. Stylesheet comments will be parsed through Markdown and

Jacob Rask 1.1k Sep 24, 2022
🐒 Normalize browsers' default style

My open source work is supported by the community Special thanks to: Differences from normalize.css Smaller Includes only normalizations for the lates

Sindre Sorhus 4.8k Jan 3, 2023