转自:https://blog.bitsrc.io/9-css-in-js-libraries-you-should-know-in-2018-25afb4025b9b

实际上  wix 的 stylable 也不错,网上也有相关的比较,以及有优缺点说明

Some of the best CSS in Javascript libraries to use in your app.

When building Bit, turning components into building blocks which can be shared, used and developed anywhere, we had to get deeply familiarized with the various ways people choose to style components in the ecosystem.

One particularly interesting concept is using JS in CSS to abstract CSS to the component level itself, using JavaScript to describe styles in a declarative and maintainable way. So, we’ve listed some useful projects to get started.

You can also read this recommended discussion to help you make a good decision, and here’s a very cool comparison of projects. Let’s dive in.

1. Styled components

An idea born in an Australian Whisky bar turned into an 18K stars project, widely adopted in the community. Styled-components makes it easier to use CSS in React components, by defining styled-components with encapsulated styles without CSS classes as a mediator layer.

Styled-components are created by defining components using the ES6 template literal notation. CSS properties can be added to the component as needed, just like you would normally do using CSS. When the JS is parsed, styled-components will generate unique class names, and inject the CSS into the DOM. You can learn more in this great talk by Max Stoiber.

Tip: Styled-components can also be combined with Bit, to share them between apps and develop in a visual playground. Take a look.

  • Also check out: Stylable by Wix-Eng which is still in development.

2. Radium

At 6.5K stars and created by FormidableLabs, Radium is defined as “A toolchain for React component styling”. It’s set of tools to manage inline styles with React without CSS. Radium offers a standard interface and abstractions for dealing with CSS features that inline styles don’t easily accommodate

Radium lets you bundle up styles with your React components, coupling javascript, html, and styling together. It also provides props-based rendering, allowing you to style your components based on the state of your app.

3. Aphrodite

Aphrodite is a framework-agnostic CSS-in-JS library with support for server-side rendering, browser prefixing, and minimum CSS generation. Aphrodite transforms everything into classes and uses the class attribute.

At 4K stars, this project works with or without React and provides features such as injecting styled into the Dom, auto prefixes styles and more, all at a relatively small size of 20k and a handful of dependancies. Here’s a useful Aphrodite vs. Radium rundown.

4. Emotion

At 4.2K stars Emotion is a performant and flexible CSS-in-JS library which allows you to style apps with string or object styles. It has predictable composition to avoid specificity issues with CSS. Based on the glam library and its philosophy the idea is to retain runtime performance when writing CSS by parsing styles with babel and PostCSS. The core runtime is 2.3kb and with React support, 4kb. Emotion isn’t limited to React.

5. Glamorous

Note: the project is no longer actively maintained! still cool though :)

At 3.6K stars PayPal’s Glamorous is oriented for building “maintainable CSS with React” inspired by styled-components and jsxtyle. Kent C. Doddsdefinethe project as “React component styling solved with an elegant (inspired) API, small footprint (<5kb gzipped), and great performance (via glamor)”. It has a very similar API to styled-components and uses similar tools under the hood.

paypal/glamorous
glamorous -

9 CSS in JS Libraries You Should Know in 2018的更多相关文章

  1. JQuery 加载 CSS、JS 文件

    JS 方式加载 CSS.JS 文件: //加载 css 文件 function includeCss(filename) { var head = document.getElementsByTagN ...

  2. grunt自定义任务——合并压缩css和js

    npm文档:www.npmjs.com grunt基础教程:http://www.gruntjs.net/docs/getting-started/ http://www.w3cplus.com/to ...

  3. 来,一起让我们越来越懒,面向CSS、JS未来编程。(9.28已更新)

    2016.10.29更新 本文存在大量的错误,仅供参考. 不知不觉在前端领域马上一个年头就要过去了,然而再看看自己的代码,果然够烂,那么为什么代码一直没有用面向对象的思维去写CSS呢?首先有两点:一点 ...

  4. 如何判断一个DOM元素正在动画,一个CSS“阻塞”JS的例子

    一般情况下CSS不会直接影响JS的程序逻辑,但是以CSS实现动画的话,这个便不太确定了,这个故事发生在与UED迁移全局样式的过程. 曾经我有一段实现弹出层隐藏动画的代码是这个样子的: if (this ...

  5. Asp.net 后台添加CSS、JS、Meta标签

    Asp.net 后台添加CSS.JS.Meta标签的写法,我这里写成函数方便以后使用.如果函数放在页面类中, Page参数也可以不要. 首先导入命名空间 using System.Web.UI.Htm ...

  6. django 关于html、css、js 目录位置

    项目目录: project/ ---------------init.py ---------------views.py ---------------settings.py ----------- ...

  7. CI模板加载css和js

    1.需求 ci无法加载css和js文件. 2.解决 删除..htaccess文件. 在config目录下配置base_url,并传给页面 $base_url = $this->config-&g ...

  8. HTML、CSS、JS对unicode字符的不同处理

    unicode字符的不同表示法 unicode字符在html.css和js中的表示方法均不相同,下面分别作介绍. 原文发表于这里 css表示法 首先来一段很常见的bootstrap的字体图标代码: . ...

  9. 关于webStrom-11.1配置less且自动生成.css和自动压缩为.min.css/.min.js

    网上看过很多配置思路,自己总结了以下, 就把我个人配置的顺序以及材料分享下,webstrom以下简称WB 1.配置less需要安装nodejs,自行安装.因为要用到npm.我是直接把npm解压到C盘根 ...

随机推荐

  1. 34sqlite

    sqlite,本地数据库.主要运用在小型的程序,传送方便(如发送附带数据库的程序,但MySQL有点大,或许没安装). 如何创建本地数据库? 1.新建一个.txt的文本文件. 2.直接将后缀名有.txt ...

  2. Ubuntu安装 Spark2.3.0 报错原因及解决

    Ubuntu 安装Spark出现的问题及解决 最近在搭建Hadoop集群环境和Spark集群环境,出现的问题可能不太复杂,纯粹记录安装步骤和问题解决办法.集群环境使用的是(2台)阿里云主机,操作系统是 ...

  3. RANSAC算法在图像拼接上的应用的实现

    关于算法原理请参考<基于SURF特征的图像与视频拼接技术的研究>. 一.问题提出         RANSAC的算法原理并不复杂,比较复杂的地方在于"建立模型"和&qu ...

  4. 20145309 李昊 《网络攻防》 Exp2 后门原理与实践

    实践内容: (1)理解免杀技术原理(1分) (2)正确使用msf编码器,veil-evasion,自己利用shellcode编程等免杀工具或技巧:(2分) (3)通过组合应用各种技术实现恶意代码免杀( ...

  5. AngularJs 表单提交按钮状态

    表单属性: $invalid:未经过验证的表单,就是表单里面信息通过验证就为false,没有通过为true $valid:经过验证的表单,表单里信息验证通过为true,反之为false $dirty: ...

  6. [参考]用递归的方法获取 字符 对应的 二进制字符串 (C/C++)

    将字符转换为16进制字符串.十进制字符串可以参考这里:https://www.cnblogs.com/stxs/p/8846545.html 代码及调试结果 举例:字符'a',查ASCII码表它对应的 ...

  7. tomcat跟目录下work文件夹的作用

    work目录只是tomcat的工作目录,也就是tomcat把jsp转换为class文件的工作目录. jsp,tomcat的工作原理:当浏览器访问某个jsp页面时,tomcat会在work目录里把这个j ...

  8. Binary Tree Zigzag Level Order Traversal,z字形遍历二叉树,得到每层访问的节点值。

    问题描述: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from l ...

  9. Missing artifact com.github.pagehelper:pagehelper:jar:3.4.2-fix的解决方法

    使用pagehelper.3.4.2.jar时报错,应该是无法从网络上下载该jar. 我的解决方案是: 从网络上下载一个pagehelper.3.4.2.jar包,然后复制到.m2目录中 如我的目录是 ...

  10. Android 各API版本代码常量

    Android开发中常常有版本比较这个功能,来做版本兼容或者,其他相关效果等   以下是Android 7.0版本下的源码:   public static class VERSION_CODES { ...