All Projects → cssinjs → aphrodite-jss

cssinjs / aphrodite-jss

Licence: MIT license
Aphrodite-like API on top of JSS.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to aphrodite-jss

Js Stack Boilerplate
Final boilerplate code of the JavaScript Stack from Scratch tutorial –
Stars: ✭ 145 (+57.61%)
Mutual labels:  jss
Aphrodite
Framework-agnostic CSS-in-JS with support for server-side rendering, browser prefixing, and minimum CSS generation
Stars: ✭ 5,257 (+5614.13%)
Mutual labels:  aphrodite
gatsby-starter-simple-landing
A simple, ready to use, easy to customize landing page starter for GatsbyJS with auto generated (sizes & types) Hero images.
Stars: ✭ 45 (-51.09%)
Mutual labels:  jss
Css In Js
Autocomplete React Native / JS Styles and converting plain CSS to JS styles
Stars: ✭ 192 (+108.7%)
Mutual labels:  jss
React-Crypto-Exchange
React Crypto exchange
Stars: ✭ 35 (-61.96%)
Mutual labels:  aphrodite
fractal-component
A javascript library that can help you to encapsulate decoupled UI component easily
Stars: ✭ 13 (-85.87%)
Mutual labels:  jss
Css In React
🍭 CSS in React - Learn the best CSS in JS frameworks by example
Stars: ✭ 101 (+9.78%)
Mutual labels:  jss
jss-material-ui
A enhanced styling engine for material-ui
Stars: ✭ 15 (-83.7%)
Mutual labels:  jss
adonis
Adonis ❤️ Aphrodite
Stars: ✭ 44 (-52.17%)
Mutual labels:  aphrodite
react-themeit
An easy way to theme your components using css modules and js css objects thanks to aphrodite. Also works with asynchronously loaded styles!
Stars: ✭ 28 (-69.57%)
Mutual labels:  aphrodite
Styled Jss
Styled Components on top of JSS.
Stars: ✭ 217 (+135.87%)
Mutual labels:  jss
A Journey Toward Better Style
A Journey toward better style
Stars: ✭ 245 (+166.3%)
Mutual labels:  jss
csstox
Convert CSS text to a React Native/JSS stylesheet object with ease.
Stars: ✭ 72 (-21.74%)
Mutual labels:  jss
Xbyjmusic
🎷🎸基于electron的跨平台 NeteaseMusic 桌面应用🎺🎻
Stars: ✭ 156 (+69.57%)
Mutual labels:  jss
gloss
a powerful style system for building ui kits
Stars: ✭ 16 (-82.61%)
Mutual labels:  jss
Jss Filevault Reissue
A framework for re-escrowing missing or invalid FileVault keys with Jamf Pro.
Stars: ✭ 132 (+43.48%)
Mutual labels:  jss
vue-jss-plugin
JSS plugin implementation for Vue.js
Stars: ✭ 24 (-73.91%)
Mutual labels:  jss
tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (-43.48%)
Mutual labels:  jss
sitecore-headless-commerce-accelerator
EPAM Headless Commerce Accelerator for Sitecore Experience Commerce
Stars: ✭ 35 (-61.96%)
Mutual labels:  jss
JSS-Resource-Tools
A CLI utility that utilises the Jamf Pro (previously Casper Suite) API in order to import, export and update JSS resources en-masse.
Stars: ✭ 24 (-73.91%)
Mutual labels:  jss

Aphrodite-like API on top of JSS.

This project is a merge of good ideas from aphrodite and JSS. It provides an API of aphrodite but fixes lots of limitations and caveats by using JSS as a rendering engine under the hood.

Good parts from aphrodite.

  • Pretty much like inline styles known from React, except it allows to use the entire CSS.
  • No CSS is generated until css() function invocation. Only the passed rules are converted to a CSS string and injected.
  • Theming is possible without any headache or framework integrations.

Benefits compared to aphrodite.

  • More powerfull rendering abstraction through JSS under the hood. You are using all it's plugins and JSON DSL. To name a few:
    • Children, siblings and any other kinds of selectors. (jss-nested)
    • Global styles, without auto namespacing (jss-global).
  • Immediate render upon css() call invocation. It gives you an access to computed styles right after render, no need to use setTimeout(). It also avoids additional recalcs and repaints, which can cause flickers and general performance overhead.
  • No auto "!important" insertion. You can write a plugin for this though.

Example

import {StyleSheet, css} from 'aphrodite-jss'

const sheet = StyleSheet.create({
  button: {
    border: '1px solid',
    borderRadius: 5,
    fontSize: 'inherit',
    lineHeight: '2.3em',
    padding: '0 1em',
    boxShadow: 'inset 0 1px 0 rgba(255, 255, 255, 0.1)',
    textShadow: '0 -1px 0 rgba(0, 0, 0, 0.25)',
    backgroundRepeat: 'repeat-x',
    color: '#fff',
    fontWeight: 400,
    '& span': {
      marginRight: 5,
      color: '#fff'
    }
  },
  primary: {
    borderColor: '#1177cd #0f6ab6 #0d5c9e',
    backgroundImage: 'linear-gradient(to bottom, #2591ed 0%, #1177cd 100%)',
    backgroundColor: '#1385e5',
    '&:hover': {
      backgroundImage: 'linear-gradient(to bottom, #3c9def 0%, #1385e5 100%)'
    }
  }
})

document.body.innerHTML = `
  <button class="${css(sheet.button, sheet.primary)}">
    <span>&#10004;</span>Primary
  </button>
`

API

Create style sheet.

StyleSheet.create(styles)

Create function doesn't render anything, it just registers your styles.

Returns an object, where key names correspond the original styles obejct.

Inject rules.

css(rule1, [rule2], [rule3], ...)

Injects a previously defined rule to the dom. This is done in sync, so the CSS rule is immediately available.

Returns a class name.

Styles format.

The format for styles is defined in jss. Aprodisiac uses jss-preset-default, so all default presets are already in place.

Customizing JSS.

aphroditeJss(jss, [options])

You can pass your own JSS instance with your custom setup.

Returns aphrodite's interface.

import aphroditeJss from 'aphrodite-jss'
import {create} from 'jss'

const {css, StyleSheet} = aphroditeJss(create())

Serverside Rendering.

There are 2 functions you need to know - toString() and reset(). As aphrodite-jss can not know that you are rendering a new response, you need to get the CSS (toString()) when you are processing the first request and call reset() to clean up the styles your current page has produced.

import {toString, reset} from 'aphrodite-jss'

function render() {
  const app = renderApp()
  const css = toString()
  reset()

  return `
    <head>
      <style>
        ${css}
      </style>
    <head>
    <body>
      ${app}
    </body>
  `
}

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].