npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

propane

v0.1.0

Published

Propane is a library to style your React components with the help of dynamic CSS classes

Downloads

4

Readme

Propane

npm install propane --save

Propane is a library to style your React components with the help of dynamic CSS classes.

CAUTION: this library is still in a experimental fase, don't use it in production yet!

Overview

Propane enables you to write CSS classes in a behavioral way. This means that you don't have to write several CSS classes in order to reflect how the state affects the styling. With Propane you can combine state (props, state and context) and styling in a declarative way. In order to do so, Propane uses a custom syntax that can be seen as an extension of regular css.

So what does it look like?

const styles = {
    main: `
        width: 50px;
        height: 50px;
        backgroundColor: {props.color || 'blue'}

        &:hover {
            backgroundColor: 'orange';
        }

        (props.selected) {
            border: 2px solid green;
        }

        @desktop {
            width: 100px;
            height: 100px;
        }
    `
}

@Propane(styles);
class MyComponent extends React.Component {
    render() {
        const classes = this.props.classes;
        return <div className={classes.main}><div>;
    }
}

There are already several great libraries that solve the problem of styling react components. Here you'll find a list created by the Radium team. Propane's take on the problem of component styling is to completely remove any styling logic out of the component. The component only knows which styles to apply, not how they are applied. Basicly all styling logic has moved inside of the propane CSS classes. Try to see Propane as a function:

function (styleDeclarations, {props, state, context}) {
    // Propane magic here
    return css;
}

Features

  • Seperate styling from components

    Your components will look cleaner. All logic related to styling is handled by Propane. Combined with the optional presentational props/state, fewer component re-renders are needed.

  • Native css, including browser state and media queries

    No eventlisteners, or any javascript realy, are involved

  • Define your mediaqueries once at the root of your app

  • Automatic vendor prefixing

  • Expressive syntax

  • Css properties that are used often can be replaced with mixins and constants

  • Other goodies such as shorthand syntax

Docs

Read the documentation here.

Basic usage

Place the StyleRoot component in the root of your app:

import React from 'react';
import { render } from 'react-dom';
import { StyleRoot } from 'propane';

function App() {
    return (
        <StyleRoot>
            ...
        </StyleRoot>
    );
}

render(<App />, document.getElementById('app'));

Define styles and wrap your component with Propane:

import React from 'react';;
import { Propane } from 'propane';

const styles = {
    list: '...',
    listItem: '...'
};

function List({ classes, items }) {
    const listItems = items.map(
        ({ name, id }) => <li className={classes.listItem} key={id}>{name}</li>
    );

    return (
        <ul className={classes.list}>
            {listItems}
        </ul>
    );
}

export default Propane(styles)(List);

Examples

To run the examples:

npm install
npm run example

How does Propane work?

The StyleRoot component is responsible for keeping the style tag located in the head od the document consistent with the css provided from the Propane components. It collects regular css updated from components and pushes it into the DOM at once, after a react update cycle has completed.

The Propane component is reponsible for generating css based on the dynamic context (props, state, context) and given style declarations (Propane/CSS-syntax). Basicly it converts the style declaration into a object tree containing selectors and properties using regular expressions, splits them into a dynamic and static part, and creates a function for both parts. These functions take an generated id, global depencencies from the StyleRoot (mixins, constants, mediaqueries) and components state (props, state, mixins) and will generate the css which it will provide to the StyleRoot.

Future goals

  • Support server side rendering
  • Better error logging