From 11b098b93a565bc5b0da932e26ffce589ce10d67 Mon Sep 17 00:00:00 2001 From: Paul Cramer Date: Tue, 27 Aug 2024 16:51:36 -0700 Subject: [PATCH] Add playground light and dark modes --- .../nextjs-app-router/components/Demo.tsx | 21 ++++++++++++++++--- .../nextjs-app-router/tailwind.config.ts | 2 ++ tailwind.config.js | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/playground/nextjs-app-router/components/Demo.tsx b/playground/nextjs-app-router/components/Demo.tsx index efff0b6275..0a286cd607 100644 --- a/playground/nextjs-app-router/components/Demo.tsx +++ b/playground/nextjs-app-router/components/Demo.tsx @@ -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'; @@ -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 ( <>
OnchainKit Playground
-
+ + diff --git a/playground/nextjs-app-router/tailwind.config.ts b/playground/nextjs-app-router/tailwind.config.ts index f9a2bac218..50d7d4b26e 100644 --- a/playground/nextjs-app-router/tailwind.config.ts +++ b/playground/nextjs-app-router/tailwind.config.ts @@ -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: { diff --git a/tailwind.config.js b/tailwind.config.js index 3762c3625e..6f7fd72469 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,6 +1,7 @@ /** @type {import('tailwindcss').Config} */ export default { content: ['./src/**/*.{ts,tsx}'], + darkMode: ['class'], safelist: ['dark'], theme: { fontFamily: {