Skip to content

Commit

Permalink
add next theme with tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMelior committed Mar 8, 2024
1 parent e3b357a commit 2719445
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"rules": {
"selector-class-pattern": "^([a-z][a-zA-Z0-9]*)$",
"keyframes-name-pattern": "^([a-z][a-zA-Z0-9]*)$",
"color-function-notation": null,
"color-function-notation": "legacy",
"scss/at-rule-no-unknown": [
true,
{
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"next": "14.1.0",
"next-intl": "^3.8.0",
"next-themes": "^0.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
9 changes: 7 additions & 2 deletions src/app/providers/ClientProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
'use client';

import { Theme } from '@/shared/types';
import { ThemeProvider } from 'next-themes';
import { ReactNode } from 'react';

export function ClientProviders({ children }: { children: ReactNode }) {
// eslint-disable-next-line react/jsx-no-useless-fragment
return <>{children}</>;
return (
<ThemeProvider attribute='class' defaultTheme={Theme.DARK}>
{children}
</ThemeProvider>
);
}
9 changes: 3 additions & 6 deletions src/app/providers/ServerProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { ThemeProvider } from '@/app/providers/ThemeProvider';
import { NextIntlClientProvider, useMessages } from 'next-intl';
import { ReactNode } from 'react';

export function ServerProviders({ children }: { children: ReactNode }) {
const messages = useMessages();

return (
<ThemeProvider>
<NextIntlClientProvider messages={messages}>
{children}
</NextIntlClientProvider>
</ThemeProvider>
<NextIntlClientProvider messages={messages}>
{children}
</NextIntlClientProvider>
);
}
5 changes: 0 additions & 5 deletions src/app/providers/ThemeProvider/index.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/app/providers/ThemeProvider/lib/ThemeContext.ts

This file was deleted.

32 changes: 0 additions & 32 deletions src/app/providers/ThemeProvider/lib/useTheme.ts

This file was deleted.

43 changes: 0 additions & 43 deletions src/app/providers/ThemeProvider/ui/ThemeProvider.tsx

This file was deleted.

23 changes: 6 additions & 17 deletions src/app/styles/themes/light.scss
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
.app_light_theme {
[class="light"] {
--color-background: #fafafa;
--bg-dots: #cacaca;

--main-color: #FFFFFF;
--color-background-dots: #cacaca;
--color-main: #FFF;
--color-main-rgb: 255, 255, 255;

--color-main-inverted: #03020D;
--color-main-inverted-rgb: 3, 2, 13;

--primary-color: #30004e;
--inverted-primary-color: #B336FF;

--secondary-color: #001e6b;
--inverted-secondary-color: #346DFF;

--color-border: rgba(0, 0, 0, .1);
--color-border-select: rgba(0, 0, 0, .2);
--color-border-active: rgba(0, 0, 0, .2);

// text
--color-border: rgba(0, 0, 0, 10%);
--color-border-select: rgba(0, 0, 0, 20%);
--color-border-active: rgba(0, 0, 0, 20%);
--color-text: 0, 0, 0;

// Light ellipse
Expand Down
12 changes: 6 additions & 6 deletions src/app/styles/themes/normal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
--color-success: #17c964;
--color-warning: #f5a524;
--color-danger: #f31260;
--color-border: rgb(255 255 255 / 10%);
--color-border-select: rgb(255 255 255 / 15%);
--color-border-active: rgb(255 255 255 / 20%);
--color-border: rgba(255, 255, 255, 10%);
--color-border-select: rgb(255, 255, 255, 15%);
--color-border-active: rgb(255, 255, 255, 20%);
--color-text: 255, 255, 255;

// Light ellipse
--light-color-ellipse-1: rgb(90 186 255 / 30%);
--light-color-ellipse-1: rgb(90, 186, 255, 30%);
--light-blur-ellipse-1: blur(400px);
--light-color-ellipse-2: rgb(255 90 209 / 30%);
--light-color-ellipse-2: rgb(255, 90, 209, 30%);
--light-blur-ellipse-2: blur(600px);
--light-color-ellipse-3: rgb(255 90 209 / 30%);
--light-color-ellipse-3: rgb(255, 90, 209, 30%);
--light-blur-ellipse-3: blur(400px);

// @media (max-width: $display-desktop) {
Expand Down
20 changes: 13 additions & 7 deletions src/features/ThemeSwitcher/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
'use client';

import { Theme, useTheme } from '@/app/providers/ThemeProvider';
import DarkIcon from 'public/images/icons/theme-dark.svg';
import LightIcon from 'public/images/icons/theme-light.svg';
import { Theme } from '@/shared/types';
import { Button } from '@/shared/ui/Button';
import { useTheme } from 'next-themes';
import Moon from 'public/images/icons/moon.svg';
import { memo } from 'react';

interface ThemeSwitcherProps {
className?: string;
}

export const ThemeSwitcher = memo(({ className }: ThemeSwitcherProps) => {
const { theme, toggleTheme } = useTheme();
const { theme, setTheme } = useTheme();

const toggleTheme = () => {
const newTheme = theme === Theme.DARK ? Theme.LIGHT : Theme.DARK;
setTheme(newTheme);
};

return (
<button type='button' onClick={toggleTheme} className={className}>
{theme === Theme.DARK ? <DarkIcon /> : <LightIcon />}
</button>
<Button slice onClick={toggleTheme} className={className}>
<Moon />
</Button>
);
});
1 change: 0 additions & 1 deletion src/pages/TopPage/TopPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const TopPage: FC<TopPageProps> = memo(
<div className={`${cls.dots} noselect`} />
<Button
starlight
// padding='lg'
className='py-5 px-12 rounded-xl'
variant='layer'
startContent={
Expand Down
5 changes: 5 additions & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export type Size = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full';

export type clsxMods = Record<string, boolean | string | undefined>;

export enum Theme {
LIGHT = 'light',
DARK = 'dark',
}
14 changes: 13 additions & 1 deletion src/shared/ui/Blackhole/Blackhole.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client';

import cn from 'clsx';
import { FC } from 'react';
import { FC, useEffect, useState } from 'react';
import cls from './Blackhole.module.scss';

interface BlackholeProps {
Expand All @@ -8,6 +10,16 @@ interface BlackholeProps {
}

export const Blackhole: FC<BlackholeProps> = ({ className = '', flip }) => {
const [mounted, setMounted] = useState(false);

useEffect(() => {
setMounted(true);
}, []);

if (!mounted) {
return null;
}

return (
<div
className={cn(cls.blackhole, { [cls.flip]: flip }, className, 'noselect')}
Expand Down
3 changes: 2 additions & 1 deletion src/shared/ui/SpaceCanvas/SpaceCanvas.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use client';

import { Theme, useTheme } from '@/app/providers/ThemeProvider';
import { Theme } from '@/shared/types';
import { PointMaterial, Points } from '@react-three/drei';
import { Canvas, useFrame } from '@react-three/fiber';
import cn from 'clsx';
import { Suspense, useEffect, useRef, useState } from 'react';
// @ts-ignore
import * as random from 'maath/random/dist/maath-random.esm';
import { useTheme } from 'next-themes';
import cls from './SpaceCanvas.module.scss';

const StarBackground = (props: any) => {
Expand Down
10 changes: 2 additions & 8 deletions src/widgets/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
'use client';

import { useTheme } from '@/app/providers/ThemeProvider';
import { LangSwitcher } from '@/features/LangSwitcher';
import { ThemeSwitcher } from '@/features/ThemeSwitcher';
import { Link, usePathname } from '@/shared/config/i18n/navigation';
import { Avatar } from '@/shared/ui/Avatar';
import { Button } from '@/shared/ui/Button';
import { Input } from '@/shared/ui/Input';
import { Logo } from '@/shared/ui/Logo';
import { Loader } from '@/widgets/Loader';
import cn from 'clsx';
import { useTranslations } from 'next-intl';
import Image from 'next/image';
import Moon from 'public/images/icons/moon.svg';
import { memo } from 'react';
import cls from './Navbar.module.scss';

Expand All @@ -36,7 +34,6 @@ export const Navbar = memo(({ className = '', blackhole }: NavbarProps) => {

const t = useTranslations();
const pathname = usePathname();
const { theme, toggleTheme } = useTheme();

const isActive = (href: string) => {
return pathname === href ? cls.selected : '';
Expand Down Expand Up @@ -92,10 +89,7 @@ export const Navbar = memo(({ className = '', blackhole }: NavbarProps) => {
<nav className={cls.right}>
<nav className={cls.controlButtons}>
<LangSwitcher />
<Button slice onClick={toggleTheme}>
<Moon />
</Button>
{/* <ThemeSwitcher /> */}
<ThemeSwitcher />
</nav>
<Avatar
border
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ module.exports = {
extend: {},
},
plugins: [],
darkMode: 'class',
};

0 comments on commit 2719445

Please sign in to comment.