9 CSS in JS Libraries You Should Know in 2018
转自:https://blog.bitsrc.io/9-css-in-js-libraries-you-should-know-in-2018-25afb4025b9b
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.
glamorous -
9 CSS in JS Libraries You Should Know in 2018的更多相关文章
- JQuery 加载 CSS、JS 文件
JS 方式加载 CSS.JS 文件: //加载 css 文件 function includeCss(filename) { var head = document.getElementsByTagN ...
- grunt自定义任务——合并压缩css和js
npm文档:www.npmjs.com grunt基础教程:http://www.gruntjs.net/docs/getting-started/ http://www.w3cplus.com/to ...
- 来,一起让我们越来越懒,面向CSS、JS未来编程。(9.28已更新)
2016.10.29更新 本文存在大量的错误,仅供参考. 不知不觉在前端领域马上一个年头就要过去了,然而再看看自己的代码,果然够烂,那么为什么代码一直没有用面向对象的思维去写CSS呢?首先有两点:一点 ...
- 如何判断一个DOM元素正在动画,一个CSS“阻塞”JS的例子
一般情况下CSS不会直接影响JS的程序逻辑,但是以CSS实现动画的话,这个便不太确定了,这个故事发生在与UED迁移全局样式的过程. 曾经我有一段实现弹出层隐藏动画的代码是这个样子的: if (this ...
- Asp.net 后台添加CSS、JS、Meta标签
Asp.net 后台添加CSS.JS.Meta标签的写法,我这里写成函数方便以后使用.如果函数放在页面类中, Page参数也可以不要. 首先导入命名空间 using System.Web.UI.Htm ...
- django 关于html、css、js 目录位置
项目目录: project/ ---------------init.py ---------------views.py ---------------settings.py ----------- ...
- CI模板加载css和js
1.需求 ci无法加载css和js文件. 2.解决 删除..htaccess文件. 在config目录下配置base_url,并传给页面 $base_url = $this->config-&g ...
- HTML、CSS、JS对unicode字符的不同处理
unicode字符的不同表示法 unicode字符在html.css和js中的表示方法均不相同,下面分别作介绍. 原文发表于这里 css表示法 首先来一段很常见的bootstrap的字体图标代码: . ...
- 关于webStrom-11.1配置less且自动生成.css和自动压缩为.min.css/.min.js
网上看过很多配置思路,自己总结了以下, 就把我个人配置的顺序以及材料分享下,webstrom以下简称WB 1.配置less需要安装nodejs,自行安装.因为要用到npm.我是直接把npm解压到C盘根 ...
随机推荐
- Java开发之JDK配置
windows下配置JDK环境变量: 1.安装JDK,安装过程中可以自定义安装目录等信息,例如我们选择安装目录为D:/java/jdk1.5.0_08: 2.安装完成后,右击“我的电 ...
- linux history记录格式修改
#保存一万条命令记录 sed -i 's/^HISTSIZE=1000/HISTSIZE=10000/g' /etc/profile #在/etc/profile的文件尾部添加如下行数配置信息 ### ...
- 20162311 课堂测试 泛型类—Bag
课堂测试 泛型类-Bag 目录 一.题目要求 二.设计思路 三.问题和解决办法 四.代码运行截图 五.代码托管地址 六.总结 一.题目要求 题目:泛型类-Bag 返回目录 二.设计思路 自定义一个Ba ...
- 「翻译」一篇redis文章引发的翻译——JVM能支持多少线程?
昨天看了一篇关于redis 的文章https://www.cnblogs.com/fanwencong/p/5782860.html 作者说他模拟了100万线程的并发,我对这个有一些怀疑,看了评论也有 ...
- ACM赛前准备——模板(排版篇)
ACM赛前准备--模板(排版篇) 更新 前言 效果演示 封面 目录页 模板页(不分栏) 模板页(分栏) 结果文件 快速使用 准备工作 安装TexLive (可选)安装minted包 创建模板 文件结构 ...
- 记一次Servlet中getAttribute的错误.
package com.ykmimi.order.servlet; import java.io.IOException; import javax.servlet.RequestDispatcher ...
- SDN前瞻 传统网络架构的危机:危机“四”起
本文基于SDN导论的视频而成:SDN导论 在网络发展速度如此之快的今天,传统网络的架构充满了危机,主要有这四个问题(3+1). 1)传统网络的部署和管理 非常困难 2)分布式网络架构凸显瓶颈 3)流量 ...
- nohup 不生成 nohup.out的方法
nohup java -jar /xxx/xxx/xxx.jar >/dev/>& & 关键在于最后的 >/dev/>& 部分,/dev/null是一个 ...
- Composite(组合)
意图: 将对象组合成树形结构以表示“部分-整体”的层次结构.C o m p o s i t e 使得用户对单个对象和组合对象的使用具有一致性. 适用性: 你想表示对象的部分-整体层次结构. 你希望用户 ...
- postgresql中终止正在执行的SQL语句
在Linux系统中可以使用kill [pid]的方式强制删除进程,但对于修改数据表的语句来说,这样可能导致postgresql进入recovery mode,这样会导致锁表. Postgresql的运 ...