![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
jsx-to-styled
Advanced tools
Changelog
Readme
jsx-to-styled adds styled props to your React components
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.
All styled props injected by jsx-to-styled are prefixed by
$
symbol to prevent forwarding props to html element, check the styled-components transiant props section for more informations.
You must have react
and styled-components
already installed
npm i jsx-to-styled
# or
yarn add jsx-to-styled
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 } from 'jsx-to-styled'
// create your styled component with system props
const Box = styled.div<System>(system)
// create your theme
const 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>
)
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 {}
}
You can use breakpoints in your styled props (codesandbox example)
// add "breakpoints" key in your theme
const theme = {
colors: {
primary: 'white',
secondary: 'tomato',
},
breakpoints: {
sm: '600px',
},
}
// now you can use props with object style
return (
<Box $display="flex" $flexDirection={{ _: 'row', sm: 'column' }}>
<Box $w="200px" $h="200px">
A
</Box>
<Box $w="200px" $h="200px">
B
</Box>
</Box>
)
You can use states in your styled props (codesandbox example)
// add "states" key in your theme
const theme = {
colors: {
primary: 'white',
secondary: 'tomato',
},
states: {
hover: '&:hover',
},
}
// now you can use props with object style
return <Box $color={{ _: 'primary', hover: 'secondary' }}>Hello World!</Box>
System is composed by all of props below
JSX Property | CSS property | Theme key |
---|---|---|
$background | background | |
$backgroundImage | background-image | |
$backgroundSize | background-size | |
$backgroundPosition | background-position | |
$backgroundRepeat | background-repeat |
JSX Property | CSS property | Theme key |
---|---|---|
$border | border | |
$borderWidth | border-width | borderWidths |
$borderStyle | border-style | |
$borderColor | border-color | colors |
$borderRadius | border-radius | radii |
$borderTop | border-top | |
$borderTopWidth | border-top-width | borderWidths |
$borderTopStyle | border-top-style | |
$borderTopColor | border-top-color | colors |
$borderTopLeftRadius | border-top-left-radius | radii |
$borderTopRightRadius | border-top-right-radius | radii |
$borderRight | border-right | |
$borderRightWidth | border-right-width | borderWidths |
$borderRightStyle | border-right-style | |
$borderRightColor | border-right-color | colors |
$borderBottom | border-bottom | |
$borderBottomWidth | border-bottom-width | borderWidths |
$borderBottomStyle | border-bottom-style | |
$borderBottomColor | border-bottom-color | colors |
$borderBottomLeftRadius | border-bottom-left-radius | radii |
$borderBottomRightRadius | border-bottom-right-radius | radii |
$borderLeft | border-left | |
$borderLeftWidth | border-left-width | borderWidths |
$borderLeftStyle | border-left-style | |
$borderLeftColor | border-left-color | colors |
JSX Property | CSS property | Theme key |
---|---|---|
$backgroundColor | background-color | colors |
$color | color | colors |
$opacity | opacity |
JSX Property | CSS property | Theme key |
---|---|---|
$flex | flex | |
$alignContent | align-content | |
$alignItems | align-items | |
$alignSelf | align-self | |
$justifyContent | justify-content | |
$justifyItems | justify-items | |
$justifySelf | justify-self | |
$flexBasis | flex-basis | |
$flexDirection | flex-direction | |
$flexGrow | flex-grow | |
$flexShrink | flex-shrink | |
$flexWrap | flex-wrap | |
$order | order |
JSX Property | CSS property | Theme key |
---|---|---|
$gridGap | grid-gap | spaces |
$gridColumnGap | grid-column-gap | spaces |
$gridRowGap | grid-row-gap | spaces |
$gridColumn | grid-column | |
$gridRow | grid-row | |
$gridArea | grid-area | |
$gridAutoFlow | grid-auto-flow | |
$gridAutoColumns | grid-auto-columns | |
$gridAutoRows | grid-auto-rows | |
$gridTemplateColumns | grid-template-columns | |
$gridTemplateRows | grid-template-rows | |
$gridTemplateAreas | grid-template-areas |
JSX Property | CSS property | Theme key |
---|---|---|
$w | width | sizes |
$h | height | sizes |
$minW | min-width | sizes |
$maxW | max-width | sizes |
$minH | min-height | sizes |
$maxH | max-height | sizes |
$display | display | |
$verticalAlign | vertical-align | |
$overflow | overflow | |
$overflowX | overflow-x | |
$overflowY | overflow-y |
JSX Property | CSS property | Theme key |
---|---|---|
$position | position | |
$zIndex | z-index | |
$top | op | spaces |
$right | right | spaces |
$bottom | bottom | spaces |
$left | left | spaces |
JSX Property | CSS property | Theme key |
---|---|---|
$m | margin | spaces |
$mt | margin-top | spaces |
$mr | margin-right | spaces |
$mb | margin-bottom | spaces |
$ml | margin-left | spaces |
$my | margin-top, margin-bottom | spaces |
$mx | margin-right, margin-left | spaces |
$p | padding | spaces |
$pt | padding-top | spaces |
$pr | padding-right | spaces |
$pb | padding-bottom | spaces |
$pl | padding-left | spaces |
$py | padding-top, padding-bottom | spaces |
$px | padding-right, padding-left | spaces |
JSX Property | CSS property | Theme key |
---|---|---|
$fontFamily | font-family | fonts |
$fontSize | font-size | fontSizes |
$fontWeight | font-weight | fontWeights |
$lineHeight | line-height | lineHeights |
$letterSpacing | line-spacing | letterSpacings |
$textAlign | text-align | |
$fontStyle | font-style | |
$textDecoration | text-decoration |
JSX Property | CSS property | Theme key |
---|---|---|
$cusor | cursor | |
$float | float | |
$objectFit | object-fit | |
$objectPosition | object-position | |
$transform | transform | |
$visibility | visibility |
FAQs
jsx-to-styled adds styled props to your React components
We found that jsx-to-styled demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.