Socket
Socket
Sign inDemoInstall

@styled-system/css

Package Overview
Dependencies
0
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @styled-system/css

Styled System for the `css` prop


Version published
Weekly downloads
496K
increased by0.9%
Maintainers
1
Install size
13.3 kB
Created
Weekly downloads
 

Package description

What is @styled-system/css?

@styled-system/css is a utility function for creating style objects based on a theme. It allows you to use a JavaScript object to define styles, which can then be applied to components. This package is part of the Styled System family and is designed to work seamlessly with other Styled System utilities.

What are @styled-system/css's main functionalities?

Theming

Theming allows you to define a set of design tokens (e.g., colors, spacing, typography) that can be referenced throughout your application. This ensures consistency and makes it easy to update the design system.

{
  "theme": {
    "colors": {
      "primary": "#07c",
      "secondary": "#05a"
    }
  },
  "styles": {
    "button": {
      "backgroundColor": "primary",
      "color": "white",
      "padding": "8px 16px",
      "borderRadius": "4px"
    }
  }
}

Responsive Styles

Responsive styles allow you to define different styles for different screen sizes using an array syntax. This makes it easy to create responsive designs without writing media queries.

{
  "styles": {
    "button": {
      "padding": ["8px 16px", "12px 24px", "16px 32px"]
    }
  }
}

Variant Styles

Variant styles allow you to define reusable style objects that can be applied to components. This is useful for creating consistent styles for different variants of a component (e.g., primary and secondary buttons).

{
  "theme": {
    "buttons": {
      "primary": {
        "backgroundColor": "primary",
        "color": "white"
      },
      "secondary": {
        "backgroundColor": "secondary",
        "color": "white"
      }
    }
  },
  "styles": {
    "button": {
      "variant": "buttons.primary"
    }
  }
}

Other packages similar to @styled-system/css

Readme

Source

@styled-system/css

Styled System for the css prop

npm i @styled-system/css

Styled System CSS lets you write style objects with responsive, theme-aware Styled System shortcuts.

// usage with the css prop
import React from 'react'
import css from '@styled-system/css'

const Beep = props =>
  <div
    {...props}
    css={css({
      fontSize: [4, 5, 6],
      color: 'primary',
    })}
  />
// usage with a styled HOC
import styled from '@emotion/styled'
import css from '@styled-system/css'

const Boop = styled('div')(
  css({
    fontSize: [ 4, 5, 6 ],
    color: 'primary',
    bg: 'gray',
    '&:hover': {
      color: 'secondary',
    },
  })
)

Theme Keys

The following keys in your style object will work the same as Styled System props, pulling values from your theme object.

PropertyTheme Key
fontFamilyfonts
fontSizefontSizes
fontWeightfontWeights
lineHeightlineHeights
letterSpacingletterSpacings
colorcolors
backgroundColor, bgcolors
margin, mspace
marginTop, mtspace
marginRight, mrspace
marginBottom, mbspace
marginLeft, mlspace
marginX, mxspace
marginY, myspace
padding, pspace
paddingTop, ptspace
paddingRight, prspace
paddingBottom, pbspace
paddingLeft, plspace
paddingX, pxspace
paddingY, pyspace
borderborders
borderTopborders
borderRightborders
borderBottomborders
borderLeftborders
borderColorcolors
borderWidthborderWidths
borderStyleborderStyles
borderRadiusradii
boxShadowshadows
zIndexzIndices
widthsizes
minWidthsizes
maxWidthsizes
heightsizes
minHeightsizes
maxHeightsizes

Responsive Arrays

All CSS properties accept arrays as values for responsive styles.

<div
  css={css({
    fontSize: [ 4, 5, 6 ],
  })}
/>

In this example, fontSize accepts an array, picking up values from the theme.fontSizes scale, and borderBottom is passed through as plain CSS.

<div
  css={css({
    // Styled System key
    fontSize: [ 3, 4, 5 ],
    // CSS property
    borderBottom: '2px solid tomato',
  })}
/>

MIT License

Keywords

FAQs

Last updated on 28 May 2019

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc