Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add light and dark mode in Playground #1175

Merged
merged 7 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to cut this into multiple lines but the linter is preventing it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use cn of clx for this

<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