Socket
Socket
Sign inDemoInstall

jsx-to-styled

Package Overview
Dependencies
82
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jsx-to-styled

jsx-to-styled adds styled props to your React components


Version published
Weekly downloads
4
increased by300%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

1.2.0

6 July 2022

Readme

Source

JSX to Styled

jsx-to-styled adds styled props to your React components

📝 What it is ?

Inspired by xstyled and styled-system, jsx-to-styled adds styled props to your React styled-components. The main idea of this library is to stay really simple and performant :

  • no responsive helpers
  • no states helpers (hover, focus...)
  • string is the only valid type for the value of styled props
  • no dependencies

If you want to add some responsives or states style, you have to do it inside a styled-component

🔧 Installation

You must have react and styled-components already installed

npm i jsx-to-styled
# or
yarn add jsx-to-styled

💻 Usage

You can use jsx-to-styled without theme (codesandbox example)

import styled from 'styled-components'
import system from 'jsx-to-styled'

// create your styled component with system props
const Box = styled.div(system)

// now you can use all jsx-to-styled props
return (
  <Box color="white" backgroundColor="tomato" p="30px" borderRadius="50%">
    Hello World!
  </Box>
)

Or use with a theme to use custom values (codesandbox example)

import styled, { ThemeProvider } from 'styled-components'
import system, { System, Theme } from 'jsx-to-styled'

// create your styled component with system props
const Box = styled.div<System>(system)

// create your theme
const theme: Theme = {
  colors: {
    primary: 'white',
    secondary: 'tomato',
  },
  spaces: {
    xl: '30px',
  },
  radii: {
    half: '50%',
  },
}

// now you can use all jsx-to-styled props with theme values
return (
  <ThemeProvider theme={theme}>
    <Box color="primary" backgroundColor="secondary" p="xl" borderRadius="half">
      Hello World!
    </Box>
  </ThemeProvider>
)

✨ Typescript

Thanks to csstype, jsx-to-styled is fully typed. You will have autocomplete for all possible css values.

import system, { System } from 'jsx-to-styled'

// don't forget to add System type to your styled-component definition
const Box = styled.div<System>(system)

If you want to access to your theme values, you have to redefine "Theme" interface with your custom theme like that:

// theme.d.ts
import 'jsx-to-styled'
import { theme } from './theme'

type MyTheme = typeof theme

declare module 'jsx-to-styled' {
  export interface Theme extends MyTheme {}
}

📕 Props

System is composed by all of props below

Background

JSX PropertyCSS propertyTheme key
backgroundbackground
backgroundImagebackground-image
backgroundSizebackground-size
backgroundPositionbackground-position
backgroundRepeatbackground-repeat

Border

JSX PropertyCSS propertyTheme key
borderborder
borderWidthborder-widthborderWidths
borderStyleborder-style
borderColorborder-colorcolors
borderRadiusborder-radiusradii
borderTopborder-top
borderTopWidthborder-top-widthborderWidths
borderTopStyleborder-top-style
borderTopColorborder-top-colorcolors
borderTopLeftRadiusborder-top-left-radiusradii
borderTopRightRadiusborder-top-right-radiusradii
borderRightborder-right
borderRightWidthborder-right-widthborderWidths
borderRightStyleborder-right-style
borderRightColorborder-right-colorcolors
borderBottomborder-bottom
borderBottomWidthborder-bottom-widthborderWidths
borderBottomStyleborder-bottom-style
borderBottomColorborder-bottom-colorcolors
borderBottomLeftRadiusborder-bottom-left-radiusradii
borderBottomRightRadiusborder-bottom-right-radiusradii
borderLeftborder-left
borderLeftWidthborder-left-widthborderWidths
borderLeftStyleborder-left-style
borderLeftColorborder-left-colorcolors

Color

JSX PropertyCSS propertyTheme key
backgroundColorbackground-colorcolors
colorcolorcolors
opacityopacity

Flex

JSX PropertyCSS propertyTheme key
flexflex
alignContentalign-content
alignItemsalign-items
alignSelfalign-self
justifyContentjustify-content
justifyItemsjustify-items
justifySelfjustify-self
flexBasisflex-basis
flexDirectionflex-direction
flexGrowflex-grow
flexShrinkflex-shrink
flexWrapflex-wrap
orderorder

Grid

JSX PropertyCSS propertyTheme key
gridGapgrid-gapspaces
gridColumnGapgrid-column-gapspaces
gridRowGapgrid-row-gapspaces
gridColumngrid-column
gridRowgrid-row
gridAreagrid-area
gridAutoFlowgrid-auto-flow
gridAutoColumnsgrid-auto-columns
gridAutoRowsgrid-auto-rows
gridTemplateColumnsgrid-template-columns
gridTemplateRowsgrid-template-rows
gridTemplateAreasgrid-template-areas

Layout

JSX PropertyCSS propertyTheme key
wwidthsizes
hheightsizes
minWmin-widthsizes
maxWmax-widthsizes
minHmin-heightsizes
maxHmax-heightsizes
displaydisplay
verticalAlignvertical-align
overflowoverflow
overflowXoverflow-x
overflowYoverflow-y

Position

JSX PropertyCSS propertyTheme key
positionposition
zIndexz-index
topopspaces
rightrightspaces
bottombottomspaces
leftleftspaces

Space

JSX PropertyCSS propertyTheme key
mmarginspaces
mtmargin-topspaces
mrmargin-rightspaces
mbmargin-bottomspaces
mlmargin-leftspaces
mymargin-top, margin-bottomspaces
mxmargin-right, margin-leftspaces
ppaddingspaces
ptpadding-topspaces
prpadding-rightspaces
pbpadding-bottomspaces
plpadding-leftspaces
pypadding-top, padding-bottomspaces
pxpadding-right, padding-leftspaces

Typography

JSX PropertyCSS propertyTheme key
fontFamilyfont-familyfonts
fontSizefont-sizefontSizes
fontWeightfont-weightfontWeights
lineHeightline-heightlineHeights
letterSpacingline-spacingletterSpacings
textAligntext-align
fontStylefont-style
textDecorationtext-decoration

Other

JSX PropertyCSS propertyTheme key
cusorcursor
floatfloat
objectFitobject-fit
objectPositionobject-position
transformtransform
visibilityvisibility

Keywords

FAQs

Last updated on 06 Jul 2022

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc