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

system-components

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

system-components

Create consistent design-system-driven React UI components

  • 2.0.0
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

system-components

Create consistent design-system-driven React UI components

Built with styled-system & styled-components

Build Status

import system from 'system-components'

// creates a Box with default props tied to your theme
const Box = system({
  p: 2,
  bg: 'blue'
})

Usage

To create a styled-component with default props that hook into styled-system props, pass a plain object as the first argument to the system function.

const Card = system({
  px: 2,
  py: 3,
  borderWidth: 1,
  borderColor: 'lightGray',
  borderRadius: 2
})

The system function will automatically apply styled-system functions to the underlying styled-component based on the keys of the defaultProps object. System components also add prop type definitions and remove style props from the underlying HTML element.

See the styled-system docs for a complete list of the available style functions.

Add style props without defaultProps

System components can also be created with styled-system props without defining defaultProps.

const Box = system(
  'space',
  'width',
  'color'
)

This allows for style props to be passed to the component instance:

<Box
  width={1/2}
  px={3}
  py={4}
  bg='blue'
/>

Using custom functions

Custom style functions can be passed as an argument.

const Box = system(
  props => ({
    height: props.height
  })
)

Changing the underlying HTML element

System components default to using a <div> as the HTML element. To change the HTML element use the is prop.

const Heading = system({
  is: 'h2',
  m: 0,
  fontSize: 6
})

Since is is a prop, it can also be passed to the element when used. This is useful for one-off changes to ensure semantic markup.

<Heading is='h1'>
  Hello
</Heading>

Extending components

System components are styled-components, so any of the built-in methods work as expected, including .extend.

const Text = system({
  fontSize: 2,
})

const Bold = Text.extend`
  font-weight: bold;
`

MIT License

Keywords

FAQs

Package last updated on 16 Feb 2018

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