博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[React] Create component variations in React with styled-components and "extend"
阅读量:6983 次
发布时间:2019-06-27

本文共 1709 字,大约阅读时间需要 5 分钟。

In this lesson, we extend the styles of a base button component to create multiple variations of buttons, using "extend". We can then modify the base styles in one place, and have all button types updated.

 

import React from "react";import styled from "styled-components";const Button = styled.button`  background: ${props => props.theme.base};  color: white;  font-size: 1rem;  padding: .75rem 2rem;  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.1);  cursor: pointer;  border: none;  border-radius: 4px;  margin: .5rem;  transition: all 0.1s;  &:hover {    transform: translateY(1px);    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.15);  }`;const ButtonDanger = Button.extend`background: ${props => props.theme.danger};`;const ButtonGradient = Button.extend`  background: ${props => props.theme.gradient};`;/* ============================== *//* ===== the main component ===== *//* ============================== */const App = () =>  
Watch out now!
Gradient Button!
;export default App;

 

theme:

import React from "react";import ReactDOM from "react-dom";import App from "./App";import { ThemeProvider, injectGlobal } from "styled-components";injectGlobal`  body {    margin: 0;    padding: 2rem;    font-family: -apple-system,      BlinkMacSystemFont,      "Segoe UI",      Roboto,      Helvetica,      Arial,      sans-serif,      "Apple Color Emoji",      "Segoe UI Emoji",      "Segoe UI Symbol";  }`;const theme = {  base: "#a04ed9",  danger: "tomato",  gradient: `background-color: #00DBDE; background-image: linear-gradient(225deg, #00DBDE 0%, #FC00FF 100%);`};ReactDOM.render(  
, document.getElementById("root"));

 

转载地址:http://pdtpl.baihongyu.com/

你可能感兴趣的文章
当精准广告遇到大数据
查看>>
《机器人自动化:建模、仿真与控制》——2.3 仿真
查看>>
泰一指尚大数据应用成为第一批省级重点企业研究院
查看>>
预测未来 盘点大数据分析领域五大趋势
查看>>
教你编写Node.js中间件,实现服务端缓存
查看>>
又到中元节 应用宝教你如何打败各种鬼
查看>>
资源大集中 浪潮I9000刀片为国家税务总局打造全能型平台
查看>>
PC如何接管手机的双因子身份验证 靠的是英特尔的CPU
查看>>
分析:“AI on Hadoop”有意义吗?
查看>>
起底英特尔大数据
查看>>
《中国人工智能学会通讯》——11.65 双重代价敏感的属性分类模型
查看>>
阿里云人工智能ET夺肺结节诊断世界冠军
查看>>
研究人员发现利用Excel宏可发起跳板攻击
查看>>
绿盟科技发布OpenSSL高危漏洞技术分析与防护方案 G20成员国美国、中国、德国受影响较大...
查看>>
《VMware Virtual SAN权威指南》一2.2.4 容量层设备
查看>>
物联网发展年报显示 2016年智能家居市场快速增长
查看>>
如何在React中做到jQuery-free
查看>>
4G+宽带高歌猛进:移动双线虐杀联通
查看>>
带你了解超大规模数据中心究竟有何不同?
查看>>
用Python实现每秒处理120万次HTTP请求
查看>>