-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathButtons.tsx
More file actions
362 lines (334 loc) · 8.73 KB
/
Buttons.tsx
File metadata and controls
362 lines (334 loc) · 8.73 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
"use client";
import React, { useEffect, useRef, useState } from "react";
import Image from "next/image";
import { useRouter } from "next/navigation";
type ButtonVariant = "regular" | "image" | "long" | "large" | "small";
type ZButtonProps = {
type: ButtonVariant;
text?: string;
color:
| "red"
| "yellow"
| "green"
| "green_2"
| "blue"
| "purple"
| "gray"
| string;
image?: string;
onClick?: () => void;
disabled?: boolean;
clicked?: boolean;
forceColor?: string;
};
type SlotToggleButtonProps = {
onToggle?: (selected: string) => void;
};
type BasicToggleButtonProps = {
defaultState: "on" | "off";
onToggle: (selected: "on" | "off") => void;
};
const colorMap: Record<string, string> = {
red: "#FFAD93",
yellow: "#FFEA79",
green: "#C1FF83",
green_2: "#59FF56",
blue: "#75E5EA",
purple: "#90BDFF",
gray: "#969696",
};
const slotToggleOptions = ["Theory", "Lab"];
export function ZButton({
type,
text,
color,
image,
onClick,
forceColor,
disabled = false,
clicked = false,
}: ZButtonProps) {
const variantClasses = {
regular: "h-12 rounded-xl px-4 text-base gap-2.5",
small: "h-10 w-10 rounded-full p-1 text-base gap-2.5",
image: "h-13 w-13 rounded-xl text-base gap-2.5",
long: "h-12 rounded-xl px-8 text-base gap-2.5",
large: "h-[60px] rounded-[20px] px-8 text-2xl gap-6",
};
const imageSize = type === "large" ? 28 : 24;
const backgroundColor = forceColor
? disabled
? colorMap["gray"]
: clicked
? colorMap["green_2"]
: forceColor
: disabled
? colorMap["gray"]
: clicked
? colorMap["green_2"]
: colorMap[color];
return (
<button
onClick={disabled ? undefined : onClick}
disabled={disabled}
style={{ backgroundColor }}
className={`
font-poppins
border-3 border-black
font-semibold
flex items-center justify-center text-center
transition duration-100
${type === "small" ? "shadow-[2px_2px_0_0_black]" : "shadow-[4px_4px_0_0_black]"}
${disabled ? "cursor-normal" : "cursor-pointer"}
${disabled
? ""
: type === "small"
? "active:shadow-[1px_1px_0_0_black] active:translate-x-[1px] active:translate-y-[1px]"
: "active:shadow-[2px_2px_0_0_black] active:translate-x-[2px] active:translate-y-[2px]"
}
${variantClasses[type]}
`}
>
{text}
{image && (
<span style={{ pointerEvents: "none", display: "flex" }}>
<Image
src={image}
alt=""
width={imageSize}
height={imageSize}
unselectable="on"
draggable={false}
priority
/>
</span>
)}
</button>
);
}
export function CCButton() {
return (
<a
href="https://codechefvit.com"
target="_blank"
rel="noopener noreferrer"
title="CodeChef VIT"
style={{ display: "flex", pointerEvents: "auto" }}
>
<Image
src="/logo_cc.png"
alt="CC Button"
width={80}
height={80}
className="cursor-pointer"
unselectable="on"
draggable={false}
priority
/>
</a>
);
}
export function FFCSButton() {
const router = useRouter();
return (
<Image
src="/logo_ffcs.svg"
alt="FFCS Button"
width={80}
height={80}
className="cursor-pointer"
onClick={() => router.push("/")}
unselectable="on"
draggable={false}
priority
/>
);
}
export function SlotToggleButton({ onToggle }: SlotToggleButtonProps) {
const [selected, setSelected] = useState<string>(slotToggleOptions[0]);
const [sizes, setSizes] = useState<{
[key: string]: { width: number; left: number };
}>({});
const btnRefs = useRef<(HTMLButtonElement | null)[]>([]);
useEffect(() => {
const newSizes: { [key: string]: { width: number; left: number } } = {};
btnRefs.current.forEach((btn, idx) => {
if (btn) {
newSizes[slotToggleOptions[idx]] = {
width: btn.offsetWidth,
left: btn.offsetLeft,
};
}
});
setSizes(newSizes);
}, []);
const handleSelect = (label: string) => {
setSelected(label);
onToggle?.(label);
};
const setIsActive = useState(false)[1];
return (
<div
style={{
fontFamily: "Poppins, sans-serif",
height: "56px",
borderRadius: "18px",
userSelect: "none",
cursor: "pointer",
}}
className={`
relative flex items-center
border-[3px] border-black
shadow-[4px_4px_0_0_black]
transition-all duration-100
bg-[${colorMap["yellow"]}]
px-2 py-1
w-fit
active:shadow-[2px_2px_0_0_black] active:translate-x-[2px] active:translate-y-[2px]
`}
onClick={() =>
handleSelect(
selected === slotToggleOptions[0]
? slotToggleOptions[1]
: slotToggleOptions[0]
)
}
onMouseDown={() => setIsActive(true)}
onMouseUp={() => setIsActive(false)}
onMouseLeave={() => setIsActive(false)}
onTouchStart={() => setIsActive(true)}
onTouchEnd={() => setIsActive(false)}
>
{sizes[selected] && (
<div
className="absolute top-1/2 -translate-y-1/2 h-[80%] bg-white border border-black transition-all duration-100 ease-in-out"
style={{
left: sizes[selected].left,
width: sizes[selected].width,
zIndex: 1,
borderRadius: "15px",
}}
/>
)}
{slotToggleOptions.map((label, idx) => (
<button
key={label}
ref={(el) => {
btnRefs.current[idx] = el;
}}
onClick={(e) => {
e.stopPropagation();
handleSelect(label);
}}
className="relative z-10 px-4 py-0 text-base font-semibold transition-colors duration-200"
style={{
fontFamily: "Poppins, sans-serif",
fontWeight: "700",
background: "none",
border: "none",
cursor: "pointer",
}}
>
{label}
</button>
))}
</div>
);
}
export function BasicToggleButton({
defaultState,
onToggle,
}: BasicToggleButtonProps) {
const [selected, setSelected] = useState<"on" | "off">(defaultState);
const handleSelect = (label: "on" | "off") => {
setSelected(label);
onToggle(label);
};
const setIsActive = useState(false)[1];
const bgColor = selected === "on" ? colorMap["blue"] : colorMap["red"];
return (
<div
className={`
relative flex items-center
border-[3px] border-black
shadow-[4px_4px_0_0_black]
transition-all duration-100
px-2 py-1
w-[60px]
h-[36px]
rounded-[12px]
cursor-pointer
font-poppins
active:shadow-[2px_2px_0_0_black]
active:translate-x-[2px]
active:translate-y-[2px]
`}
style={{ backgroundColor: bgColor }}
onClick={() => handleSelect(selected === "on" ? "off" : "on")}
onMouseDown={() => setIsActive(true)}
onMouseUp={() => setIsActive(false)}
onMouseLeave={() => setIsActive(false)}
onTouchStart={() => setIsActive(true)}
onTouchEnd={() => setIsActive(false)}
>
<div
className={`
absolute
top-1/2
-translate-y-1/2
h-[24px]
w-[24px]
bg-white
border
border-black
transition-all
duration-100
ease-in-out
z-[1]
rounded-[8px]
`}
style={selected === "on" ? { right: 4 } : { left: 4 }}
/>
</div>
);
}
export function GoogleLoginButton({ onClick }: { onClick?: () => void }) {
const buttonColor = "#ffffff";
return (
<button
onClick={onClick}
style={{
backgroundColor: buttonColor,
fontFamily: "Poppins, sans-serif",
height: "48px",
borderRadius: "16px",
userSelect: "none",
}}
className={`
text-black
px-4 py-2
border-3 border-black
font-semibold
text-base
cursor-pointer
flex items-center justify-center text-center gap-2.5
transition duration-100
shadow-[4px_4px_0_0_black]
active:shadow-[2px_2px_0_0_black] active:translate-x-[2px] active:translate-y-[2px]
`}
>
<span style={{ pointerEvents: "none", display: "flex" }}>
<Image
src="/social/google.svg"
alt=""
width={24}
height={4}
unselectable="on"
draggable={false}
priority
/>
</span>
{"Login with Google"}
</button>
);
}