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

resplendence

v4.0.4

Published

Styling in React made easy, beautiful, and performant.

Downloads

7

Readme

Resplendence npm

Styling in React made easy, beautiful, and performant.

npm install --save resplendence

Following in the footsteps of Styled Components and Glamorous, Resplendence lets you use raw css to style your React components, right in the .js file.

import React from "react";
import rx from "resplendence";

// Put raw css in your javascript...
rx`
html {
  background: linear-gradient(to right, #ff9966, #ff5e62);
}
`;

// ... or let it generate a classname for you...
const APP_CLASSNAME = rx()`
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
`;

// ... or use styled components.
const StyledComponentTitle = rx("h1")`
  color: white;
  font-size: 150px;
  font-family: sans-serif;
`;

const App = () => (
  <div className={APP_CLASSNAME}>
    <StyledComponentTitle>Hello =)</StyledComponentTitle>
  </div>
);

export default App;

During the webpack bundle, Resplendence will auto-generate separate css files and give you back your choice of a css class or a styled component. It all happens during the build, meaning you get the benefits of css-in-js with none of the overhead during runtime.

Here's the js and css files that will get emitted to your bundle:

import React from "react";
import rx from "resplendence";

const APP_CLASSNAME = "rx-App-1";

const StyledComponentTitle = rx("h1", "rx-App-2");

const App = () => (
  <div className={APP_CLASSNAME}>
    <StyledComponentTitle>Hello =)</StyledComponentTitle>
  </div>
);

export default App;
html {
  background: linear-gradient(to right, #ff9966, #ff5e62);
}

.rx-App-1 {
  background: linear-gradient(to right, #ff9966, #ff5e62);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.rx-App-2 {
  color: white;
  font-size: 200px;
  font-family: sans-serif;
}

Setup

In your webpack.config, you'll need to configure two loaders.

The script-loader should be added to run on your script files before your other js loaders (last in the list).

The style-loader must be set up to match on resourceQuery: /resplendence=true/. Use oneOf to make sure that it is caught separately from your other rules, and add in all of your css loaders afterwards.

Here's an example of what an ejected create-react-app application looks like with this set up:

// webpack.config

module.exports = {
  // ...,
  module: {
    // ...,
    rules: [
      // ...,
      {
        oneOf: [
          // ...,
          {
            resourceQuery: /resplendence=true/,
            use: [
              ...getStyleLoaders({
                importLoaders: 1
              }),
              {
                loader: require.resolve("resplendence/style-loader"),
                options: {
                  src: paths.appSrc
                }
              }
            ]
          }
          {
            test: /\.(js|jsx)$/,
            use: [
              // ...,
              {
                loader: require.resolve("resplendence/script-loader"),
                options: {
                  src: paths.appSrc
                }
              }
            ],
            include: "./src"
          }
          // ...
        ]
        // ...
      }
    ],
    // ...
  },
};

At this point, you should be good to go!

Preprocessors

Want to use SCSS or LESS? Just make sure to throw in the appropriate loaders in your /resplendence=true/ rules.

SCSS lets you use patterns like the following:

import cx from "classnames";

rx`
$gradient: linear-gradient(to right, #ff9966, #ff5e62);
$font-size: 150px;
`;

const CLASSNAME = rx()`
  background: black;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  &.colorful {
    background: $gradient;
  }
  .title {
    color: white;
    font-size: $font-size;
    font-family: sans-serif;
  }
`;

const App = ({ colorful }) => (
  <div className={cx(CLASSNAME, { colorful })}>
    <h1 className="title">Hello =)</h1>
  </div>
);

Refs

If you need the ref to a resplendent component, pass the innerRef prop. This will turn into a ref prop if you're styling a raw html component, and otherwise pass through as innerRef for everything else. This means that refs work with nested resplendent components, as well as any other React components that ask for an innerRef.

Classnames

Assuming your css preprocessor supports it, using classes can be a powerful tool for having resplendent components handle multiple states. To this end, you can pass the rx property to any resplendent component, which will be used to set the className according to the rules of classnames.

const Component = rx("div")`
  background: black;
  &.active {
    background: red;
  }
`;

const App = ({ on, charged }) => <Component rx={{ active: on && charged }} />;

Syntax Highlighting

There is a vs code extension for syntax highlighting available at https://marketplace.visualstudio.com/items?itemName=strangerelics.vscode-resplendence.