Skip to content

Commit

Permalink
Add playground light and dark modes
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcramer committed Aug 27, 2024
1 parent ccac2a1 commit 11b098b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
21 changes: 18 additions & 3 deletions playground/nextjs-app-router/components/Demo.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use client';
import { useContext, useEffect, useState } from 'react';
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 IdentityDemo from './demo/Identity';
import SwapDemo from './demo/Swap';
import TransactionDemo from './demo/Transaction';
Expand All @@ -12,15 +11,31 @@ import { ActiveComponent } from './form/active-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
onClick={toggleDarkMode}
className='rounded border border-gray-300 bg-white px-3 py-2 text-black transition-colors hover:bg-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:text-white dark:hover:bg-gray-700'
>
{isDarkMode ? 'Switch to Light Mode' : 'Switch to Dark Mode'}
</button>
<form className='mt-4 grid gap-8'>
<ActiveComponent />
<WalletType />
<Chain />
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 11b098b

Please sign in to comment.