Skip to content

Commit 20b47a9

Browse files
committed
Using toggle switches instead of checkboxes
1 parent 0194c38 commit 20b47a9

File tree

3 files changed

+118
-75
lines changed

3 files changed

+118
-75
lines changed

src/components/__tests__/__snapshots__/skills.test.js.snap

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,31 @@ exports[`Skills renders correctly 1`] = `
4646
className="flex justify-start items-center flex-wrap w-full mb-6 pl-4 sm:pl-10"
4747
>
4848
<div
49-
className="w-1/3 sm:w-1/4 my-6"
49+
className="skillCheckbox w-1/3 sm:w-1/4 my-6 flex items-center"
5050
key="javascript"
5151
>
52+
<input
53+
checked={true}
54+
className="offscreen"
55+
id="javascript"
56+
onChange={[Function]}
57+
type="checkbox"
58+
/>
5259
<label
53-
className="skillCheckboxLabel cursor-pointer flex items-center justify-start"
60+
className="switch cursor-pointer"
5461
htmlFor="javascript"
62+
/>
63+
<img
64+
alt="javascript"
65+
className="ml-4 w-8 h-8 sm:w-10 sm:h-10 cursor-pointer"
66+
onClick={[Function]}
67+
src="javascript.svg"
68+
/>
69+
<span
70+
className="tooltiptext"
5571
>
56-
<input
57-
checked={true}
58-
id="javascript"
59-
onChange={[Function]}
60-
type="checkbox"
61-
/>
62-
<img
63-
alt="javascript"
64-
className="ml-4 w-8 h-8 sm:w-10 sm:h-10"
65-
src="javascript.svg"
66-
/>
67-
<span
68-
className="tooltiptext"
69-
>
70-
javascript
71-
</span>
72-
</label>
72+
javascript
73+
</span>
7374
</div>
7475
</div>
7576
</div>
@@ -86,54 +87,56 @@ exports[`Skills renders correctly 1`] = `
8687
className="flex justify-start items-center flex-wrap w-full mb-6 pl-4 sm:pl-10"
8788
>
8889
<div
89-
className="w-1/3 sm:w-1/4 my-6"
90+
className="skillCheckbox w-1/3 sm:w-1/4 my-6 flex items-center"
9091
key="react"
9192
>
93+
<input
94+
className="offscreen"
95+
id="react"
96+
onChange={[Function]}
97+
type="checkbox"
98+
/>
9299
<label
93-
className="skillCheckboxLabel cursor-pointer flex items-center justify-start"
100+
className="switch cursor-pointer"
94101
htmlFor="react"
102+
/>
103+
<img
104+
alt="react"
105+
className="ml-4 w-8 h-8 sm:w-10 sm:h-10 cursor-pointer"
106+
onClick={[Function]}
107+
src="react.svg"
108+
/>
109+
<span
110+
className="tooltiptext"
95111
>
96-
<input
97-
id="react"
98-
onChange={[Function]}
99-
type="checkbox"
100-
/>
101-
<img
102-
alt="react"
103-
className="ml-4 w-8 h-8 sm:w-10 sm:h-10"
104-
src="react.svg"
105-
/>
106-
<span
107-
className="tooltiptext"
108-
>
109-
react
110-
</span>
111-
</label>
112+
react
113+
</span>
112114
</div>
113115
<div
114-
className="w-1/3 sm:w-1/4 my-6"
116+
className="skillCheckbox w-1/3 sm:w-1/4 my-6 flex items-center"
115117
key="svelte"
116118
>
119+
<input
120+
className="offscreen"
121+
id="svelte"
122+
onChange={[Function]}
123+
type="checkbox"
124+
/>
117125
<label
118-
className="skillCheckboxLabel cursor-pointer flex items-center justify-start"
126+
className="switch cursor-pointer"
119127
htmlFor="svelte"
128+
/>
129+
<img
130+
alt="svelte"
131+
className="ml-4 w-8 h-8 sm:w-10 sm:h-10 cursor-pointer"
132+
onClick={[Function]}
133+
src="svelte.svg"
134+
/>
135+
<span
136+
className="tooltiptext"
120137
>
121-
<input
122-
id="svelte"
123-
onChange={[Function]}
124-
type="checkbox"
125-
/>
126-
<img
127-
alt="svelte"
128-
className="ml-4 w-8 h-8 sm:w-10 sm:h-10"
129-
src="svelte.svg"
130-
/>
131-
<span
132-
className="tooltiptext"
133-
>
134-
svelte
135-
</span>
136-
</label>
138+
svelte
139+
</span>
137140
</div>
138141
</div>
139142
</div>

src/components/skills.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ const Skills = props => {
99
const inputRef = React.createRef()
1010
const createSkill = skill => {
1111
return (
12-
<div className="w-1/3 sm:w-1/4 my-6" key={skill}>
13-
<label
14-
htmlFor={skill}
15-
className="skillCheckboxLabel cursor-pointer flex items-center justify-start"
16-
>
17-
<input
18-
id={skill}
19-
type="checkbox"
20-
checked={props.skills[skill]}
21-
onChange={event => props.handleSkillsChange(skill)}
22-
/>
23-
<img
24-
className="ml-4 w-8 h-8 sm:w-10 sm:h-10"
25-
src={icons[skill]}
26-
alt={skill}
27-
/>
28-
<span className="tooltiptext">{skill}</span>
29-
</label>
30-
</div>
12+
<div
13+
className="skillCheckbox w-1/3 sm:w-1/4 my-6 flex items-center"
14+
key={skill}>
15+
<input
16+
type="checkbox"
17+
id={skill}
18+
className="offscreen"
19+
checked={props.skills[skill]}
20+
onChange={event => props.handleSkillsChange(skill)}
21+
/>
22+
<label htmlFor={skill} className="switch cursor-pointer" />
23+
<img
24+
className="ml-4 w-8 h-8 sm:w-10 sm:h-10 cursor-pointer"
25+
onClick={event => props.handleSkillsChange(skill)}
26+
src={icons[skill]}
27+
alt={skill}
28+
/>
29+
<span className="tooltiptext">{skill}</span>
30+
</div>
3131
)
3232
}
3333

src/pages/index.css

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,50 @@ a {
8080
font-size: 14px;
8181
}
8282

83-
.skillCheckboxLabel:hover .tooltiptext {
83+
.skillCheckbox:hover .tooltiptext {
8484
visibility: visible;
8585
}
8686

87+
.switch {
88+
position: relative;
89+
display: inline-block;
90+
width: 40px;
91+
height: 20px;
92+
background-color: rgba(0, 0, 0, 0.25);
93+
border-radius: 20px;
94+
transition: all 0.25s;
95+
}
96+
.switch::after {
97+
content: '';
98+
position: absolute;
99+
width: 16px;
100+
height: 16px;
101+
border-radius: 16px;
102+
background-color: #fff;
103+
top: 2px;
104+
left: 2px;
105+
transition: all 0.25s;
106+
}
107+
108+
input[type='checkbox']:checked+.switch::after {
109+
transform: translateX(20px);
110+
}
111+
input[type='checkbox']:checked+.switch {
112+
background-color: var(--light-green);
113+
}
114+
input[type='checkbox']:focus+.switch {
115+
background-color: var(--blue);
116+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
117+
}
118+
input[type='checkbox']:checked:focus+.switch {
119+
background-color: var(--light-green);
120+
}
121+
122+
.offscreen {
123+
position: absolute;
124+
left: -9999px;
125+
}
126+
87127
.tooltiptext::after {
88128
content: " ";
89129
position: absolute;

0 commit comments

Comments
 (0)