Giter Site home page Giter Site logo

styled-property's Introduction

styledProperty

npm version Build Status Coverage Status

styled-components helper that generates a set of styles and sets the auto-generated className for them as property on a wrapped component.

Installation

npm install styled-property

Usage

import styledProperty from 'styled-property'

// auto-generates a class selector for the given css and sets it
// as "propName" property on the WrappedComponent.
const Component = styledProperty(WrappedComponent, 'propName')`
  display: block;
`

Use Cases

react-router Link

Set default and active styles of Link component from react-router.

import { Link } from 'react-router'
import styled from 'styled-components'
import styledProperty from 'styled-property'

// create basic Link styles
const BaseLink = styled(Link)`
  color: #aaa;
  display: inline-block;
  text-decoration: none;
`

// create an additional set of style rules and set the "activeClassName"
// property of the wrapped component (BaseLink) to the auto-generated
// className for those styles.
const StyledLink = styledProperty(BaseLink, 'activeClassName')`
  color: #bada55;
`

react-sticky Sticky

Set default and sticky styles of Sticky component from react-sticky.

import { Sticky } from 'react-sticky'
import styled from 'styled-components'
import styledProperty from 'styled-property'

// create basic Sticky styles
const BaseSticky = styled(Sticky)`
  margin-top: 0;
  transition: margin-top .3s ease-in-out;
`

// create an additional set of style rules and set the "stickyClassName"
// property of the wrapped component (BaseSticky) to the auto-generated
// className for those styles.
const StyledSticky = styledProperty(BaseSticky, 'stickyClassName')`
  margin-top: 16px;
`

styled-property's People

Contributors

codepunkt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.