You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@css-system/use-css

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@css-system/use-css

A react hook for building versatile design primitives.

0.2.0
Source
npmnpm
Version published
Weekly downloads
5
Maintainers
2
Weekly downloads
 
Created
Source

css-system/use-css

A react hook for building versatile design primitives.

Example

import React, {createContext, useContext} from "react"
import ReactDOM from "react-dom"
import {useCss} from "@css-system/use-css"

const theme = {
  breakpoints: ["40em", "52em", "64em"],
  colors: {
    background: "#ffffff",
    text: "#000000",
    primary: "#ff0000",
  },
  space: [0, 4, 8, 16, 32],
  fontSizes: [0, 12, 14, 16, 20, 24, 32, 48, 64, 72],
}

const ThemeContext = createContext(theme)

const View = ({as: Component = "div", css, ...props}) => {
  const theme = useContext(ThemeContext)
  const className = useCss(
    {
      display: "flex",
      minWidth: 0,
      minHeight: 0,
      flex: "none",
      alignSelf: "auto",
      alignItems: "stretch",
      flexDirection: "column",
      justifyContent: "flex-start",
      ...css,
    },
    theme
  )

  return <Component className={className} {...props} />
}

const Text = ({as: Component = "span", css, ...props}) => {
  const theme = useContext(ThemeContext)
  const className = useCss(
    {
      display: "inline-flex",
      minWidth: 0,
      minHeight: 0,
      flex: "none",
      alignSelf: "auto",
      alignItems: "stretch",
      flexDirection: "row",
      justifyContent: "flex-start",
      ...css,
    },
    theme
  )

  return <Component className={className} {...props} />
}

const App = () => {
  return (
    <View
      css={{
        p: [1, 2, 3],
        "&:hover": {
          bg: "text",
          color: "background",
        },
      }}
    >
      <Text css={{fontSize: [1, 2, 3]}}>Hello world !</Text>
    </View>
  )
}

FAQs

Package last updated on 24 Feb 2020

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