All Projects → andywer → React Usestyles

andywer / React Usestyles

Licence: mit
🖍 Style components using React hooks. Abstracts the styling library away.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Usestyles

Css In Js
Autocomplete React Native / JS Styles and converting plain CSS to JS styles
Stars: ✭ 192 (+115.73%)
Mutual labels:  css-in-js, jss
vue-jss-plugin
JSS plugin implementation for Vue.js
Stars: ✭ 24 (-73.03%)
Mutual labels:  css-in-js, jss
Css In React
🍭 CSS in React - Learn the best CSS in JS frameworks by example
Stars: ✭ 101 (+13.48%)
Mutual labels:  css-in-js, jss
React Jss
JSS integration for React (Migrated to a Monorepo it JSS repository)
Stars: ✭ 1,212 (+1261.8%)
Mutual labels:  css-in-js, jss
Styled Tools
Useful interpolated functions for CSS-in-JS
Stars: ✭ 761 (+755.06%)
Mutual labels:  css-in-js, jss
gloss
a powerful style system for building ui kits
Stars: ✭ 16 (-82.02%)
Mutual labels:  css-in-js, jss
A Journey Toward Better Style
A Journey toward better style
Stars: ✭ 245 (+175.28%)
Mutual labels:  css-in-js, jss
Postjss
Use the power of PostCSS in compiling with JSS
Stars: ✭ 40 (-55.06%)
Mutual labels:  css-in-js, jss
Css In Js Benchmarks
Stars: ✭ 360 (+304.49%)
Mutual labels:  css-in-js, jss
tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (-41.57%)
Mutual labels:  css-in-js, jss
Jss
JSS is an authoring tool for CSS which uses JavaScript as a host language.
Stars: ✭ 6,576 (+7288.76%)
Mutual labels:  css-in-js, jss
Scale
The Scale library offers a set of customizable web components written with Stencil.js & TypeScript. The default theme of the library can be easily replaced so that a corresponding corporate identity of a dedicated brand can be represented.
Stars: ✭ 87 (-2.25%)
Mutual labels:  css-in-js, jss
Flame
Component library for building Lightspeed products
Stars: ✭ 65 (-26.97%)
Mutual labels:  css-in-js
Rosebox
CSS in Typescript
Stars: ✭ 62 (-30.34%)
Mutual labels:  css-in-js
Vue Styled Components
Visual primitives for the component age. A simple port for Vue of styled-components 💅
Stars: ✭ 1,114 (+1151.69%)
Mutual labels:  css-in-js
React Image Smooth Loading
[not maintained] Images which just flick to appear aren't cool. Images which appear smoothly with a fade like Instagram are cool
Stars: ✭ 84 (-5.62%)
Mutual labels:  css-in-js
Styled Components Rhythm
Vertical Rhythm and Font Baselines with Styled Components
Stars: ✭ 76 (-14.61%)
Mutual labels:  css-in-js
Css In Js Utils
Useful utility functions for CSS in JS solutions
Stars: ✭ 61 (-31.46%)
Mutual labels:  css-in-js
Tailwind Styled Component
Create Tailwind CSS React components like styled components with class names on multiple lines and conditional class rendering
Stars: ✭ 57 (-35.96%)
Mutual labels:  css-in-js
Cabana React
A design system built especially for both Sketch and React. 💎⚛️
Stars: ✭ 58 (-34.83%)
Mutual labels:  css-in-js

Unified React styling hook

Leveraging the React Hooks API to provide an elegant, unified styling API.

One simple API based on the hooks API to style all components. Suddenly it does not matter anymore if you are using Emotion, Styled Components or JSS - the styling becomes transparent.

Great for component libraries: Don't force your users into a particular styling library! Style with universal hooks and let the users plug-in the styling library that works best for them.

Features

💅 Style components with useStyles()
💡 Uncouple components from styling library
🌅 Server side rendering
🌈 Theming support out of the box


Any feedback welcome! Leave a comment or 🌟 the repo.

⚠️  Attention: Bleeding edge ahead. Don't use this in production.

Installation

In your app:

$ npm install [email protected] [email protected] @andywer/style-hook @andywer/style-api-jss

In a component package you only need this:

$ npm install [email protected] @andywer/style-hook

Live Playgrounds

Here are some code sandboxes to see the style hooks in action. You can also see the source code and live-edit it:

😸 Basics - https://codesandbox.io/s/zx4o632n8l
🖥 Material-UI / Simple Hacker News client - https://codesandbox.io/s/myo47mvjw9

Usage

useStyles()

// Button.js
import { useStyles } from "@andywer/style-hook"
import React from "react"

export function Button (props) {
  const classNames = useStyles({
    button: {
      padding:    "0.6em 1.2em",
      background: theme => theme.button.default.background,
      color:      theme => theme.button.default.textColor,
      border:     "none",
      boxShadow:  "0 0 0.5em #b0b0b0",
      "&:hover": {
        boxShadow: "0 0 0.5em #e0e0e0"
      }
    },
    buttonPrimary: {
      background: theme => theme.button.primary.background,
      color:      theme => theme.button.primary.textColor
    }
  })

  const className = `${classNames.button} ${props.primary ? classNames.buttonPrimary : ""}`
  return (
    <button className={className} onClick={props.onClick}>
      {props.children}
    </button>
  )
}

Rendering your app with style hook support is easy: Add a provider for the styling library at the top of your app.

// App.js
import { JssProvider } from "@andywer/style-api-jss"
import React from "react"
import ReactDOM from "react-dom"

const App = () => (
  <JssProvider>
    {/* ... */}
  </JssProvider>
)

ReactDOM.render(<App />, document.getElementById("app"))

useStyle()

This is a convenience function to define a single CSS class.

import { useStyle } from "@andywer/style-hook"
import React from "react"

export function Button (props) {
  const className = useStyle({
    padding:   "0.6em 1.2em",
    boxShadow: "0 0 0.5em #b0b0b0",
    "&:hover": {
      boxShadow: "0 0 0.5em #e0e0e0"
    }
  })
  return (
    <button className={className} onClick={props.onClick}>
      {props.children}
    </button>
  )
}

Theming & props

import { useStyles } from "@andywer/style-hook"
import React from "react"

export function Button (props) {
  const classNames = useStyles({
    button: {
      background: theme => theme.button.default.background,
      color:      theme => theme.button.default.textColor,
      border:     () => props.border || "none",
      boxShadow:  "0 0 0.5em #b0b0b0",
      "&:hover": {
        boxShadow: "0 0 0.5em #e0e0e0"
      }
    },
    buttonPrimary: {
      background: theme => theme.button.primary.background,
      color:      theme => theme.button.primary.textColor
    }
  }, [props.border])

  const className = `${classNames.button} ${props.primary ? classNames.buttonPrimary : ""}`
  return (
    <button className={className} onClick={props.onClick}>
      {props.children}
    </button>
  )
}

For details see the style-hook package readme.

Details

For more details about the API and usage instructions, check out the style-hook package readme.

API

  • style-hook - The main package providing the hooks
  • style-api - Defines the API between styling library provider and hooks (internal)
  • style-api-jss - The styling library provider for JSS

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].