Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request scaffold-eth#122 from calvbore/nightmode
Browse files Browse the repository at this point in the history
Add dark theme switch
  • Loading branch information
austintgriffith authored Mar 8, 2021
2 parents 45a909a + 27d77af commit 2a2acd6
Show file tree
Hide file tree
Showing 18 changed files with 1,467 additions and 76 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"graph-remove-local": "yarn workspace @scaffold-eth/subgraph graph remove --node http://localhost:8020/ scaffold-eth/your-contract",
"graph-deploy-local": "yarn workspace @scaffold-eth/subgraph graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 scaffold-eth/your-contract",
"graph-ship-local": "yarn graph-prepare && yarn graph-codegen && yarn graph-deploy-local",
"deploy-and-graph": "yarn deploy && yarn graph-ship-local"
"deploy-and-graph": "yarn deploy && yarn graph-ship-local",
"theme": "yarn workspace @scaffold-eth/react-app theme",
"watch-theme": "yarn workspace @scaffold-eth/react-app watch"
},
"workspaces": {
"packages": [
Expand Down
28 changes: 28 additions & 0 deletions packages/react-app/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const gulp = require('gulp')
const gulpless = require('gulp-less')
const postcss = require('gulp-postcss')
const debug = require('gulp-debug')
var csso = require('gulp-csso')
const autoprefixer = require('autoprefixer')
const NpmImportPlugin = require('less-plugin-npm-import')

gulp.task('less', function () {
const plugins = [autoprefixer()]

return gulp
.src('src/themes/*-theme.less')
.pipe(debug({title: 'Less files:'}))
.pipe(
gulpless({
javascriptEnabled: true,
plugins: [new NpmImportPlugin({prefix: '~'})],
}),
)
.pipe(postcss(plugins))
.pipe(
csso({
debug: true,
}),
)
.pipe(gulp.dest('./public'))
})
14 changes: 13 additions & 1 deletion packages/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@
"graphiql": "^1.0.5",
"graphql": "^15.3.0",
"isomorphic-fetch": "^3.0.0",
"node-watch": "^0.7.1",
"postcss": "^8.2.6",
"qrcode.react": "^1.0.0",
"react": "^16.14.0",
"react-blockies": "^1.4.1",
"react-css-theme-switcher": "^0.2.2",
"react-dom": "^16.14.0",
"react-qr-reader": "^2.2.1",
"react-router-dom": "^5.2.0",
Expand All @@ -56,13 +59,20 @@
"devDependencies": {
"@testing-library/dom": "^6.12.2",
"@types/react": "^16.9.19",
"autoprefixer": "^10.2.4",
"chalk": "^4.1.0",
"eslint": "^7.5.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-prettier": "^3.1.4",
"gulp": "^4.0.2",
"gulp-csso": "^4.0.1",
"gulp-debug": "^4.0.0",
"gulp-less": "^4.0.1",
"gulp-postcss": "^9.0.0",
"ipfs-http-client": "^45.0.0",
"less-plugin-npm-import": "^2.1.0",
"prettier": "^2.0.5",
"s3-folder-upload": "^2.3.1",
"surge": "^0.21.5"
Expand All @@ -79,6 +89,8 @@
"ipfs": "node ./scripts/ipfs.js",
"surge": "surge ./build",
"s3": "node ./scripts/s3.js",
"ship": "yarn surge"
"ship": "yarn surge",
"theme": "npx gulp less",
"watch": "node ./scripts/watch.js"
}
}
1 change: 1 addition & 0 deletions packages/react-app/public/dark-theme.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/react-app/public/light-theme.css

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions packages/react-app/scripts/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const watch = require("node-watch");
const { exec } = require("child_process");

const run = () => {
console.log("Compiling & Generating...");
exec("npx gulp less", function (error, stdout, stderr) {
console.log(stdout);
if (error) console.log(error);
if (stderr) console.log(stderr);
});
};

console.log("🔬 Watching Themes...");
watch("./src/themes", { recursive: true }, function (evt, name) {
console.log("%s changed.", name);
run();
});
run();
7 changes: 5 additions & 2 deletions packages/react-app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { BrowserRouter, Switch, Route, Link } from "react-router-dom";
import "antd/dist/antd.css";
import { JsonRpcProvider, Web3Provider } from "@ethersproject/providers";
import "./App.css";
import { Row, Col, Button, Menu, Alert } from "antd";
import { Row, Col, Button, Menu, Alert, Switch as SwitchD } from "antd";
import Web3Modal from "web3modal";
import WalletConnectProvider from "@walletconnect/web3-provider";
import { useUserAddress } from "eth-hooks";
import { useExchangePrice, useGasPrice, useUserProvider, useContractLoader, useContractReader, useEventListener, useBalance, useExternalContractLoader } from "./hooks";
import { Header, Account, Faucet, Ramp, Contract, GasGauge } from "./components";
import { Header, Account, Faucet, Ramp, Contract, GasGauge, ThemeSwitch } from "./components";
import { Transactor } from "./helpers";
import { formatEther, parseEther } from "@ethersproject/units";
//import Hints from "./Hints";
import { Hints, ExampleUI, Subgraph } from "./views"
import { useThemeSwitcher } from "react-css-theme-switcher";
import { INFURA_ID, DAI_ADDRESS, DAI_ABI, NETWORK, NETWORKS } from "./constants";
/*
Welcome to 🏗 scaffold-eth !
Expand Down Expand Up @@ -291,6 +292,8 @@ function App(props) {
</Switch>
</BrowserRouter>

<ThemeSwitch />


{/* 👨‍💼 Your account is in the top right with a wallet at connect options */}
<div style={{ position: "fixed", textAlign: "right", right: 0, top: 0, padding: 10 }}>
Expand Down
6 changes: 3 additions & 3 deletions packages/react-app/src/components/Address.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function Address(props) {
if (props.minimized) {
return (
<span style={{ verticalAlign: "middle" }}>
<a style={{ color: "#222222" }} target={"_blank"} href={etherscanLink} rel="noopener noreferrer">
<a /*style={{ color: "#222222" }}*/ target={"_blank"} href={etherscanLink} rel="noopener noreferrer">
<Blockies seed={address.toLowerCase()} size={8} scale={2} />
</a>
</span>
Expand All @@ -71,15 +71,15 @@ export default function Address(props) {
if (props.onChange) {
text = (
<Text editable={{ onChange: props.onChange }} copyable={{ text: address }}>
<a style={{ color: "#222222" }} target={"_blank"} href={etherscanLink} rel="noopener noreferrer">
<a /*style={{ color: "#222222" }}*/ target={"_blank"} href={etherscanLink} rel="noopener noreferrer">
{displayAddress}
</a>
</Text>
);
} else {
text = (
<Text copyable={{ text: address }}>
<a style={{ color: "#222222" }} target={"_blank"} href={etherscanLink} rel="noopener noreferrer">
<a /*style={{ color: "#222222" }}*/ target={"_blank"} href={etherscanLink} rel="noopener noreferrer">
{displayAddress}
</a>
</Text>
Expand Down
6 changes: 3 additions & 3 deletions packages/react-app/src/components/Contract/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const noContractDisplay = (
Loading...{" "}
<div style={{ padding: 32 }}>
You need to run{" "}
<span style={{ marginLeft: 4, backgroundColor: "#f1f1f1", padding: 4, borderRadius: 4, fontWeight: "bolder" }}>
<span class="highlight" style={{ marginLeft: 4, /*backgroundColor: "#f1f1f1",*/ padding: 4, borderRadius: 4, fontWeight: "bolder" }}>
yarn run chain
</span>{" "}
and{" "}
<span style={{ marginLeft: 4, backgroundColor: "#f1f1f1", padding: 4, borderRadius: 4, fontWeight: "bolder" }}>
<span class="highlight" style={{ marginLeft: 4, /*backgroundColor: "#f1f1f1",*/ padding: 4, borderRadius: 4, fontWeight: "bolder" }}>
yarn run deploy
</span>{" "}
to see your contract here.
Expand All @@ -24,7 +24,7 @@ const noContractDisplay = (
☢️
</span>
Warning: You might need to run
<span style={{ marginLeft: 4, backgroundColor: "#f1f1f1", padding: 4, borderRadius: 4, fontWeight: "bolder" }}>
<span class="highlight" style={{ marginLeft: 4, /*backgroundColor: "#f1f1f1",*/ padding: 4, borderRadius: 4, fontWeight: "bolder" }}>
yarn run deploy
</span>{" "}
<i>again</i> after the frontend comes up!
Expand Down
31 changes: 31 additions & 0 deletions packages/react-app/src/components/ThemeSwitch.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useEffect, useState } from "react";
import { Switch } from "antd";
import { useThemeSwitcher } from "react-css-theme-switcher";

export default function ThemeSwitcher() {

const theme = window.localStorage.getItem("theme");
const [isDarkMode, setIsDarkMode] = useState(!theme || theme == "light" ? false : true);
const { switcher, currentTheme, status, themes } = useThemeSwitcher();

useEffect(() => {
window.localStorage.setItem("theme", currentTheme);
}, [currentTheme]);

const toggleTheme = (isChecked) => {
setIsDarkMode(isChecked);
switcher({ theme: isChecked ? themes.dark : themes.light });
};

// Avoid theme change flicker
// if (status === "loading") {
// return null;
// }

return (
<div className="main fade-in" style={{paddingTop: "60px", paddingBottom: "170px"}}>
<h2>The current theme is: {currentTheme ? currentTheme : "light"}</h2>
<Switch checked={isDarkMode} onChange={toggleTheme} />
</div>
);
}
2 changes: 1 addition & 1 deletion packages/react-app/src/components/Wallet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function Wallet(props) {
rotate={-90}
style={{
padding: 7,
color: props.color ? props.color : "#1890ff",
color: props.color ? props.color : "",
cursor: "pointer",
fontSize: 28,
verticalAlign: "middle",
Expand Down
1 change: 1 addition & 0 deletions packages/react-app/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export { default as Timeline } from "./Timeline";
export { default as GasGauge } from "./GasGauge";
export { default as BytesStringInput } from "./BytesStringInput";
export { default as Swap } from "./Swap";
export { default as ThemeSwitch } from "./ThemeSwitch";
13 changes: 12 additions & 1 deletion packages/react-app/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client";
import "./index.css";
import App from "./App";

import { ThemeSwitcherProvider } from "react-css-theme-switcher";

const themes = {
dark: `${process.env.PUBLIC_URL}/dark-theme.css`,
light: `${process.env.PUBLIC_URL}/light-theme.css`,
};

const prevTheme = window.localStorage.getItem("theme");

let subgraphUri = "http://localhost:8000/subgraphs/name/scaffold-eth/your-contract"

const client = new ApolloClient({
Expand All @@ -13,7 +22,9 @@ const client = new ApolloClient({

ReactDOM.render(
<ApolloProvider client={client}>
<App subgraphUri={subgraphUri}/>
<ThemeSwitcherProvider themeMap={themes} defaultTheme={prevTheme ? prevTheme : "light"}>
<App subgraphUri={subgraphUri}/>
</ThemeSwitcherProvider>
</ApolloProvider>,
document.getElementById("root"),
);
24 changes: 24 additions & 0 deletions packages/react-app/src/themes/dark-theme.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import "~antd/lib/style/color/colorPalette.less";
@import "~antd/dist/antd.less";
@import "~antd/lib/style/themes/dark.less";

// These are shared variables that can be extracted to their own file
@primary-color: #2caad9;
@border-radius-base: 4px;

@component-background: #212121;
@body-background: #212121;
@popover-background: #212121;
@border-color-base: #6f6c6c;
@border-color-split: #424242;
@table-header-sort-active-bg: #424242;
@card-skeleton-bg: #424242;
@skeleton-color: #424242;
@table-header-sort-active-bg: #424242;

@link-color: @text-color;
@icon-color: @primary-color;

.highlight {
background-color: #3f3f3f;
}
14 changes: 14 additions & 0 deletions packages/react-app/src/themes/light-theme.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import "~antd/lib/style/color/colorPalette.less";
@import "~antd/dist/antd.less";
@import "~antd/lib/style/themes/default.less";

// These are shared variables that can be extracted to their own file
// @primary-color: #00adb5;
@border-radius-base: 4px;

@link-color: @text-color;
@icon-color: @primary-color;

.highlight {
background-color: #f9f9f9;
}
Loading

0 comments on commit 2a2acd6

Please sign in to comment.