New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@ustyle/styled

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ustyle/styled

STATUS: Moved to [@slimr/styled](https://www.npmjs.com/package/@slimr/styled)

latest
Source
npmnpm
Version
1.0.40
Version published
Maintainers
1
Created
Source

@ustyle/styled

STATUS: Moved to @slimr/styled

A tiny (2kb) React css-in-js library inspired by chakra-ui, emotion, and styled-components libs

Demos: See ./packages/demo or CodeSandbox

Sister libs:

  • @ustyle/css

Pros:

  • Much less bundle size and runtime sluggishness

  • Less is more: less bugs, no breaking changes

  • Supports declaring css and styled components inside of Components for better code colocating and NO MORE NEED TO PASS ARGS!

  • Styled shortcuts like styled.div when imported from @ustyle/styled/withHtmlTags. Note: To get types you'll need tsconfig:moduleResolution >= Node16

  • Zx/Css shorthand props like chakra-ui:

    • Pass shorthand props or zx props to styled components. This lib will create css classes if complex, passthrough as styles otherwise.
    • m --> margin
    • mx --> margin-left and right
    • py --> padding-top and bottom
    • More here!
  • CSS Breakpoints shorthand like chakra-ui:

    margin: [auto, null, inherit];
    /* Translates to */
    margin: auto;
    @media (min-width: 48em) {
      margin: inherit;
    }
    
    • Breakpoints are [30em, 48em, 62em, 80em, 96em]

Cons:

  • No SSR support

Setup/Install

npm i @ustyle/styled

Usage

Preview below. For full code, see demos

// Create primitive components if you like
const Box = styled.div`
  pos: relative;
`

interface ButtonProps extends Omit<HtmlTagProps['button'], 'id'> {
  id: HtmlTagProps['button']['id'] // make required
}
function Button(props: ButtonProps) {
  return (
    <button
      {...props}
      onClick={(e) => {
        console.log(`Button ${props.id} clicked`)
        props.onClick?.(e)
      }}
    />
  )
}
const ButtonP = styled(Button)`
  bg: red;
  c: white;
  w: [100%, null, inherit];
`

export function App() {
  const on = useOscillator()

  return (
    <Box
      // enjoy chakra-ui like shorthand syntax
      bg={['lightblue', null, 'lightred']}
    >
      <ButtonP
        // use css if you'd like, which gets converted into a css class and attached to this element
        css={`
          --font-weight: [bold, null, initial];
        `}
        id="my-button"
        // kinda like style but accepts shorthand syntax
        _zx={{
          textTransform: on ? 'uppercase' : 'inherit',
        }}
        // Any attr with '_' prefix will be passed to zx
        _fontWeight="var(--font-weight)"
        // like _zx, but applies only on :hover
        _hover={{ bg: 'lightblue' }}
        // like _zx, but applies only on :active
        _active={{ bg: 'lightblue' }}
        // like _zx, but applies only when browser prefers dark modes
        _dark={{ bg: 'lightblue' }}
      >
        Click me!
      </ButtonP>
    </Box>
  )
}

Comparisons

Chakra-UI

  • A popular css-in-js lib that inspired this lib

Pros

  • More mature, SSR support
  • Premade components

Cons

  • Is crazy large bundle impact (80+kb)

Styled-Components

  • A popular css-in-js lib that inspired this lib

Pros

  • More mature, SSR support

Cons

  • Is massive (~12kb), plus has dependency on emotion (~11kb)
  • Does not support zx prop or css shorthand props

Emotion

  • A popular css-in-js lib similar to styled-components

Pros

  • More mature, SSR support

Cons

  • Is large (>10kb)
  • Many features require addons, which make bundle even larger
  • Does not support zx prop or css shorthand props

Goober

  • another tiny 1kb styled-components like css-in-js

Pros:

  • More mature, SSR support

Cons:

  • Many features require addons, which in sum may make the bundle larger than ustyle
  • Does not support zx prop or css shorthand props

Keywords

chakra

FAQs

Package last updated on 09 Feb 2023

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