Skip to content

Commit d84d43f

Browse files
committed
Switch impl
1 parent b61ea8b commit d84d43f

File tree

4 files changed

+175
-5
lines changed

4 files changed

+175
-5
lines changed

rsa-frontend/src/routes/components/ScenarioArea.js

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,79 @@
11
import React, { useState } from 'react';
2+
import Switch from "./Switch";
23

3-
const users = [
4-
{ id: 1, name: 'Alice' },
5-
{ id: 2, name: 'Bob' },
6-
{ id: 3, name: 'Charlie' },
4+
const initialUsers = [
5+
{ id: 1, name: 'Alice', publicKey: false, privateKey: false, fileUpload: false, readFiles: false, eKey: "...", dKey:"..." },
6+
{ id: 2, name: 'Bob', publicKey: false, privateKey: false, fileUpload: false, readFiles: false,eKey: "...", dKey:"..." },
7+
{ id: 3, name: 'Charlie', publicKey: false, privateKey: false, fileUpload: false, readFiles: false,eKey: "...", dKey:"..." },
78
];
89

10+
const UserContainer = ({ user, handleUserToggle }) => {
11+
const handleToggle = (field) => {
12+
handleUserToggle(user.id, field);
13+
};
14+
15+
return (
16+
<div className={"user-container"}>
17+
<p className={"font-bold"} style={{ color: "var(--orange-color-1)" }}>{user.name}</p>
18+
19+
<div className={"custom-row"} style={{gap:0}}>
20+
<Switch
21+
isOn={user.publicKey}
22+
handleToggle={() => handleToggle('publicKey')}
23+
id={user.id+"publicKey"}
24+
/>
25+
<div>
26+
<p>Açık Anahtar</p>
27+
<p className={"small-text"}>{user.publicKey ? user.eKey : "Kapalı"}</p>
28+
<p></p>
29+
</div>
30+
</div>
31+
32+
<div className={"custom-row"} style={{gap:0}}>
33+
<Switch
34+
isOn={user.privateKey}
35+
handleToggle={() => handleToggle('privateKey')}
36+
id={user.id+"privateKey"}
37+
/>
38+
<div>
39+
<p>Kapalı Anahtar</p>
40+
<p className={"small-text"}>{user.privateKey ? user.dKey : "Kapalı"}</p>
41+
<p></p>
42+
</div>
43+
</div>
44+
45+
<div className={"custom-row"} style={{gap:36}}>
46+
<div className={"custom-row"} style={{gap:0}}>
47+
<Switch
48+
isOn={user.fileUpload}
49+
handleToggle={() => handleToggle('fileUpload')}
50+
id={user.id+"fileUpload"}
51+
/>
52+
<div>
53+
<p>Dosya Yükleme</p>
54+
<p className={"small-text"}>{user.fileUpload ? user.fileUpload : "Kapalı"}</p>
55+
<p></p>
56+
</div>
57+
</div>
58+
<div className={"custom-row"} style={{gap:0}}>
59+
<Switch
60+
isOn={user.readFiles}
61+
handleToggle={() => handleToggle('readFiles')}
62+
id={user.id+"readFiles"}
63+
/>
64+
<div>
65+
<p>Dosya Okuma</p>
66+
<p className={"small-text"}>{user.readFiles ? user.readFiles : "Kapalı"}</p>
67+
<p></p>
68+
</div>
69+
</div>
70+
</div>
71+
</div>
72+
);
73+
};
74+
975
const ScenarioArea = () => {
76+
const [users, setUsers] = useState(initialUsers);
1077
const [activeUsers, setActiveUsers] = useState([]);
1178

1279
const handleUserClick = (userId) => {
@@ -17,11 +84,19 @@ const ScenarioArea = () => {
1784
}
1885
};
1986

87+
const handleUserToggle = (userId, field) => {
88+
setUsers(users.map(user =>
89+
user.id === userId
90+
? { ...user, [field]: !user[field] }
91+
: user
92+
));
93+
};
94+
2095
return (
2196
<div className="scenario-area">
2297
<p className={"title-text"}><span>Senaryo</span> Alanı</p>
2398
<div className="custom-row">
24-
<p className={"italic"} style={{marginRight:12}}>Kullanıcı<br/>Seçim</p>
99+
<p className={"italic"} style={{ marginRight: 12 }}>Kullanıcı<br />Seçim</p>
25100
{users.map((user) => (
26101
<div
27102
key={user.id}
@@ -36,6 +111,21 @@ const ScenarioArea = () => {
36111
</div>
37112
))}
38113
</div>
114+
{
115+
activeUsers
116+
.sort((a, b) => a - b)
117+
.map((id) => {
118+
const user = users.find(user => user.id === id);
119+
return (
120+
<div key={id}>
121+
<UserContainer
122+
user={user}
123+
handleUserToggle={handleUserToggle}
124+
/>
125+
</div>
126+
);
127+
})
128+
}
39129
</div>
40130
);
41131
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import '../css/switch.css';
3+
4+
const Switch = ({ isOn, handleToggle ,id}) => {
5+
return (
6+
<>
7+
<input
8+
checked={isOn}
9+
onChange={handleToggle}
10+
className="react-switch-checkbox"
11+
id={id}
12+
type="checkbox"
13+
/>
14+
<label
15+
className="react-switch-label"
16+
htmlFor={id}
17+
style={{borderColor :isOn ? 'var(--green-color-1)' : 'rgb(184,184,184)'}}
18+
>
19+
<span className={`react-switch-button`} style={{
20+
background: isOn ? 'var(--green-color-1)' : 'rgb(184,184,184)',
21+
}} />
22+
</label>
23+
</>
24+
);
25+
};
26+
27+
export default Switch;

rsa-frontend/src/routes/css/index.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,18 @@ span{
242242
.file-container p{
243243
color: var(--black-color-1);
244244
}
245+
246+
247+
.user-container{
248+
padding: 8px;
249+
border-radius: 8px;
250+
background-color: var(--secondary-color-1);
251+
display: flex;
252+
flex-direction: column;
253+
gap: 12px;
254+
}
255+
256+
.file-container p{
257+
color: var(--black-color-1);
258+
}
259+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.react-switch-checkbox {
2+
height: 0;
3+
width: 0;
4+
visibility: hidden;
5+
}
6+
7+
.react-switch-label {
8+
display: flex;
9+
align-items: center;
10+
cursor: pointer;
11+
width: 36px;
12+
height: 17px;
13+
margin-right: 8px;
14+
background: var(--primary-color-1);
15+
border-radius: 100px;
16+
position: relative;
17+
border: 1px solid rgba(184,184,184);
18+
transition: background-color .2s;
19+
}
20+
21+
.react-switch-label .react-switch-button {
22+
position: absolute;
23+
left: 4px;
24+
width: 12px;
25+
height: 12px;
26+
border-radius: 30px;
27+
transition: 0.4s;
28+
background: rgba(184,184,184);
29+
}
30+
31+
.react-switch-checkbox:checked + .react-switch-label .react-switch-button {
32+
left: calc(100% - 4px);
33+
transform: translateX(-100%);
34+
}
35+
36+
.react-switch-label:active .react-switch-button {
37+
width: 20px;
38+
}

0 commit comments

Comments
 (0)