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

styletron-inferno

v3.0.4

Published

Inferno bindings for Styletron

Downloads

11

Readme

styletron-inferno

Styletron bindings for Inferno.

Provider

Provider is a component that exposes a styletron instance to child components on their context.

An instance of styletron-server or styletron-client must be passed to Provider as a styletron prop.

Server-side Example

import StyletronServer from 'styletron-server';
import { Provider } from 'styletron-inferno';
import { renderToString } from 'inferno-server';
import express from 'express';
import App from './path/to/app';

function renderHMTL() {
  const styletron = new StyletronServer();
  const root = renderToString(
    <Provider styletron={styletron}>
      <App/>
    </Provider>
  );

  // NOTE: getStylesheetsHtml must be called after renderToString
  const stylesheets = styletron.getStylesheetsHtml('my-custom-class');
  return `
    <!DOCTYPE html>
    <html>
      <head>
        ${stylesheets}
      </head>
      <body>
        <div id="root">${root}</div>
      </body>
    </html>
  `;
}

const app = express();
app.get('/', (req, res) => {
  res.send(renderHMTL());
});

Client-side Example

import { render } from 'inferno';
import { Provider } from 'styletron-inferno';
import StyletronClient from 'styletron-client';
import App from './path/to/app';

const stylesheets = document.getElementsByClassName('my-custom-class');
const styletron = new StyletronClient(stylesheets);

render((
  <Provider styletron={styletron}>
    <App/>
  </Provider>
), document.getElementsById('root'));

styled(name, styles)

const StyledComponent = styled(
  name: string|function,
  styles: object|function
):VNode

name can be a string to create a styled element, or it can be a class|function component.

styles can be an object with CSS property/value pairs, or it can be a function that returns an object with CSS property/value pairs. When a function is passed, it is called with props and context.

import { styled } from 'styletron-inferno';

const StaticStyledDiv = styled('div', {
  backgroundColor: 'lightblue',
  fontSize: '12px'
});

const DynamicStyledDiv = styled('div', (props) => ({
  backgroundColor: props.alert ? 'orange' : 'lightblue',
  fontSize: '12px'
}));

const ComposedStyledDiv = styled(StaticStyledDiv, (props) => ({
  backgroundColor: props.alert ? 'red' : 'lime',
  boxShadow: '0 2px 4px darkgray'
}));

Inferno.render((
  <div>
    <StaticStyledDiv/>
    <DynamicStyledDiv alert={true}/>
    <DynamicStyledDiv alert={false}/>
    <ComposedStyledDiv alert={true}/>
    <ComposedStyledDiv alert={false}/>
  </div>
), document.getElementsById('root'));

If you want a ref to the inner DOMElement or rendered Component instance, a special innerRef prop is provided. innerRef must be a function—string refs are not supported.

NOTE: ref does not work with functional components since they are stateless.

const StyledDiv = styled('div', {
  backgroundColor: 'lightblue',
  fontSize: '12px'
});

class SomeComponent extends Component {
  componentDidMount() {
    console.log(this.styledDiv);
  }
  render() {
    return <StyledDiv innerRef={el => this.styledDiv = el}/>
  }
}