styled-components all in one

CSS in JS

https://www.styled-components.com/

https://github.com/styled-components

# install
$ yarn add styled-components $ npm i -S styled-components
import styled from 'styled-components'

// const Button = styled.button``

const Button = styled.button`
background: transparent;
border-radius: 3px;
border: 2px solid palevioletred;
color: palevioletred;
margin: 0 1em;
padding: 0.25em 1em;
`
import styled, { css } from 'styled-components'

const Button = styled.button`
background: transparent;
border-radius: 3px;
border: 2px solid palevioletred;
color: palevioletred;
margin: 0 1em;
padding: 0.25em 1em; ${props =>
props.primary &&
css`
background: palevioletred;
color: white;
`};
`
const Button = styled.button`
background: transparent;
border-radius: 3px;
border: 2px solid palevioletred;
color: palevioletred;
margin: 0.5em 1em;
padding: 0.25em 1em;
${props => props.primary && css`
background: palevioletred;
color: white;
`}
`;
const Container = styled.div`
text-align: center;
`
render(
<Container>
<Button>Normal Button</Button>
<Button primary>Primary Button</Button>
</Container>
);

demos


const Button = styled.a`
/* This renders the buttons above... Edit me! */
display: inline-block;
border-radius: 3px;
padding: 0.5rem 0;
margin: 0.5rem 1rem;
width: 11rem;
background: transparent;
color: white;
border: 2px solid white; /* The GitHub button is a primary button
* edit this to target it specifically! */
${props => props.primary && css`
background: white;
color: black;
`}
` render(
<div>
<Button
href="https://github.com/styled-components/styled-components"
target="_blank"
rel="noopener"
primary
>
GitHub
</Button> <Button as={Link} href="/docs">
Documentation
</Button>
</div>
)
const Button = styled.a`
/* This renders the buttons above... Edit me! */
display: inline-block;
border-radius: 3px;
padding: 0.5rem 0;
margin: 0.5rem 1rem;
width: 11rem;
background: transparent;
color: white;
border: 2px solid white;
/* The GitHub button is a primary button
* edit this to target it specifically! */
${props => props.primary && css`
background: white;
color: black;
`}
`
render(
<div>
<Button
href="https://github.com/styled-components/styled-components"
target="_blank"
rel="noopener"
primary
>
GitHub
</Button>
<Button as={Link} href="/docs">
Documentation
</Button>
</div>
)

tagged templates

`string text`

`string text line 1
string text line 2` `string text ${expression} string text` tag`string text ${expression} string text`

demo

"use strict";

/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-09-21
* @modified
*
* @description
* @difficulty Easy Medium Hard
* @complexity O(n)
* @augments
* @example
* @link
* @solutions
*
* @best_solutions
*
*/ const log = console.log; // tagged templates const name = `xgqfrms`;
const age = 23;
const title = "CEO"; const taggedTemplateFunc = (strs, arg1, arg2, ...args) => {
log(`\nstrs`, strs);
log(`arg1`, arg1);
log(`arg2`, arg2);
log(`args`, args);
return strs[0] + arg1 + strs[1] + arg2;
} taggedTemplateFunc`name=${name}, age=${age}, title=${title}`; const q = `what's your name`; taggedTemplateFunc`${q}, name=${name}, age=${age}, title=${title}`; /* $ node tagged-templates.js strs [ 'name=', ', age=', ', title=', '' ]
arg1 xgqfrms
arg2 23
args [ 'CEO' ] strs [ '', ', name=', ', age=', ', title=', '' ]
arg1 what's your name
arg2 xgqfrms
args [ 23, 'CEO' ] */

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates

let person = 'Mike';
let age = 28; function myTag(strings, personExp, ageExp) {
let str0 = strings[0]; // "That "
let str1 = strings[1]; // " is a "
// let str2 = strings[2]; // ""
// There is technically a string after the final expression (in our example), but it is empty (""), so disregard.
let ageStr;
if (ageExp > 99){
ageStr = 'centenarian';
} else {
ageStr = 'youngster';
}
// We can even return a string built using a template literal
return `${str0}${personExp}${str1}${ageStr}`;
} let output = myTag`That ${person} is a ${age}`; console.log(output);
// That Mike is a youngster

refs

https://www.cnblogs.com/xgqfrms/p/10043199.html



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


最新文章

  1. 前端:IE兼容性的相关方法
  2. [NOIP2015] 斗地主(搜索)
  3. R随笔(2)
  4. Apache+Mod_Python配置
  5. 2.django笔记之缓存,session,cookie,ajax
  6. Problem F: Exponentiation大数求幂
  7. 一步一步实现基于Task的Promise库(一)Promise的基本实现
  8. Spring 依赖注入的理解
  9. RxJava在Android中使用场景详解
  10. 认识浏览器请求头User-Agent
  11. 什么是DAPP
  12. robot framework中的返回值
  13. Grunt: 拼接代码,js丑化(压缩),css压缩,html压缩,观察文件,拷贝文件,删除文件,压缩文件
  14. apache的bin目录下的apxs有什么作用? PHP模块加载运行方式
  15. javascript删除Cookie的正确方法(转载)
  16. Path Sum II leetcode java
  17. 【20181102T1】优美的序列【二分+ST表】
  18. c++ 参数个数可变的函数
  19. .net中的lock
  20. linux下tar.gz、tar、bz2、zip等解压缩、压缩命令小结(转载)

热门文章

  1. a.default.ERROR.httpAjax is not a function
  2. 服务发现 ap cp 强一致性 最终一致性 dns vip ip
  3. 作为一款内存数据库,为什么断电后Redis数据不会丢失
  4. 【Soul网关探秘】http数据同步-Web端处理变更通知
  5. Java 实现Redis客户端,服务端
  6. Ceph对象存储 S3
  7. ssh登陆时,参数直接加入密码
  8. java获取post请求头部字符串
  9. DEDECMS:删除DEDE自带的织梦链方法
  10. 【函数分享】每日PHP函数分享(2021-2-5)