🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

suit-up

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

suit-up

> css-in-js with template strings. For React.

latest
Source
npmnpm
Version
0.4.1
Version published
Maintainers
1
Created
Source

:necktie: suit-up

css-in-js with template strings. For React.

travis build version js-standard-style

Benefits

  • Scoped selectors
  • Automatic vendor prefixing
  • Support global CSS
  • All CSS features included
  • Share constants between js and styles
  • Only load the styles that a component have used
  • Easily themeable

Example

import React, {Component} from 'react'
import {render} from 'react-dom'
import suitup from 'suit-up'

// it works with CSS Modules syntax for globals
const style = `
  :global .container {
    color: red;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
  }
`

// local composes works too!
const buttonStyle = `
  .base {
    border: none;
    border-radius: 4px;
    cursor: pointer;
    padding: 10px 20px;
  }

  .default {
    composes: base;
    background-color: lightgray;
    color: black;
  }

  .primary {
    composes: base;
    background-color: blue;
    color: white;
  }
`

let Button = ({children, styles, primary, ...rest}) => {
  return (
    <button
      className={primary ? styles.primary : styles.default}
      {...rest}
    >
      {children}
    </button>
  )
}

Button = suitup(buttonStyle)(Button)

@suitup(style)
class App extends Component {
  render () {
    return (
      <div className='container'>
        <span>Red Text</span>
        <Button>Default Button</Button>
        <Button primary>Primary Button</Button>
      </div>
    )
  }
}

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

Theme Example

import React, {Component} from 'react'
import {render} from 'react-dom'
import suitup, {ThemeProvider} from 'suit-up'

const buttonStyle = theme => `
  .base {
    border: none;
    border-radius: ${theme.sizes.borderRadius}px;
    cursor: pointer;
    padding: ${theme.sizes.verticalPadding}px ${theme.sizes.horizontalPadding}px;
  }

  .default {
    composes: base;
    background-color: ${theme.colors.default};
    color: ${theme.colors.text};
  }

  .primary {
    composes: base;
    background-color: ${theme.colors.primary};
    color: ${theme.colors.invertedText};
  }
`

let Button = ({children, styles, primary, ...rest}) => {
  return (
    <button
      className={primary ? styles.primary : styles.default}
      {...rest}
    >
      {children}
    </button>
  )
}

Button = suitup(buttonStyle)(Button)

const someTheme = {
  colors: {
    default: 'lightgray',
    primary: 'darkblue',
    text: 'black',
    invertedText: 'white',
  },
  sizes: {
    borderRadius: 4,
    verticalPadding: 10,
    horizontalPadding: 20
  }
}

class App extends Component {
  render () {
    return (
      <ThemeProvider theme={someTheme}>
        <div>
          <Button>Default Button</Button>
          <Button primary>Primary Button</Button>
        </div>
      </ThemeProvider>
    )
  }
}

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

Acknowledgements

This is HIGHLY inspired by some amazing work:

Keywords

react

FAQs

Package last updated on 26 Nov 2016

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