Skip to content

Commit 4cd0a93

Browse files
authored
添加 react 示例 (#508)
* 添加 react 示例 * 添加 start script * 优化样式 * 优化错误提示 * 细节优化 * append * 添加 footer * append * 细节调整 * 使用 esbuild-loading compiled time's 5.53s * 挪动 loadSetting 到 utils * 变量重命名 * update package.json * 根据 review 的意见进行调整
1 parent c6fea03 commit 4cd0a93

34 files changed

+6676
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
webpack.config.js
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"@qiniu"
4+
]
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
**/node_modules
3+
dist
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "react-typescript",
3+
"description": "React Typescript",
4+
"version": "1.0.0",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev": "webpack serve --mode development --inline --hot --open",
8+
"start": "webpack serve --mode development",
9+
"build": "webpack --mode production",
10+
"lint": "eslint --ext .tsx,.ts src/"
11+
},
12+
"license": "MIT",
13+
"devDependencies": {
14+
"@qiniu/eslint-config": "0.0.6-beta.7",
15+
"@types/react": "^17.0.5",
16+
"@types/react-dom": "^17.0.5",
17+
"@typescript-eslint/eslint-plugin": "~4.10.0",
18+
"css-loader": "^5.2.4",
19+
"esbuild-loader": "^2.13.1",
20+
"eslint": "~7.2.0",
21+
"eslint-import-resolver-typescript": "~2.3.0",
22+
"eslint-plugin-import": "~2.22.1",
23+
"eslint-plugin-jsx-a11y": "~6.3.0",
24+
"eslint-plugin-react": "~7.20.0",
25+
"eslint-plugin-react-hooks": "~4.2.0",
26+
"eslint-webpack-plugin": "^2.5.4",
27+
"file-loader": "^6.2.0",
28+
"html-webpack-plugin": "^5.3.1",
29+
"less": "^4.1.1",
30+
"less-loader": "^9.0.0",
31+
"qiniu": "^7.3.2",
32+
"style-loader": "^2.0.0",
33+
"typescript": "4.1.5",
34+
"url-loader": "^4.1.1",
35+
"webpack": "^5.37.0",
36+
"webpack-cli": "^4.7.0",
37+
"webpack-dev-server": "^3.11.2",
38+
"webpackbar": "^5.0.0-3"
39+
},
40+
"dependencies": {
41+
"byte-size": "^7.0.1",
42+
"qiniu-js": "^3.4.0",
43+
"react": "^17.0.2",
44+
"react-dom": "^17.0.2"
45+
}
46+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as React from 'react'
2+
3+
import { Queue } from '../Queue'
4+
import { Layout } from '../Layout'
5+
import { Settings } from '../Settings'
6+
import { SelectFile, UniqueFile } from '../SelectFile'
7+
8+
import settingIcon from '../Settings/assets/setting.svg'
9+
import classnames from './style.less'
10+
11+
export const App = () => {
12+
const [fileList, setFileList] = React.useState<UniqueFile[]>([])
13+
const [settingVisible, setSettingVisible] = React.useState(false)
14+
15+
const selectFile = (file: UniqueFile) => {
16+
setFileList(files => [file, ...files])
17+
}
18+
19+
const toggleSettingVisible = () => {
20+
setSettingVisible(!settingVisible)
21+
}
22+
23+
const settingsClassName = React.useMemo(() => {
24+
const list = [classnames.setting]
25+
if (settingVisible) {
26+
list.push(classnames.show)
27+
} else {
28+
list.push(classnames.hidden)
29+
}
30+
return list.join(' ')
31+
}, [settingVisible])
32+
33+
return (
34+
<Layout>
35+
<div className={classnames.content}>
36+
<SelectFile onFile={selectFile} />
37+
<div className={settingsClassName}>
38+
<Settings />
39+
</div>
40+
<img
41+
src={settingIcon}
42+
className={classnames.settingIcon}
43+
onClick={toggleSettingVisible}
44+
/>
45+
</div>
46+
<Queue fileList={fileList} />
47+
</Layout>
48+
)
49+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
.content {
3+
display: flex;
4+
flex-direction: row;
5+
align-items: center;
6+
7+
.setting {
8+
z-index: 0;
9+
position: relative;
10+
margin-left: -300px;
11+
12+
@width: 400px;
13+
14+
&.show {
15+
animation: show 1s;
16+
animation-fill-mode: forwards;
17+
}
18+
19+
&.hidden {
20+
animation: hidden 1s;
21+
animation-fill-mode: forwards;
22+
}
23+
24+
@keyframes show {
25+
from { margin-left: -@width;opacity: 0; }
26+
to { margin-left: -10px ;opacity: 1; }
27+
}
28+
29+
@keyframes hidden {
30+
from { margin-left: -10px; opacity: 1; }
31+
to { margin-left: -@width; opacity: 0; }
32+
}
33+
}
34+
}
35+
36+
37+
.settingIcon {
38+
width: 20px;
39+
height: 20px;
40+
margin-left: 2rem;
41+
padding: 1rem;
42+
border-radius: 1rem;
43+
background-color: rgba(0, 0, 0, .02);
44+
cursor: pointer;
45+
transition: .3s;
46+
47+
&:hover {
48+
background-color: rgba(0, 0, 0, .1);
49+
}
50+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as React from 'react'
2+
3+
import classnames from './style.less'
4+
5+
interface IProps {
6+
value: string | undefined
7+
onChange(v: string | undefined): void
8+
9+
placeholder?: string | undefined
10+
}
11+
12+
export function Input(props: IProps) {
13+
return (
14+
<input
15+
type="text"
16+
value={props.value}
17+
className={classnames.input}
18+
placeholder={props.placeholder}
19+
onChange={e => props.onChange(e.target.value)} />
20+
)
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.input {
2+
padding: 0.4rem 0.6rem;
3+
4+
font-size: 14px;
5+
font-weight: 500;
6+
7+
border-radius: 4px;
8+
border: 2px solid transparent;
9+
box-shadow: 0px 0px 20px 10px rgba(0, 0, 0, .07) inset;
10+
11+
&:focus {
12+
outline: none;
13+
border: 2px solid royalblue;
14+
}
15+
16+
&::placeholder {
17+
color: rgba(0, 0, 0, 0.15);
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Loading
Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)