Skip to content

Commit

Permalink
chore: added light and dark mode in Playground (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcramer authored Aug 28, 2024
1 parent ccac2a1 commit 1c73305
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
28 changes: 25 additions & 3 deletions playground/nextjs-app-router/components/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,46 @@ import { AppContext, OnchainKitComponent } from '@/components/AppProvider';
import { Chain } from '@/components/form/chain';
import { PaymasterUrl } from '@/components/form/paymaster';
import { WalletType } from '@/components/form/wallet-type';
import { useContext, useEffect } from 'react';
import { useContext, useEffect, useState } from 'react';
import IdentityDemo from './demo/Identity';
import SwapDemo from './demo/Swap';
import TransactionDemo from './demo/Transaction';
import WalletDemo from './demo/Wallet';
import { ActiveComponent } from './form/active-component';

// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO Refactor this component
function Demo() {
const { activeComponent } = useContext(AppContext);
const [isDarkMode, setIsDarkMode] = useState(true);

useEffect(() => {
console.log('Playground.activeComponent:', activeComponent);
}, [activeComponent]);

useEffect(() => {
document.documentElement.classList.toggle('dark', isDarkMode);
}, [isDarkMode]);

const toggleDarkMode = () => {
setIsDarkMode(!isDarkMode);
};

return (
<>
<div className="hidden w-1/4 min-w-120 flex-col border-r bg-background p-6 sm:flex">
<div className="mb-12 font-semibold text-lg">OnchainKit Playground</div>
<form className="grid gap-8">
<button
type="button"
onClick={toggleDarkMode}
className={`rounded border px-3 py-2 transition-colors ${
isDarkMode
? 'border-gray-600 bg-gray-800 text-white hover:bg-gray-700'
: 'border-gray-300 bg-white text-black hover:bg-gray-100'
}`}
>
{isDarkMode ? 'Switch to Light Mode' : 'Switch to Dark Mode'}
</button>
<form className="mt-4 grid gap-8">
<ActiveComponent />
<WalletType />
<Chain />
Expand All @@ -36,7 +58,7 @@ function Demo() {
View Github
</a>
</div>
<div className="flex flex-1 flex-col bg-[linear-gradient(to_right,#f0f0f0_1px,transparent_1px),linear-gradient(to_bottom,#f0f0f0_1px,transparent_1px)] bg-[size:6rem_4rem]">
<div className="linear-gradient(to_bottom,#f0f0f0_1px,transparent_1px)] flex flex-1 flex-col bg-[linear-gradient(to_right,#f0f0f0_1px,transparent_1px), bg-[size:6rem_4rem]">
<div className="flex h-full w-full flex-col justify-center">
{activeComponent === OnchainKitComponent.Identity ? (
<IdentityDemo />
Expand Down
2 changes: 2 additions & 0 deletions playground/nextjs-app-router/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const config: Config = {
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
],
darkMode: ['class'],
safelist: ['dark'],
theme: {
extend: {
backgroundImage: {
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ['./src/**/*.{ts,tsx}'],
darkMode: ['class'],
safelist: ['dark'],
theme: {
fontFamily: {
Expand Down

0 comments on commit 1c73305

Please sign in to comment.