[TypeStyle] Compose CSS classes using TypeStyle
We will demonstrate composing classes using the utility classes function. classes is also what we recommend for theming. Using pure CSS classes means that the component consumers are free to customize the component using any technology (not just TypeStyle). classes is also what is recommended for conditionally applied TypeStyle CSS class names.
import { style, classes } from 'typestyle';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
const fontSize = (value: number | string) => {
const valueStr = typeof value === 'string' ?
value :
value + 'px';
return {
fontSize: valueStr
}
};
const baseClassName = style(
{
color: 'green',
},
fontSize(15)
);
const errorClassName = style({
color: 'red'
},
fontSize(12)
);
const Section = ({children, hasError, className}: {
children?: any, hasError?: boolean, className?: string
}) => (
<div className={classes(
baseClassName,
className,
hasError && errorClassName
)}>
{children}
</div>
);
const App = () => (
<div>
<Section className={style({backgroundColor: 'pink'})}>Success</Section>
<Section className={style({backgroundColor: 'yellow'})} hasError={true}>Error</Section>
</div>
);
ReactDOM.render(
<App />,
document.getElementById('root')
);
[TypeStyle] Compose CSS classes using TypeStyle的更多相关文章
- [TypeStyle] Style CSS pseudo-classes using TypeStyle with $nest
TypeStyle is a very thin layer on top of CSS. In this lesson we show how to change styles based on p ...
- [TypeStyle] Style CSS pseudo elements with TypeStyle
Just like pseudo-classes, pseudo-elements are added to selectors but instead of describing a special ...
- [TypeStyle] Use fallback values in TypeStyle for better browser support
You can increase the browser support of your CSS using fallback values and vendor prefixes. This les ...
- [TypeStyle] Add responsive styles using TypeStyle Media Queries
Media queries are very important for designs that you want to work on both mobile and desktop browse ...
- 章节十、4-CSS Classes---用多个CSS Classes定位元素
以下演示操作以该网址中的输入框为例:https://learn.letskodeit.com/p/practice 一.使用input[class=inputs]验证元素是否唯一 注意:使用“clas ...
- [TypeStyle] Use TypeStyle keyframes to create CSS animations
We cover CSS keyframes and how to create them using TypeStyle. We then show how to use the keyframes ...
- [TypeStyle] Add type safety to CSS using TypeStyle
TypeStyle is the only current CSS in JS solution that is designed with TypeSafety and TypeScript dev ...
- 【转载】CSS规范
原文地址:http://www.cnblogs.com/whitewolf/p/4491707.html 目录 HTML 语法 HTML5 doctype 语言属性(Language attribut ...
- 4.1HTML和Bootstrap css精华
1.HTML 2.理解Bootstrap HTML元素告诉浏览器,他要表现的是什么类型的内容,当他们不提供任何关于如何显示内容的信息.如何显示内容的信息,由CSS提供. 本书仅包含足够的信息,让你查看 ...
随机推荐
- Java: 数据类型
核心:对事物的某种规范 前提: 1.JAVA:JAVA程序的运行是以堆栈的操作来完成的 堆栈以帧为单位保存线程的状态. JVM对堆栈只进行两种操作:以帧为单位的压栈和出栈操作. 理解 ...
- poj 2480 Longge's problem 积性函数性质+欧拉函数
题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d ...
- excel表如何实现多if选择结构多分支判断
excel表如何实现多if选择结构多分支判断 一.总结 一句话总结:把多if分支转换成单if分支相加. 也可以if分支,也可以lookup函数. 1.CHOICE: +2 if band A; +1 ...
- 17.Node.js 回调函数--异步编程
转自:http://www.runoob.com/nodejs/nodejs-tutorial.html Node.js 异步编程的直接体现就是回调. 异步编程依托于回调来实现,但不能说使用了回调后程 ...
- Java Base64、HMAC、SHA1、MD5、AES DES 3DES加密算法
● BASE64 严格地说,属于编码格式,而非加密算法 ● MD5(Message Digest algorithm 5,信息摘要算法) ● SHA(Secure Hash Algo ...
- 五、Docker+Sqlserver
原文:五.Docker+Sqlserver sqlserver现在支持linux了.所以可以运行在docker内 一.下载镜像: docker pull microsoft/mssql-server- ...
- 【LightOJ - 1205】Palindromic Numbers
[链接]https://cn.vjudge.net/problem/LightOJ-1205 [题意] 求出L..R范围内的回文个数 [题解] 数位DP; 先求出1..x里面的回文串个数.则做一下前缀 ...
- Windows系统 配置Java的JDK环境变量
安装了JDK或者绿色版后,在系统的环境变量设置中,进行以下配置: 1.新建->变量名"JAVA_HOME",变量值"D:\jdk1.8.0_05"(即JD ...
- [D3JS] Add more map layer and color
import React, {Component} from 'react'; import * as d3 from 'd3'; import 'd3-geo'; import * as topoj ...
- 怎样让索引仅仅能被一个SQL使用
有个徒弟问我,要创建一个索引,去优化一个SQL,可是创建了索引之后其它 SQL 也要用 这个索引,其它SQL慢死了.要优化的SQL又快.遇到这样的问题咋搞? 一般遇到这样的问题还是非常少的.处理的方法 ...