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

styled-css-modules-component

v0.1.0

Published

Build styled component with css-modules

Downloads

4

Readme

styled-css-modules-component

NPM version Build Status Dependency Status

Build styled component with css-modules

styled-component forces developers use clearer way to add styles to the components which looks great to me, but there are still some difficult unsolved issues in CSS-in-JS area, even after radium, aphrodite and a lot of libraries involved.

css-modules is a good choice for getting modularization without being as cutting-edge as the CSS-in-JS approaches. You can just write css and get full superpower from PostCSS ecosystem!

Install

$ npm install styled-css-modules-component

Note: You have to setup your own css-modules environment.

Usage

Basic

styles.css:

.title {
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
}

.wrapper {
  padding: 4em;
  background: papayawhip;
}

This creates two react components, <Title> and <Wrapper>:

import React from 'react';
import styled from 'styled-css-module-components';

import styles from './styles.css';

// Create a <Title> react component that renders an <h1> which is
// centered, palevioletred and sized at 1.5em
const Title = styled.h1(styles.title);

// Create a <Wrapper> react component that renders a <section> with
// some padding and a papayawhip background
const Wrapper = styled.section(styles.wrapper);

You render them like so:

// Use them like any other React component – except they're styled!
<Wrapper>
  <Title>Hello World, this is my first styled css modules component!</Title>
</Wrapper>

screencapture-localhost-3000-1486314996688

Checkout full examples here.

Passed props

styles.css:

.input {
  font-size: 1.25em;
  padding: 0.5em;
  margin: 0.5em;
  color: palevioletred;
  background: papayawhip;
  border: none;
  border-radius: 3px;
}

Styled components pass on all their props. This is a styled <input>:

import React from 'react';
import styled from 'styled-css-modules-components';

import styles from './styles.css';

// Create an <Input> component that'll render an <input> tag with some styles
const Input = styled.input(styles.input);

You can just pass a placeholder prop into the styled-css-modules-component. It will pass it on to the DOM node like any other react component:

// Render a styled input with a placeholder of "@chentsulin"
<Input placeholder="@chentsulin" type="text" />

2017-02-06 1 23 26

Checkout full examples here.

Third-party components

styles.css:

.link {
  color: palevioletred;
  display: block;
  margin: 0.5em 0;
  font-family: Helvetica, Arial, sans-serif;
}

The above also works perfectly for styling third-party components, like a react-router <Link />!

import styled from 'styled-components';
import { Link } from 'react-router';

const StyledLink = styled(Link)(styles.link);
<Link to="/">Standard, unstyled Link</Link>
<StyledLink to="/">This Link is styled!</StyledLink>

2017-02-07 1 50 27

Checkout full examples here.

Animations

Directly supported by CSS.

Overriding component styles & Theming

See the long discusses at css-modules #147.

React Native

Not supported.

Relevant Projects

License

MIT © C.T. Lin