[React] Theme your application with styled-components and "ThemeProvider"
In this styled-components lesson, we set a "primary color" within a UI "theme" object. We make this theme accessible to all components by wrapping our application inside a .
Define a theme object:
const theme = {
primary: "#a04ed9"
};
Add provider:
import { ThemeProvider } from "styled-components";
ReactDOM.render(
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>,
document.getElementById("root")
);
Use the theme from props:
import React from "react";
import styled from "styled-components"; const Button = styled.button`
background: ${props => props.theme.primary};
color: white;
font-size: 1rem;
padding: .75rem 2rem;
box-shadow: 3px 5px rgba(,,,0.1);
cursor: pointer;
border: none;
border-radius: 4px;
`; export default props => <Button>{props.children}</Button>;
[React] Theme your application with styled-components and "ThemeProvider"的更多相关文章
- styled components草根中文版文档
1.styled components官网网址 https://www.styled-components.com/docs 以组件的形式来写样式. 1.1安装 yarn add styled-c ...
- [React Fundamentals] Using Refs to Access Components
When you are using React components you need to be able to access specific references to individual ...
- [React] React Fundamentals: Using Refs to Access Components
When you are using React components you need to be able to access specific references to individual ...
- [React] Prevent Unnecessary Rerenders of Compound Components using React Context
Due to the way that React Context Providers work, our current implementation re-renders all our comp ...
- The Road to learn React书籍学习笔记(第一章)
react灵活的生态圈 Small Application Boilerplate: create-react-app Utility: JavaScript ES6 and beyond Styli ...
- 使用create react app教程
This project was bootstrapped with Create React App. Below you will find some information on how to ...
- 6周学习计划,攻克JavaScript难关(React/Redux/ES6 etc.)
作者:余博伦链接:https://zhuanlan.zhihu.com/p/23412169来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 和大家一样,最近我也看了Jo ...
- Angular 2 to Angular 4 with Angular Material UI Components
Download Source - 955.2 KB Content Part 1: Angular2 Setup in Visual Studio 2017, Basic CRUD applicat ...
- 推荐 9 个样式化组件的 React UI 库
简评:喜欢 CSS in JS 吗?本文将介绍一些使用样式组件所构建的 React UI 库,相信你会很感兴趣的. 在 React 社区,对 UI 组件进行样式化的讨论逐步从 CSS 模块到内联 CS ...
随机推荐
- javaScript 原型与原型链学习笔记
javaScript中,原型是常用到一种方式,它能降低储存占用,写出更高效的代码 原型常用到的则是prototype属性 JavaScript prototype 属性 定义和用法 prototype ...
- Unity 实现Log实时输出到屏幕或控制台上<一>
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/49818953 作者:car ...
- mysql省市区数据库表源码
下载 一:创建表 1省: create table CREATE TABLE `provinces` ( `id` ) NOT NULL AUTO_INCREMENT, `provinceid` ...
- PyCharm激活方法
1.激活码激活 1.修改hosts文件 将0.0.0.0 account.jetbrains.com添加到hosts文件最后,windows系统hosts文件路径为:C:\windows\system ...
- Mysql学习总结(9)——MySql视图原理讲解与使用大全
一. 视图概述 视图是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据来自由定义视图的查询所引用的表,并且 ...
- php将数组或字符串写入文件
//将数组保存在文件里 function export_to_file($file, $variable) { $fopen = fopen($file, 'wb'); if (!$fopen) { ...
- OpenCV —— 摄像机模型与标定
这种理论看的已经够多了,感觉应用价值不大(矫正畸变图像还凑合,用摄像机测距神马的...) 有始有终吧,简单把内容梳理一下 针孔 摄像机模型 —— 过于理想(不能为快速曝光收集足够的光线) 透镜可以聚 ...
- tortoisegit--无法commit
tortoisegit--无法提交,好几次使用tortoisegit,commit的时候出现卡死的情况,导致无法提交代码. 分析错误以为是: 电脑的性功能有关,但重启好几次电脑一人无济于事,打开任务管 ...
- python的循环测试
这段代码要实现的是:猜数字58 ,猜三次,三个判断条件和一个结束条件.判断为等于58的时候跳出循环. 首先定义一个固定变量 int 函数是更改input输入的文字类型 if guess_age == ...
- fg、bg、jobs、&、 ctrl+z---系统任务
系统任务有关的命令 一.& 这个用在一个命令的最后,可以把这个命令放到后台执行 二.ctrl + z 可以将一个正在前台执行的命令放到后台,并且暂停 一和二的区别(&放入后 ...