Skip to content
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
24 changes: 24 additions & 0 deletions judy/Week2/Dark-mode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
54 changes: 54 additions & 0 deletions judy/Week2/Dark-mode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:

```js
export default tseslint.config({
extends: [
// Remove ...tseslint.configs.recommended and replace with this
...tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
...tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:

```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'

export default tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})
```
28 changes: 28 additions & 0 deletions judy/Week2/Dark-mode/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions judy/Week2/Dark-mode/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
32 changes: 32 additions & 0 deletions judy/Week2/Dark-mode/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "dark-mode",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@tailwindcss/vite": "^4.0.16",
"clsx": "^2.1.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tailwindcss": "^4.0.16"
},
"devDependencies": {
"@eslint/js": "^9.21.0",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@vitejs/plugin-react-swc": "^3.8.0",
"eslint": "^9.21.0",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^15.15.0",
"typescript": "~5.7.2",
"typescript-eslint": "^8.24.1",
"vite": "^6.2.0"
}
}
1 change: 1 addition & 0 deletions judy/Week2/Dark-mode/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
12 changes: 12 additions & 0 deletions judy/Week2/Dark-mode/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "./App.css";
import { ContextPage } from "./components/ContextPage";

function App() {
return (
<>
<ContextPage />
</>
);
}

export default App;
1 change: 1 addition & 0 deletions judy/Week2/Dark-mode/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions judy/Week2/Dark-mode/src/components/ContextPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ThemeProvider } from "../context/ThemeProvider";
import { Navbar } from "./Navbar";
import { ThemeContent } from "./ThemeContent";

export const ContextPage = () => {
return (
<>
<ThemeProvider>
<div className="flex flex-col items-center justify-center min-h-screen">
<Navbar />
<main className="flex-1 w-full">
<ThemeContent />
</main>
</div>
</ThemeProvider>
</>
);
};
19 changes: 19 additions & 0 deletions judy/Week2/Dark-mode/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import clsx from "clsx";
import { THEME, useTheme } from "../context/ThemeProvider";
import { ThemeToggleButton } from "./ThemeToggleButton";

export const Navbar = () => {
const { theme } = useTheme();

const isLigthMode = theme === THEME.LIGHT;
return (
<nav
className={clsx(
"p-4 w-full flex justify-end",
isLigthMode ? "bg-white" : "bg-gray-800"
)}
>
<ThemeToggleButton />
</nav>
);
};
25 changes: 25 additions & 0 deletions judy/Week2/Dark-mode/src/components/ThemeContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import clsx from "clsx";
import { THEME, useTheme } from "../context/ThemeProvider";

export const ThemeContent = () => {
const { theme } = useTheme();

const isLightMode = theme === THEME.LIGHT;
return (
<div
className={clsx("p-4 h-dvh", isLightMode ? "bg-whitd" : "bg-gray-800")}
>
<h1
className={clsx(
"text-xl font-bold",
isLightMode ? "text-black" : "text-white"
)}
>
Theme Content
</h1>
<p className={clsx("mt-2", isLightMode ? "text-black" : "text-white")}>
라이트 모드 다크 모드{" "}
</p>
</div>
);
};
19 changes: 19 additions & 0 deletions judy/Week2/Dark-mode/src/components/ThemeToggleButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import clsx from "clsx";
import { THEME, useTheme } from "../context/ThemeProvider";

export const ThemeToggleButton = () => {
const { theme, toggleTheme } = useTheme();

const isLightMode = theme === THEME.LIGHT;
return (
<button
onClick={toggleTheme}
className={clsx("px-4 py-2 mt-4 rounded-md transition-all", {
"bg-black text-white": !isLightMode,
"bg-white text-black": isLightMode,
})}
>
{isLightMode ? "🌝 다크 모드" : "🌞 라이트 모드"}
</button>
);
};
38 changes: 38 additions & 0 deletions judy/Week2/Dark-mode/src/context/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createContext, ReactNode, useContext, useState } from "react";

export enum THEME {
LIGHT = "LIGHT",
DARK = "DARK",
}

type TTheme = THEME.LIGHT | THEME.DARK;

interface IThemeContext {
theme: TTheme;
toggleTheme: () => void;
}

export const ThemeContext = createContext<IThemeContext | undefined>(undefined);

export const ThemeProvider = ({ children }: { children: ReactNode }) => {
const [theme, setTheme] = useState<TTheme>(THEME.LIGHT);
const toggleTheme = () => {
setTheme(
(prevTheme): THEME =>
prevTheme === THEME.LIGHT ? THEME.DARK : THEME.LIGHT
);
};
return (
<ThemeContext.Provider value={{ theme, toggleTheme }}>
{children}
</ThemeContext.Provider>
);
};

export const useTheme = (): IThemeContext => {
const context = useContext(ThemeContext);
if (!context) {
throw new Error("useTheme은 ThemeProvider 안에서 사용되어야 합니다.");
}
return context;
};
1 change: 1 addition & 0 deletions judy/Week2/Dark-mode/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "tailwindcss";
10 changes: 10 additions & 0 deletions judy/Week2/Dark-mode/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
1 change: 1 addition & 0 deletions judy/Week2/Dark-mode/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
26 changes: 26 additions & 0 deletions judy/Week2/Dark-mode/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}
7 changes: 7 additions & 0 deletions judy/Week2/Dark-mode/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}
24 changes: 24 additions & 0 deletions judy/Week2/Dark-mode/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}
5 changes: 5 additions & 0 deletions judy/Week2/Dark-mode/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
plugins: [tailwindcss()],
});
Loading