styled-components all in one
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 发布文章使用:只允许注册用户才可以访问!
styled-components all in one的更多相关文章
- styled components草根中文版文档
		
1.styled components官网网址 https://www.styled-components.com/docs 以组件的形式来写样式. 1.1安装 yarn add styled-c ...
 - 6周学习计划,攻克JavaScript难关(React/Redux/ES6 etc.)
		
作者:余博伦链接:https://zhuanlan.zhihu.com/p/23412169来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 和大家一样,最近我也看了Jo ...
 - 大前端的自动化工厂(2)—— SB Family
		
原文链接:https://bbs.huaweicloud.com/blogs/53c0c3509b7a11e89fc57ca23e93a89f 我坦白我是标题党,SB只是SCSS-Bourbon的简写 ...
 - 使用styled-components实现CSS in JS
		
前面的话 使用jsx语法可以实现HTML in JS,使用svgr可以实现svg in JS,使用styled-components可以实现CSS in JS.这样,使用react开发,就变成了使用J ...
 - Next.js v4.1.4 文档中文翻译【转载】
		
最近想稍稍看下 React的 SSR框架 Next.js,因为不想看二手资料, 所以自己跑到 Github上看,Next.js的文档是英文的,看倒是大概也能看得懂, 但有些地方不太确定,而且英文看着毕 ...
 - CSS Overrides: Friend or Foe?
		
转自:http://www.callumhart.com/blog/css-overrides-friend-or-foe Anyone familiar with CSS will know how ...
 - 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 实际上 wix 的 styl ...
 - 推荐 9 个样式化组件的 React UI 库
		
简评:喜欢 CSS in JS 吗?本文将介绍一些使用样式组件所构建的 React UI 库,相信你会很感兴趣的. 在 React 社区,对 UI 组件进行样式化的讨论逐步从 CSS 模块到内联 CS ...
 - The Road to learn React书籍学习笔记(第一章)
		
react灵活的生态圈 Small Application Boilerplate: create-react-app Utility: JavaScript ES6 and beyond Styli ...
 - Angular Vue React 框架中的 CSS
		
框架中的 CSS Angular Vue React 三大框架 Angular Vue 内置样式集成 React 一些业界实践 Angular Angular . js (1.x):没有样式集成能力 ...
 
随机推荐
- 用xmind设计用例:
			
注意一个原则:清晰明了,简单高效 注意不要写成需求分析,从测试的角度对场景进行分类管理 注意点: 1.思维导图重要的是逻辑清晰归类,注意有不要太多具体的操作步骤 举个例子(来源:https://www ...
 - Linux下nf_conntrack(最全面)_董明磊-CSDN博客_nf_conntrack https://blog.csdn.net/qq_35299863/article/details/79530732
			
Linux下nf_conntrack(最全面)_董明磊-CSDN博客_nf_conntrack https://blog.csdn.net/qq_35299863/article/details/79 ...
 - 熟悉而陌生API:Promise
			
前言 ES6 发布到现在差不多有5年时间了.在这5年时间里ES6摧枯拉朽般的将现代前端"改朝换代",Promise是其中"大将"般的存在,影响着无数的前端库和A ...
 - slowhttptest慢速攻击工具使用详解
			
参考文章 浅谈"慢速HTTP攻击Slow HTTP Attack" HTTP慢速攻击 Slowhttptest攻击原理 InstallationAndUsage tag: #slo ...
 - Java——I/O入门相关练习代码
			
流的概念 读取文件 读取文件1 读取文件2 读取文件3 读取文件4 skip跳过n个字节后再开始读取 读取过程中暂停给当前位置做一个标记下一次从标记位置开始读取 序列流集合流 把三个流添加到集合中合并 ...
 - freemarket+itext+springboot将html静态页面渲染后导出为pdf文件
			
1.maven依赖 <dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf& ...
 - MySQL复合索引探究
			
复合索引(又称为联合索引),是在多个列上创建的索引.创建复合索引最重要的是列顺序的选择,这关系到索引能否使用上,或者影响多少个谓词条件能使用上索引.复合索引的使用遵循最左匹配原则,只有索引左边的列匹配 ...
 - 四. SpringCloud负载均衡与调用
			
1. Ribbon概述 1.1 Ribbon是什么 SpringCloud Ribbon是基于Netflix Ribbon实现的一套客户端,是负载均衡的工具. Ribbon是Netflix发布的开源项 ...
 - Educational Codeforces Round 86 (Div. 2)
			
比赛链接:https://codeforces.com/contest/1342 A - Road To Zero 题意 有两个非负整数 x, y 以及两种操作: 支付 a 点代价使其中一个数加一或减 ...
 - P1714 切蛋糕  单调队列
			
题目: 题目描述 今天是小Z的生日,同学们为他带来了一块蛋糕.这块蛋糕是一个长方体,被用不同色彩分成了N个相同的小块,每小块都有对应的幸运值. 小Z作为寿星,自然希望吃到的第一块蛋糕的幸运值总和最大, ...