Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1ac8dd5

Browse files
practice set added
1 parent c52b85f commit 1ac8dd5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3591
-0
lines changed

‎practice/online-status/.gitignore

Lines changed: 24 additions & 0 deletions
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?

‎practice/online-status/index.html

Lines changed: 13 additions & 0 deletions
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</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.jsx"></script>
12+
</body>
13+
</html>

‎practice/online-status/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "online-status",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "vite build",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
"react": "^18.2.0",
13+
"react-dom": "^18.2.0"
14+
},
15+
"devDependencies": {
16+
"@types/react": "^18.0.26",
17+
"@types/react-dom": "^18.0.9",
18+
"@vitejs/plugin-react": "^3.0.0",
19+
"vite": "^4.0.0"
20+
}
21+
}

‎practice/online-status/public/vite.svg

Lines changed: 1 addition & 0 deletions
Loading[フレーム]

‎practice/online-status/src/App.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.App{
2+
width: auto;
3+
height: auto;
4+
display: flex;
5+
flex-wrap: wrap;
6+
}
7+
.online{
8+
width: 60px;
9+
height: 60px;
10+
background-color: gray;
11+
cursor: pointer;
12+
margin: 6px;
13+
border-radius: 6px;
14+
}

‎practice/online-status/src/App.jsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from "react";
2+
import "./App.css"
3+
import data from "./data.json"
4+
import Online from "./Online";
5+
6+
export default function App() {
7+
8+
const [user, setUser] = React.useState(data)
9+
function toggle(id) {
10+
setUser((prevuser) => {
11+
return(
12+
prevuser.map((userdata) => {
13+
return userdata.id === id ? {...userdata, status: !userdata.status} : userdata
14+
15+
})
16+
)
17+
})
18+
}
19+
20+
const onlinedataitem = user.map((onlinedata) => {
21+
return(
22+
<Online
23+
id={onlinedata.id}
24+
status={onlinedata.status}
25+
key={onlinedata.id}
26+
toggle={toggle(onlinedata.id)}
27+
/>
28+
)
29+
})
30+
return(
31+
<div className="App">
32+
{onlinedataitem}
33+
</div>
34+
)
35+
}

‎practice/online-status/src/Online.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from "react";
2+
3+
export default function Online(props) {
4+
5+
const bgcolor = {
6+
backgroundColor: props.status ? "orange" : "gray"
7+
}
8+
return(
9+
<div className="online" style={bgcolor} onClick={() => props.toggle}>
10+
</div>
11+
)
12+
}

‎practice/online-status/src/data.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
{
3+
"id": 11,
4+
"status": true
5+
},
6+
{
7+
"id": 22,
8+
"status": false
9+
},
10+
{
11+
"id": 33,
12+
"status": false
13+
},
14+
{
15+
"id": 44,
16+
"status": true
17+
},
18+
{
19+
"id": 55,
20+
"status": true
21+
},
22+
{
23+
"id": 66,
24+
"status": false
25+
},
26+
{
27+
"id": 77,
28+
"status": false
29+
},
30+
{
31+
"id": 88,
32+
"status": true
33+
}
34+
]

‎practice/online-status/src/index.css

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

‎practice/online-status/src/main.jsx

Lines changed: 10 additions & 0 deletions
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'
4+
import './index.css'
5+
6+
ReactDOM.createRoot(document.getElementById('root')).render(
7+
<React.StrictMode>
8+
<App />
9+
</React.StrictMode>,
10+
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /