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盘根 ...
随机推荐
- SecureCRT 下载,安装,绝佳配色,实用配置,上传下载配置合集
SecureCRT 下载,安装,绝佳配色,实用配置,上传下载配置合集 chocoball 发布于 2年前,共有 3 条评论 SecureCRT 是一款支持 SSH2.SSH1.Telnet.Telne ...
- 反射获取成员方法(Method)
1.1.1 反射公开的非静态的成员方法 Method getDeclaredMethod(String name,Class ... parameterTypes)获取某个方法. 说明: 1)在Cla ...
- 微信小程序中公用内容
微信小程序中各个页面调用公用的js 在util.js文件中 // 跳转哪里 function go(where) { wx.reLaunch({ url: where, }) } // 将方法暴露出去 ...
- CSS设置文本末行显示省略号...
首先设置文本标签或文字所在标签的宽度 最主要是以下三点: ①white-space:nowrap;如果是中文需要设置行末不断行 ②overflow:hidden;设置控 ...
- Python学习札记(三十二) 面向对象编程 Object Oriented Program 3
参考:访问限制 NOTE 1.eg. #!/usr/bin/env python3 class Student(object): """docstring for Stu ...
- 2016湘潭邀请赛—Heartstone
http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1246 题意: 有n只怪,每只怪有指定的HP.现在1和2两种攻击方式,前者扣 ...
- PostgreSql 其它客户端连接
在 PATH_TO_YOUR_PostGreSQL/data/pg_hba.conf 加上红色那行,重启postgre的service就能让其它人连你的数据库了. host all all 127.0 ...
- shell 计时获取输入
#!/bin/bash if read -t 5 -p "please enter your name:" name then echo "hello ...
- 优化 Redis 的使用策略
Redis Key 的命名策略 Redis 是 K-V 形式的缓存数据库,每一个需要缓存的 Object 都需要唯一的 Key 来标识.但是,我们日常在做开发的时候,经常会出现一个公司或者部门之间共用 ...
- jquery ui是什么
jquery ui是什么 一.总结 一句话总结:jQuery UI [1] 是以 jQuery 为基础的开源 JavaScript 网页用户界面代码库.包含底层用户交互.动画.特效和可更换主题的可视 ...