All Projects → 07akioni → css-render

07akioni / css-render

Licence: MIT license
Generating CSS using JS with considerable flexibility and extensibility, at both server side and client side.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
SCSS
7915 projects

Projects that are alternatives of or similar to css-render

Immutable Styles
A library for styling web interfaces with a focus on predictability and robustness. It uses immutability to remove side effects often tied to CSS, allowing UI bugs to be caught ahead of time!
Stars: ✭ 69 (-49.64%)
Mutual labels:  preprocessor, css-in-js
Nano Style
React functional CSS-in-JS
Stars: ✭ 85 (-37.96%)
Mutual labels:  style, css-in-js
glitz
Lightweight CSS-in-JS library with high performance written in TypeScript
Stars: ✭ 42 (-69.34%)
Mutual labels:  style, css-in-js
Expo Dark Mode Switch
A beautiful React dark mode switch component for iOS, Android, and Web
Stars: ✭ 137 (+0%)
Mutual labels:  style, css-in-js
svelte-style-directive
A custom Svelte preprocessor to add support for style directive.
Stars: ✭ 19 (-86.13%)
Mutual labels:  preprocessor, style
Axs
Stupid simple style components for React
Stars: ✭ 214 (+56.2%)
Mutual labels:  style, css-in-js
Glamorous Primitives
💄 style primitive React interfaces with glamorous
Stars: ✭ 91 (-33.58%)
Mutual labels:  style, css-in-js
Stylable
Stylable - CSS for components
Stars: ✭ 1,109 (+709.49%)
Mutual labels:  preprocessor, style
tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (-62.04%)
Mutual labels:  style, css-in-js
linaria-styled
Zero-runtime CSS in JS library for building React components
Stars: ✭ 17 (-87.59%)
Mutual labels:  css-in-js
preprocessor-loader
Bring the awesome "Conditional Compilation" to the Webpack, and more.
Stars: ✭ 32 (-76.64%)
Mutual labels:  preprocessor
lit
a little preprocessor for literate programming
Stars: ✭ 108 (-21.17%)
Mutual labels:  preprocessor
stitches-site
stitches.dev
Stars: ✭ 240 (+75.18%)
Mutual labels:  css-in-js
Aris
Aris - A fast and powerful tool to write HTML in JS easily. Includes syntax highlighting, templates, SVG, CSS autofixing, debugger support and more...
Stars: ✭ 61 (-55.47%)
Mutual labels:  css-in-js
postcss-gtk
Processes GTK+ CSS into browser CSS
Stars: ✭ 23 (-83.21%)
Mutual labels:  style
siimple
The minimal and themeable CSS toolkit for flat and clean designs
Stars: ✭ 525 (+283.21%)
Mutual labels:  css-in-js
vrm pp
Small C++ preprocessor library
Stars: ✭ 12 (-91.24%)
Mutual labels:  preprocessor
stitches-reset
The famous Eric Meyer's Reset CSS for stitches
Stars: ✭ 35 (-74.45%)
Mutual labels:  css-in-js
react-koa-universal
a boilerplate react graphql apollo css-in-js buzzword koa ssr pwa wasm throwaway app 🚮
Stars: ✭ 12 (-91.24%)
Mutual labels:  css-in-js
rollup-plugin-jscc
Conditional compilation and compile-time variable replacement for Rollup
Stars: ✭ 52 (-62.04%)
Mutual labels:  preprocessor

css-render · GitHub Liscense npm Total alerts codecov

Generating CSS using JS with considerable flexibility and extensibility, at both server side and client side.

It's mainly built for library builders (who wants make their library work without css import at small overhead). It's not recommend to use it in a webapp.

It is not designed to totally replace other style-related solutions, but to be a progressive tool which can just work as a supplementary of your style files or totally replace your .css files.

Docs

css-render

Why Using It

  1. You want to ship a library without css at a small price (gzip < 2kb).
  2. Reduce size compared with static css (which contains duplicate logic).
  3. You can't write sass-like or less-like css-in-js (eg. mixin in sass or less).
  4. You want to write style variables in JS.
  5. Support an simple SSR API (now only for vue3).

Comparasion with other CSS-in-JS framework

Main differences between css-render and styled-component, jss or emotion:

  1. It doesn't do the bindings between components and styles. It is more like a style generator with low level mount and unmount API.
  2. It's easier to write like a sass mixin or less mixin.

Examples

Realworld Example

Basic Example

$ npm install --save-dev css-render
import CssRender from 'css-render'
/**
 * CommonJS:
 * const { CssRender } = require('css-render')
 */

const {
  c
} = CssRender()

const style = c('body', ({ props }) => ({
  margin: 0,
  backgroundColor: props.backgroundColor
}), [
  c('&.dark', {
    backgroundColor: 'black'
  }),
  c('.container', {
    width: '100%'
  })
])

/** use it as string */
console.log(style.render({ backgroundColor: 'white' }))
/**
 * or mount on document.head. (the following lines only work in the browser.)
 */
style.mount()
// ...
style.unmount()
body {
  margin: 0;
  background-color: white;
}

body.dark {
  background-color: black;
}

body .container {
  width: 100%;
}

BEM Plugin Example

$ npm install --save-dev css-render @css-render/plugin-bem

You can use bem plugin to generate bem CSS like this:

import CssRender from 'css-render'
import bem from '@css-render/plugin-bem'
/**
 * CommonJS:
 * const { CssRender } = require('css-render')
 * const { plugin: bem } = require('@css-render/plugin-bem')
 */

const cssr = CssRender()
const plugin = bem({
  blockPrefix: '.c-'
})
cssr.use(plugin) // bind the plugin with the cssr instance
const {
  cB, cE, cM
} = plugin

const style = cB(
  'container',
  [
    cE(
      'left, right', 
      {
        width: '50%'
      }
    ),
    cM(
      'dark', 
      [
        cE(
          'left, right',
          {
            backgroundColor: 'black'
          }
        )
      ]
    )
  ]
)

/** use it as string */
console.log(style.render())
/**
 * or mount on document.head
 * the following lines only works in browser, don't call them in node.js
 */
style.mount()
// ...
style.unmount()
.c-container .c-container__left, .c-container .c-container__right {
  width: 50%;
}

.c-container.c-container--dark .c-container__left, .c-container.c-container--dark .c-container__right {
  background-color: black;
}

Packages

Name Cov
css-render codecov
@css-render/plugin-bem codecov
vue3-ssr codecov
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].