Skip to content

Commit

Permalink
Merge pull request #27 from ledevmacedo/dark-mode
Browse files Browse the repository at this point in the history
Dark mode
  • Loading branch information
hasanharman authored Nov 17, 2024
2 parents 046d450 + 5656f0c commit 3d3ecbf
Show file tree
Hide file tree
Showing 12 changed files with 10,320 additions and 6,302 deletions.
1 change: 0 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ViewTransitions } from 'next-view-transitions'
import { Toaster } from 'sonner'
import localFont from 'next/font/local'
import NextTopLoader from 'nextjs-toploader'

import './globals.css'

import AllProviders from '@/providers'
Expand Down
33 changes: 18 additions & 15 deletions components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ import { FaXTwitter } from 'react-icons/fa6'

import Logo from '@/assets/logo.svg'
import { usePathname } from 'next/navigation'
import { ThemeSwitch } from '../ui/theme-switch'

type Tabs = {
name: string
href: string
isNewTab?: boolean
variant:
| 'default'
| 'destructive'
| 'outline'
| 'secondary'
| 'ghost'
| 'link'
| 'arrow'
| 'smile'
| 'linkHover2'
| null
| undefined
| 'default'
| 'destructive'
| 'outline'
| 'secondary'
| 'ghost'
| 'link'
| 'arrow'
| 'smile'
| 'linkHover2'
| null
| undefined
className?: string
isUpdated?: boolean
}
Expand All @@ -57,11 +58,11 @@ export default function Header() {

return (
<header className="max-w-5xl mx-auto flex justify-between items-center my-5 px-5 lg:px-0">
<Link href="/" className="cursor-pointer md:hidden">
<Link href="/" className="cursor-pointer md:hidden dark:bg-white dark:rounded-lg p-2">
<Logo className="w-9 h-9" />
</Link>
<nav className="hidden md:flex items-center gap-3">
<Link href="/" className="cursor-pointer">
<Link href="/" className="cursor-pointer dark:bg-white dark:rounded-lg p-1">
<Logo className="w-9 h-9" />
</Link>
{tabs.map((tab, i) => (
Expand Down Expand Up @@ -96,7 +97,7 @@ export default function Header() {
<Link href="/playground">
<Button
variant="gooeyLeft"
className="g-primary text-white rounded-full px-4"
className="g-primary rounded-full px-4"
>
Playground
</Button>
Expand All @@ -114,6 +115,7 @@ export default function Header() {
<FaXTwitter className="text-lg" />
</Button>
</Link>
<ThemeSwitch />
</div>

<nav className="md:hidden">
Expand Down Expand Up @@ -142,6 +144,7 @@ export default function Header() {
<FaXTwitter className="text-lg" />
</Button>
</Link>
<ThemeSwitch />
</div>

{tabs.map((tab) => (
Expand All @@ -157,7 +160,7 @@ export default function Header() {
</DrawerClose>
))}
<Link href="/playground">
<Button className="w-full bg-primary text-white px-2">
<Button className="w-full bg-primary px-2">
Playground
</Button>
</Link>
Expand Down
6 changes: 3 additions & 3 deletions components/sections/logos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ export default function Logos() {
BUILD WITH USING
</h3>
<div className="relative mt-6">
<Marquee className="max-w-full [--duration:40s]">
<Marquee className="max-w-full [--duration:40s] ">
{companies.map((item) => (
<div
key={item.name}
className="h-10 w-40 dark:brightness-0 dark:invert grayscale opacity-30 flex items-center gap-1"
className="h-10 w-40 grayscale opacity-30 flex items-center gap-1"
>
<Image
width={112}
height={40}
src={`https://avatars.githubusercontent.com/u/${item.img}`}
className="h-8 w-8 rounded"
className="h-8 w-8 rounded "
alt={item.name}
/>
<p className="text-sm whitespace-nowrap">{item.name}</p>
Expand Down
3 changes: 2 additions & 1 deletion components/ui/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const badgeVariants = cva(
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
new: "border-transparent bg-yellow-200 font-normal hover:bg-yellow-200/80 rounded dark:text-primary-foreground",
outline: "text-foreground",
},
},
Expand All @@ -25,7 +26,7 @@ const badgeVariants = cva(

export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}
VariantProps<typeof badgeVariants> { }

function Badge({ className, variant, ...props }: BadgeProps) {
return (
Expand Down
2 changes: 1 addition & 1 deletion components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface IconRefProps {

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
VariantProps<typeof buttonVariants> {
asChild?: boolean
}

Expand Down
40 changes: 40 additions & 0 deletions components/ui/theme-switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use client"

import * as React from "react"
import { Moon, Sun } from "lucide-react"
import { useTheme } from "next-themes"

import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"

export function ThemeSwitch() {
const { setTheme } = useTheme()

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="icon" className="rounded-full">
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
<span className="sr-only">Toggle theme</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => setTheme("light")}>
Light
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("dark")}>
Dark
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("system")}>
System
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}
11 changes: 9 additions & 2 deletions providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PostHogProvider } from 'posthog-js/react'
import { GoogleAnalytics } from '@next/third-parties/google'
import { OpenPanelComponent } from '@openpanel/nextjs'
import { Analytics } from '@vercel/analytics/react'

import { ThemeProvider } from './theme-provider'
const AllProviders = ({ children }: { children: ReactNode }) => {
if (typeof window !== 'undefined') {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY || '', {
Expand All @@ -16,7 +16,14 @@ const AllProviders = ({ children }: { children: ReactNode }) => {

return (
<PostHogProvider client={posthog}>
{children}
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
>
{children}
</ThemeProvider>
<Analytics />
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GA_ID || ''} />
<OpenPanelComponent
Expand Down
11 changes: 11 additions & 0 deletions providers/theme-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use client"

import * as React from "react"
import { ThemeProvider as NextThemesProvider } from "next-themes"

export function ThemeProvider({
children,
...props
}: React.ComponentProps<typeof NextThemesProvider>) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>
}
9 changes: 5 additions & 4 deletions screens/field-selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fieldTypes } from '@/constants'
import { Button } from '@/components/ui/button'
import If from '@/components/ui/if'
import Link from 'next/link'
import { Badge } from '@/components/ui/badge'

type FieldSelectorProps = {
addFormField: (variant: string, index?: number) => void
Expand All @@ -27,18 +28,18 @@ export const FieldSelector: React.FC<FieldSelectorProps> = ({
<If
condition={variant.isNew}
render={() => (
<div className="md:hidden ml-1 text-[10px] p-1 bg-yellow-200 rounded">
<Badge variant={'new'} className='md:hidden ml-1 p-1 text-[10px]'>
New
</div>
</Badge>
)}
/>
</Button>
<If
condition={variant.isNew}
render={() => (
<div className="hidden md:block ml-1 text-[10px] p-1 bg-yellow-200 rounded">
<Badge variant={'new'} className='hidden md:block ml-1 p-1 text-[10px]'>
New
</div>
</Badge>
)}
/>
</div>
Expand Down
8 changes: 4 additions & 4 deletions screens/form-builder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export default function FormBuilder() {
disabled: false,
label: label || newFieldName,
name: newFieldName,
onChange: () => {},
onSelect: () => {},
onChange: () => { },
onSelect: () => { },
placeholder: placeholder || 'Placeholder',
required: true,
rowIndex: index,
setValue: () => {},
setValue: () => { },
type: '',
value: '',
variant,
Expand Down Expand Up @@ -140,7 +140,7 @@ export default function FormBuilder() {
addFormField(variant, index)
}
/>
<div className="overflow-y-auto flex-1">
<div className="overflow-y-auto flex-1 ">
<FormFieldList
formFields={formFields}
setFormFields={setFormFields}
Expand Down
2 changes: 2 additions & 0 deletions screens/form-field-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormFieldType } from '@/types'
import { FieldItem } from '@/screens/field-item'

import { LuRows } from 'react-icons/lu'
import { Badge } from '@/components/ui/badge'

export type FormFieldOrGroup = FormFieldType | FormFieldType[]

Expand Down Expand Up @@ -40,6 +41,7 @@ export const FormFieldList: React.FC<FormFieldListProps> = ({

return (
<div className="mt-3 lg:mt-0">

<Reorder.Group
axis="y"
onReorder={setFormFields}
Expand Down
Loading

0 comments on commit 3d3ecbf

Please sign in to comment.