Skip to content

Commit 047d572

Browse files
committed
first commit
0 parents  commit 047d572

19 files changed

+3413
-0
lines changed

.eslintrc.cjs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
node: true
5+
},
6+
extends: [
7+
'eslint:recommended',
8+
'plugin:react/recommended',
9+
'plugin:react-hooks/recommended',
10+
'plugin:import/recommended',
11+
'plugin:jsx-a11y/recommended',
12+
'plugin:@typescript-eslint/recommended',
13+
'eslint-config-prettier',
14+
'plugin:storybook/recommended'
15+
],
16+
settings: {
17+
react: {
18+
// Tells eslint-plugin-react to automatically detect the version of React to use.
19+
version: 'detect'
20+
},
21+
// Tells eslint how to resolve imports
22+
'import/resolver': {
23+
node: {
24+
paths: ['src'],
25+
extensions: ['.js', '.jsx', '.ts', '.tsx', 'json']
26+
},
27+
alias: {
28+
map: [['@', './src']],
29+
extensions: ['.js', '.jsx', '.ts', '.tsx', 'json']
30+
}
31+
}
32+
},
33+
plugins: ['@typescript-eslint', 'simple-import-sort', 'react', 'prettier'],
34+
rules: {
35+
'prettier/prettier': 'error',
36+
'@typescript-eslint/camelcase': 'off',
37+
'react/react-in-jsx-scope': 'off',
38+
'@typescript-eslint/no-empty-interface': 'off',
39+
// simple import sort
40+
'sort-imports': 'off',
41+
'import/order': 'off',
42+
'simple-import-sort/imports': 'error',
43+
'simple-import-sort/exports': 'error'
44+
}
45+
}

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

.prettierrc.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
tabWidth: 2,
3+
singleQuote: true,
4+
semi: false,
5+
endOfLine: 'lf'
6+
}

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Installation & Scripts
2+
```
3+
npm install
4+
yarn
5+
```
6+
```
7+
npm run test <檔案路徑>
8+
```
9+
### Testing
10+
11+
`filename.test.js`
12+
13+
14+
### Files
15+
16+
17+
#### <>.js
18+
19+
####

index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

package.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "libs",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"test": "jest",
8+
"dev": "vite",
9+
"build": "tsc && vite build",
10+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
11+
"preview": "vite preview"
12+
},
13+
"dependencies": {
14+
"react": "^18.2.0",
15+
"react-dom": "^18.2.0"
16+
},
17+
"devDependencies": {
18+
"@types/react": "^18.2.15",
19+
"@types/react-dom": "^18.2.7",
20+
"@typescript-eslint/eslint-plugin": "^6.0.0",
21+
"@typescript-eslint/parser": "^6.0.0",
22+
"@vitejs/plugin-react": "^4.0.3",
23+
"eslint": "^8.45.0",
24+
"eslint-plugin-react-hooks": "^4.6.0",
25+
"eslint-plugin-react-refresh": "^0.4.3",
26+
"jest": "^29.7.0",
27+
"typescript": "^5.0.2",
28+
"vite": "^4.4.5"
29+
}
30+
}

public/vite.svg

+1
Loading

src/App.css

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
transition: filter 300ms;
13+
}
14+
.logo:hover {
15+
filter: drop-shadow(0 0 2em #646cffaa);
16+
}
17+
.logo.react:hover {
18+
filter: drop-shadow(0 0 2em #61dafbaa);
19+
}
20+
21+
@keyframes logo-spin {
22+
from {
23+
transform: rotate(0deg);
24+
}
25+
to {
26+
transform: rotate(360deg);
27+
}
28+
}
29+
30+
@media (prefers-reduced-motion: no-preference) {
31+
a:nth-of-type(2) .logo {
32+
animation: logo-spin infinite 20s linear;
33+
}
34+
}
35+
36+
.card {
37+
padding: 2em;
38+
}
39+
40+
.read-the-docs {
41+
color: #888;
42+
}

src/App.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useState } from 'react'
2+
import reactLogo from './assets/react.svg'
3+
import viteLogo from '/vite.svg'
4+
import './App.css'
5+
6+
function App() {
7+
const [count, setCount] = useState(0)
8+
9+
return (
10+
<>
11+
<div>
12+
<a href="https://vitejs.dev" target="_blank">
13+
<img src={viteLogo} className="logo" alt="Vite logo" />
14+
</a>
15+
<a href="https://react.dev" target="_blank">
16+
<img src={reactLogo} className="logo react" alt="React logo" />
17+
</a>
18+
</div>
19+
<h1>Vite + React</h1>
20+
<div className="card">
21+
<button onClick={() => setCount((count) => count + 1)}>
22+
count is {count}
23+
</button>
24+
<p>
25+
Edit <code>src/App.tsx</code> and save to test HMR
26+
</p>
27+
</div>
28+
<p className="read-the-docs">
29+
Click on the Vite and React logos to learn more
30+
</p>
31+
</>
32+
)
33+
}
34+
35+
export default App

src/assets/react.svg

+1
Loading

src/index.css

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
:root {
2+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3+
line-height: 1.5;
4+
font-weight: 400;
5+
6+
color-scheme: light dark;
7+
color: rgba(255, 255, 255, 0.87);
8+
background-color: #242424;
9+
10+
font-synthesis: none;
11+
text-rendering: optimizeLegibility;
12+
-webkit-font-smoothing: antialiased;
13+
-moz-osx-font-smoothing: grayscale;
14+
-webkit-text-size-adjust: 100%;
15+
}
16+
17+
a {
18+
font-weight: 500;
19+
color: #646cff;
20+
text-decoration: inherit;
21+
}
22+
a:hover {
23+
color: #535bf2;
24+
}
25+
26+
body {
27+
margin: 0;
28+
display: flex;
29+
place-items: center;
30+
min-width: 320px;
31+
min-height: 100vh;
32+
}
33+
34+
h1 {
35+
font-size: 3.2em;
36+
line-height: 1.1;
37+
}
38+
39+
button {
40+
border-radius: 8px;
41+
border: 1px solid transparent;
42+
padding: 0.6em 1.2em;
43+
font-size: 1em;
44+
font-weight: 500;
45+
font-family: inherit;
46+
background-color: #1a1a1a;
47+
cursor: pointer;
48+
transition: border-color 0.25s;
49+
}
50+
button:hover {
51+
border-color: #646cff;
52+
}
53+
button:focus,
54+
button:focus-visible {
55+
outline: 4px auto -webkit-focus-ring-color;
56+
}
57+
58+
@media (prefers-color-scheme: light) {
59+
:root {
60+
color: #213547;
61+
background-color: #ffffff;
62+
}
63+
a:hover {
64+
color: #747bff;
65+
}
66+
button {
67+
background-color: #f9f9f9;
68+
}
69+
}

src/main.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom/client'
3+
import App from './App.tsx'
4+
import './index.css'
5+
6+
ReactDOM.createRoot(document.getElementById('root')!).render(
7+
<React.StrictMode>
8+
<App />
9+
</React.StrictMode>,
10+
)

src/test/validation.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { isFieldEmpty, isValidEmail } = require('../utils/validation.js')
2+
3+
describe('Form Validation', () => {
4+
test('檢查是否正確地檢測空值', () => {
5+
expect(isFieldEmpty('')).toBe(true)
6+
expect(isFieldEmpty('Hello')).toBe(false)
7+
})
8+
9+
test('檢查是否正確地檢測有效的電子郵件', () => {
10+
expect(isValidEmail('[email protected]')).toBe(true)
11+
expect(isValidEmail('invalid_email')).toBe(false)
12+
})
13+
})

src/utils/validation.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* 檢查表單輸入是否為空
3+
* @param {string} value - 要檢查的值
4+
* @returns {boolean} 如果輸入為空則返回 true,否則返回 false
5+
*/
6+
const isFieldEmpty = (value) => {
7+
return value.trim() === ''
8+
}
9+
10+
// Test isFieldEmpty
11+
// const inputValue1 = '' // 空字串
12+
// const inputValue2 = 'Hello' // 非空字串
13+
14+
// isFieldEmpty(inputValue1) // 輸出: true
15+
// isFieldEmpty(inputValue2) // 輸出: false
16+
17+
// -----------------------------------------------------------------
18+
19+
/**
20+
* 檢查是否為有效的電子郵件格式
21+
* @param {string} email - 要檢查的電子郵件
22+
* @returns {boolean} 如果是有效的電子郵件則返回 true,否則返回 false
23+
*/
24+
const isValidEmail = (email) => {
25+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
26+
return emailRegex.test(email)
27+
}
28+
29+
// Test isValidEmail
30+
// const validEmail = '[email protected]' // 有效的電子郵件
31+
// const invalidEmail = 'invalid_email' // 無效的電子郵件
32+
33+
// isValidEmail(validEmail) // 輸出: true
34+
// isValidEmail(invalidEmail) // 輸出: false
35+
36+
// -----------------------------------------------------------------
37+
38+
module.exports = { isValidEmail, isFieldEmpty }

src/vite-env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

tsconfig.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"useDefineForClassFields": true,
5+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6+
"module": "ESNext",
7+
"skipLibCheck": true,
8+
9+
/* Bundler mode */
10+
"moduleResolution": "bundler",
11+
"allowImportingTsExtensions": true,
12+
"resolveJsonModule": true,
13+
"isolatedModules": true,
14+
"noEmit": true,
15+
"jsx": "react-jsx",
16+
17+
/* Linting */
18+
"strict": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"noFallthroughCasesInSwitch": true
22+
},
23+
"include": ["src"],
24+
"references": [{ "path": "./tsconfig.node.json" }]
25+
}

0 commit comments

Comments
 (0)