-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.tsx
109 lines (101 loc) · 3.18 KB
/
popup.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { useEffect } from "react"
import { useStorage } from "@plasmohq/storage/hook"
import "./style.css"
import { BlindnessSettings } from "~components/BlindnessSettings"
import { ColorBlindnessSettings } from "~components/ColorBlindnessSettings"
import { MyopiaSettings } from "~components/MyopiaSettings"
import { applyBlindness } from "~filters/applyBlindness"
import { applyColorBlindness } from "~filters/applyColorBlindness"
import { applyMyopia } from "~filters/applyMyopia"
import { clearFilters } from "~filters/clearFilters"
type Filters = "myopia" | "blindness" | "colorBlindness" | "off"
function IndexPopup() {
const [selectedFilter, setSelectedFilter] = useStorage<string>(
"filter",
"off"
)
const [selectedDiopter, setSelectedDiopter] = useStorage<string>(
"diopter",
"0"
)
const [selectedFontSize, setSelectedFontSize] = useStorage<string>(
"fontSize",
"0"
)
const [selectedBlindMode, setSelectedBlindMode] = useStorage<string>(
"blind",
"blindness"
)
const [selectedColorBlindMode, setSelectedColorBlindMode] =
useStorage<string>("colorBlind", "achromatopsia")
useEffect(() => {
switch (selectedFilter) {
case "myopia": {
applyMyopia(selectedDiopter, selectedFontSize)
break
}
case "blindness": {
applyBlindness(selectedBlindMode)
break
}
case "colorBlindness": {
applyColorBlindness(selectedColorBlindMode)
break
}
case "off": {
clearFilters()
break
}
}
}, [
selectedFilter,
selectedDiopter,
selectedFontSize,
selectedBlindMode,
selectedColorBlindMode
])
return (
<div className="w-80 p-8 flex flex-col gap-8 bg-zinc-100">
<div className="w-full flex flex-col gap-4">
<label
htmlFor="filter-selector"
className="block text-xl font-normal whitespace-nowrap">
Select a visual impairment:
</label>
<select
name="filter-selector"
className="px-4 py-2 text-base font-meduim bg-zinc-100 rounded border border-zinc-300"
value={selectedFilter}
onChange={(e) => {
setSelectedFilter(e.target.value as Filters)
}}>
<option value="off">Off</option>
<option value="myopia">Myopia</option>
<option value="blindness">Blindness</option>
<option value="colorBlindness">Color blindness</option>
</select>
</div>
{selectedFilter === "myopia" && (
<MyopiaSettings
selectedDiopter={selectedDiopter}
setSelectedDiopter={setSelectedDiopter}
selectedFontSize={selectedFontSize}
setSelectedFontSize={setSelectedFontSize}
/>
)}
{selectedFilter === "blindness" && (
<BlindnessSettings
selectedBlindnessOption={selectedBlindMode}
setSelectedBlindnessOption={setSelectedBlindMode}
/>
)}
{selectedFilter === "colorBlindness" && (
<ColorBlindnessSettings
selectedColorBlindnessOption={selectedColorBlindMode}
setSelectedColorBlindnessOption={setSelectedColorBlindMode}
/>
)}
</div>
)
}
export default IndexPopup