Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

styled-when

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

styled-when

Easily declare prop-based conditions when using styled components.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

styled-when

Easily declare prop-based conditions when using styled components.

Compatible with styled-components and emotion.

Install

npm i styled-when

Usage

Select when prop's value is truthy. Use for simple checks.

import when from 'styled-when'

const Button = styled.button`
    font-weight: normal;

    ${when('important')} {
        font-weight: bold;
    }
`

Select when callback returns a truthy value. Use for more complex or multiple conditions.

import when from 'styled-when'

const Button = styled.button`
    color: white;
    background: cornflowerblue;
    border: 1px solid cornflowerblue;

    ${when(props => props.variant === 'secondary')} {
        color: cornflowerblue;
        background: white;
    }
`

Select when value is true or false. Use for constant conditions.

import when from 'styled-when'

const Button = styled.button`
    font-weight: regular;

    ${when(window.EMBEDDED_IN_ANDROID_APP)} {
        font-weight: bold;
        text-transform: uppercase;
    }
`

API

when(prop: string) => (props: Props) => string
when(callback: Function) => (props: Props) => string
when(condition: boolean) => string

Keywords

FAQs

Package last updated on 18 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc