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

本文共 1763 字,大约阅读时间需要 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"));

 

转载于:https://www.cnblogs.com/Answer1215/p/7377535.html

你可能感兴趣的文章
前端各种mate积累
查看>>
jQuery 1.7 发布了
查看>>
Python(软件目录结构规范)
查看>>
Windows多线程入门のCreateThread与_beginthreadex本质区别(转)
查看>>
Nginx配置文件(nginx.conf)配置详解1
查看>>
linux php编译安装
查看>>
name phone email正则表达式
查看>>
721. Accounts Merge
查看>>
「Unity」委托 将方法作为参数传递
查看>>
重置GNOME-TERMINAL
查看>>
redis哨兵集群、docker入门
查看>>
hihoCoder 1233 : Boxes(盒子)
查看>>
oracle中anyData数据类型的使用实例
查看>>
C++对vector里面的元素排序及取任意重叠区间
查看>>
软件测试——性能测试总结
查看>>
12.4站立会议
查看>>
Java Concurrentmodificationexception异常原因和解决方法
查看>>
客户端访问浏览器的流程
查看>>
codeforces水题100道 第二十二题 Codeforces Beta Round #89 (Div. 2) A. String Task (strings)
查看>>
c++||template
查看>>