-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorContrastCheckerPage.jsx
More file actions
273 lines (254 loc) · 10.8 KB
/
ColorContrastCheckerPage.jsx
File metadata and controls
273 lines (254 loc) · 10.8 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import React, { useState, useCallback, useEffect } from 'react';
import { Link } from 'react-router-dom';
import {
ArrowLeftIcon,
CheckCircleIcon,
XCircleIcon,
PaletteIcon,
} from '@phosphor-icons/react';
import Seo from '../../components/Seo';
import GenerativeArt from '../../components/GenerativeArt';
import BreadcrumbTitle from '../../components/BreadcrumbTitle';
const hexToRgb = (hex) => {
const r = parseInt(hex.substring(1, 3), 16);
const g = parseInt(hex.substring(3, 5), 16);
const b = parseInt(hex.substring(5, 7), 16);
return [r, g, b];
};
const getLuminance = (r, g, b) => {
const a = [r, g, b].map((v) => {
v /= 255;
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
});
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
};
const getContrastRatio = (rgb1, rgb2) => {
const lum1 = getLuminance(rgb1[0], rgb1[1], rgb1[2]);
const lum2 = getLuminance(rgb2[0], rgb2[1], rgb2[2]);
const brightest = Math.max(lum1, lum2);
const darkest = Math.min(lum1, lum2);
return (brightest + 0.05) / (darkest + 0.05);
};
const ColorContrastCheckerPage = () => {
const [foregroundColor, setForegroundColor] = useState('#FFFFFF');
const [backgroundColor, setBackgroundColor] = useState('#050505');
const [contrastRatio, setContrastRatio] = useState(0);
const [wcagStatus, setWcagStatus] = useState({ aa: false, aaa: false });
const calculateContrast = useCallback(() => {
try {
const fgRgb = hexToRgb(foregroundColor);
const bgRgb = hexToRgb(backgroundColor);
const ratio = getContrastRatio(fgRgb, bgRgb);
setContrastRatio(ratio.toFixed(2));
setWcagStatus({
aa: ratio >= 4.5,
aaa: ratio >= 7,
});
} catch (error) {
setContrastRatio(0);
setWcagStatus({ aa: false, aaa: false });
}
}, [foregroundColor, backgroundColor]);
useEffect(() => {
calculateContrast();
}, [calculateContrast]);
return (
<div className="min-h-screen bg-[#050505] text-white selection:bg-emerald-500/30 font-sans">
<Seo
title="Contrast Checker | Fezcodex"
description="Verify color accessibility and WCAG compliance for digital interfaces."
keywords={[
'Fezcodex',
'color contrast',
'accessibility',
'WCAG',
'color checker',
]}
/>
<div className="mx-auto max-w-7xl px-6 py-24 md:px-12">
<header className="mb-24">
<Link
to="/apps"
className="group mb-12 inline-flex items-center gap-2 text-xs font-mono text-gray-500 hover:text-white transition-colors uppercase tracking-[0.3em]"
>
<ArrowLeftIcon
weight="bold"
className="transition-transform group-hover:-translate-x-1"
/>
<span>Applications</span>
</Link>
<div className="flex flex-col md:flex-row md:items-end justify-between gap-12">
<div className="space-y-4">
<BreadcrumbTitle
title="Contrast Checker"
slug="ccc"
variant="brutalist"
/>
<p className="text-xl text-gray-400 max-w-2xl font-light leading-relaxed">
Accessibility verification protocol. Map chromatic ratios to
ensure visual clarity and adherence to universal standards.
</p>
</div>
</div>
</header>
<div className="grid grid-cols-1 lg:grid-cols-12 gap-12">
{/* Controls Column */}
<div className="lg:col-span-4 space-y-8">
<div className="border border-white/10 bg-white/[0.02] p-8 rounded-sm space-y-10">
<h3 className="font-mono text-[10px] font-bold text-emerald-500 uppercase tracking-widest flex items-center gap-2">
<PaletteIcon weight="fill" />
Aesthetic_Input
</h3>
<div className="space-y-8">
<div className="space-y-4">
<label className="block font-mono text-[10px] text-gray-500 uppercase tracking-widest">
Foreground_Hex
</label>
<div className="flex gap-2">
<input
type="color"
value={foregroundColor}
onChange={(e) =>
setForegroundColor(e.target.value.toUpperCase())
}
className="w-12 h-12 rounded-sm cursor-pointer bg-transparent border border-white/10 p-1"
/>
<input
type="text"
value={foregroundColor}
onChange={(e) =>
setForegroundColor(e.target.value.toUpperCase())
}
className="flex-1 bg-white/5 border border-white/10 rounded-sm px-4 font-mono text-sm uppercase focus:border-emerald-500/50 focus:ring-0 transition-all"
/>
</div>
</div>
<div className="space-y-4">
<label className="block font-mono text-[10px] text-gray-500 uppercase tracking-widest">
Background_Hex
</label>
<div className="flex gap-2">
<input
type="color"
value={backgroundColor}
onChange={(e) =>
setBackgroundColor(e.target.value.toUpperCase())
}
className="w-12 h-12 rounded-sm cursor-pointer bg-transparent border border-white/10 p-1"
/>
<input
type="text"
value={backgroundColor}
onChange={(e) =>
setBackgroundColor(e.target.value.toUpperCase())
}
className="flex-1 bg-white/5 border border-white/10 rounded-sm px-4 font-mono text-sm uppercase focus:border-emerald-500/50 focus:ring-0 transition-all"
/>
</div>
</div>
</div>
</div>
<div className="p-8 border border-white/10 bg-white/[0.01] rounded-sm">
<p className="text-[10px] font-mono uppercase tracking-[0.2em] leading-relaxed text-gray-500">
Contrast ratios define the readability of digital assets. Higher
ratios improve processing efficiency for human operators.
</p>
</div>
</div>
{/* Preview & Results Column */}
<div className="lg:col-span-8 space-y-8">
{/* Immersive Preview */}
<div
className="relative aspect-video rounded-sm overflow-hidden flex flex-col items-center justify-center p-12 transition-colors duration-500 border border-white/10"
style={{ backgroundColor }}
>
<div className="absolute inset-0 opacity-10 pointer-events-none mix-blend-overlay">
<GenerativeArt
seed={foregroundColor + backgroundColor}
className="w-full h-full"
/>
</div>
<div
className="relative z-10 text-center space-y-6"
style={{ color: foregroundColor }}
>
<div className="text-6xl md:text-8xl font-black uppercase tracking-tighter leading-none">
Sample Text
</div>
<p className="text-xl md:text-2xl font-light max-w-md mx-auto leading-relaxed">
The quick brown fox jumps over the lazy dog.
</p>
</div>
</div>
{/* Metrics Dashboard */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-8">
<div className="border border-white/10 bg-white/[0.02] p-8 rounded-sm flex flex-col items-center justify-center gap-2">
<span className="font-mono text-[10px] text-gray-500 uppercase tracking-widest">
Ratio
</span>
<div className="text-4xl font-black text-emerald-500">
{contrastRatio}:1
</div>
</div>
<div
className={`border border-white/10 p-8 rounded-sm flex flex-col items-center justify-center gap-4 transition-all ${wcagStatus.aa ? 'bg-emerald-500/10 border-emerald-500/20' : 'bg-red-500/10 border-red-500/20'}`}
>
<span className="font-mono text-[10px] text-gray-500 uppercase tracking-widest">
WCAG_AA
</span>
{wcagStatus.aa ? (
<CheckCircleIcon
size={32}
weight="fill"
className="text-emerald-500"
/>
) : (
<XCircleIcon
size={32}
weight="fill"
className="text-red-500"
/>
)}
<span
className={`text-[10px] font-black uppercase tracking-widest ${wcagStatus.aa ? 'text-emerald-500' : 'text-red-500'}`}
>
{wcagStatus.aa ? 'PASS' : 'FAIL'}
</span>
</div>
<div
className={`border border-white/10 p-8 rounded-sm flex flex-col items-center justify-center gap-4 transition-all ${wcagStatus.aaa ? 'bg-emerald-500/10 border-emerald-500/20' : 'bg-red-500/10 border-red-500/20'}`}
>
<span className="font-mono text-[10px] text-gray-500 uppercase tracking-widest">
WCAG_AAA
</span>
{wcagStatus.aaa ? (
<CheckCircleIcon
size={32}
weight="fill"
className="text-emerald-500"
/>
) : (
<XCircleIcon
size={32}
weight="fill"
className="text-red-500"
/>
)}
<span
className={`text-[10px] font-black uppercase tracking-widest ${wcagStatus.aaa ? 'text-emerald-500' : 'text-red-500'}`}
>
{wcagStatus.aaa ? 'PASS' : 'FAIL'}
</span>
</div>
</div>
</div>
</div>
<footer className="mt-32 pt-12 border-t border-white/10 flex flex-col md:flex-row justify-between items-center gap-6 text-gray-600 font-mono text-[10px] uppercase tracking-[0.3em]">
<span>Fezcodex_Chromatic_Analyzer_v0.6.1</span>
<span className="text-gray-800">ACCESSIBILITY_MODE // VERIFIED</span>
</footer>
</div>
</div>
);
};
export default ColorContrastCheckerPage;