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

react-classed

v1.1.0

Published

Create React components with CSS classes

Downloads

17

Readme

react-classed

Build Status npm (scoped)

Create React components with CSS classes. Perfect when using a CSS framework, e.g Tailwind.

Installation

npm install --save react-classed

Usage

Create React components with CSS classes, inspired by styled-components and other styled packages.

import React from 'react';
import { render } from 'react-dom';
import classed from 'react-classed';

const Text = classed.p`text-blue-500`;

const Link = classed.a([
    'text-green-500',
    ({ href }) => ({
        'bg-red-500': href && href.startsWith('http')
    })
]);

const App = () => (
    <div>
        <Text>Blue text</Text>
        <Link>A green link</Link>
        <Link href="https://github.com">A green link with red background</Link>
    </div>
)

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

Just like a styled package you can create any html tag by using classed.X, classed[x] and classed(x).

You can also use a existing component that accepts className prop:

const Button = props => <button {...props}>{props.children}</button>;
const BlackButton = classed(Button)('bg-black');

Dynamic classnames

You can pass an object or a function that takes a object of props:

// object
const href = true;
const Link = classed.a({
  'bg-red-500': href
});

// function
const Link = classed.a(({ href }) => ({
  'bg-red-500': href && href.startsWith('http')
}));

const App = () => (
    <div>
        <Link>A green link</Link>
        <Link href="https://github.com">A green link with red background</Link>
    </div>
)

Functions can return a array of classNames:

const Link = classed.a(({ href }) => ['link', { 'bg-red-500': href && href.startsWith('http') }]);

Array of classNames

You can pass an array of classnames and allow any type of other input:

const Link = classed.a([
    'text-green-500',
    ({ href }) => ({
        'bg-red-500': href && href.startsWith('http')
    })
]);

Template string

You can also use tagged template strings:

const Text = classed.p`text-blue-500`;

And with variables:

const hasError = true;
const Error = classed.p`${hasError && 'error'}`;

And with functions to access props

const Link = classed.a`
  text-green-500
  ${({ href }) => ({
    'bg-red-500': href && href.startsWith('http')
  })}
`

You can return array, objects with true/false values and strings.

classnames package

You also support all input types of classnames.

Additional CSS

You can also add additional css and styled-components and emotion css functions or any input that are a object with styles string property or array of strings.

// template string
const Text = classed.p(`text-blue-500`, `font-weight: bold`);

// styled-components
import { css } from 'styled-components';

// css() => ['font-weight: bold']
const Text = classed.p(`text-blue-500`, css(`font-weight: bold`));

// emotion
import { css } from '@emotion/core';

// css() => { styles: 'font-weight: bold' }
const Text = classed.p(`text-blue-500`, css(`font-weight: bold`));

License

MIT © Fredrik Forsmo