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的更多相关文章

  1. [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 ...

  2. [TypeStyle] Style CSS pseudo elements with TypeStyle

    Just like pseudo-classes, pseudo-elements are added to selectors but instead of describing a special ...

  3. [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 ...

  4. [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 ...

  5. 章节十、4-CSS Classes---用多个CSS Classes定位元素

    以下演示操作以该网址中的输入框为例:https://learn.letskodeit.com/p/practice 一.使用input[class=inputs]验证元素是否唯一 注意:使用“clas ...

  6. [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 ...

  7. [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 ...

  8. 【转载】CSS规范

    原文地址:http://www.cnblogs.com/whitewolf/p/4491707.html 目录 HTML 语法 HTML5 doctype 语言属性(Language attribut ...

  9. 4.1HTML和Bootstrap css精华

    1.HTML 2.理解Bootstrap HTML元素告诉浏览器,他要表现的是什么类型的内容,当他们不提供任何关于如何显示内容的信息.如何显示内容的信息,由CSS提供. 本书仅包含足够的信息,让你查看 ...

随机推荐

  1. Laravel输出sql语句

    $queries = DB::getQueryLog();

  2. django第三方库

    1. django_celery_beat 作用:网页端配置定时任务 注意:1,需要迁移表格 2.需要注册app python3 manage.py makemigrations python3 ma ...

  3. GetInvocationList 委托链表

    最近发现C#程序初始化时在构造函数中,偶尔出现事件注册不成功.后查资料发现有GetInvocationList 这么一个获取类中的委托链表的函数, 使用方法如下: 1.在需委托的类(Class1)中增 ...

  4. 【习题 8-3 UVA - 12545】Bits Equalizer

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果1的个数第一个串比第2个串多. 那么就无解. 否则. 找几个位置去凑1 优先找'?'然后才是0的位置 剩余的全都用swap操作就 ...

  5. ORA-01653 无法在表空间扩展的解决办法 -- 增加表空间大小或给表空间增加数据文件

    转自原文 ORA-01653 无法在表空间扩展的解决办法 -- 增加表空间大小或给表空间增加数据文件 当前系统的数据量越来越大的,昨天还运行正常的数据库,突然无法使用了.经过定位发现是"OR ...

  6. HDU1050:Moving Tables

    pid=1050">Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. 【SSH高速进阶】——struts2简单的实例

    近期刚刚入门struts2.这里做一个简单的struts2实例来跟大家一起学习一下. 本例实现最简单的登陆,仅包括两个页面:login.jsp 用来输入username与password:succes ...

  8. 怎样将OpenStack部署到Hadoop

    随着信息时代的快速发展,大数据技术和私有云环境都非常实用;只是,假设将两者结合在一起.企业会获得巨大的利润.虽然结合两者会让环境变得更复杂.企业仍然能够看到将 OpenStack 私有云和 Apach ...

  9. Eclipse导入Maven项目出现错误:Unsupported IClasspathEntry kind=4

    使用Eclipse导入Maven项目失败,提示: An internal error occurred during: "Importing Maven projects". Un ...

  10. css基础属性

    color:设置文本颜色:属性值:1.表示颜色的英文单词,例如:red.blue.green.pink.purple.cyan等:2.十六进制表示法:#ff0000: 0.1.2...9.a.b.c. ...