New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

instyled

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instyled

React inline styled component generator

  • 0.11.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

instyled

Generate React components that automatically switch styles in response to prop changes.

Quick Start

import instyled from 'instyled'

const SomeComponent = instyled(d => {
  d({ color: 'red' }) // default style
  d(['hover'], { color: 'blue' })
  d(['deactivated'], { color: 'gray' })
  d(['hover', 'deactivated'], { color: 'lightgray' })
})

This will give you a new component SomeComponent that accepts properties hover and deactivated. It will automatically switch to the specified styling for a given combination of "truthy" property values.

So

<SomeComponent/>
// -> <div style="color:red;"></div>

<SomeComponent deactivated={true} />
// -> <div style="color:gray;"></div>

<SomeComponent hover={true} />
// -> <div style="color:blue;"></div>

<SomeComponent hover={true} deactivated={true} />
// -> <div style="color:lightgray;"></div>

instyled will figure out which style to apply for a given combination

Input Transforms

Maybe the default API seems overly verbose to you. API's are hard to get right, but don't worry, you're covered. instyled comes with two built-in input transformers and makes it pretty easy to write your own.

Each of these will give you the same results as the first example above.

Specify styles with a hierarchical map

import { instyledWithTransform, hierarchical } from 'instyled'

const instyled = instyledWithTransform(hierarchical)

const SomeComponent = instyled({
  color: 'red',
  hover: {
    color: 'blue'
  },
  deactivated: {
    color: 'gray',
    hover: {
      color: 'lightgray'
    }
  }
})

Specify styles with a flat map

import { instyledWithTransform, flatKeyed } form 'instyled'

const instyled = instyledWithTransform(flatKeyed)

const SomeComponent = instyled({
  $base: { color: 'red' },
  hover: { color: 'blue' },
  deactivated: { color: 'gray' },
  'deactivated_hover': { color: 'grayer' }
})

Keywords

FAQs

Package last updated on 29 Dec 2015

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