Loads of Riddle Stuff
This commit is contained in:
1 parent
69b730ad92
commit
eaa5cc0065
18 files changed
+393
-87
No files matched your search
@@ -1,18 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { CSSProperties, ReactNode, useRef, useState } from "react";
|
||||
import { CSSProperties, ReactNode, useEffect, useRef, useState } from "react";
|
||||
import styles from "@/css/ChargedButton.module.css";
|
||||
|
||||
interface ChargedButtonProps {
|
||||
children?: ReactNode;
|
||||
style?: CSSProperties;
|
||||
className?: string;
|
||||
/** Time in milliseconds needed to fully charge by continuous hold. */
|
||||
holdDuration?: number;
|
||||
/** Runs exactly once, when the button is fully charged at 100%. */
|
||||
onAction?: () => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
red?: boolean;
|
||||
}
|
||||
|
||||
export default function ChargedButton({
|
||||
children,
|
||||
@@ -21,10 +20,11 @@ export default function ChargedButton({
|
||||
holdDuration = 500,
|
||||
onAction,
|
||||
disabled = false,
|
||||
red = false,
|
||||
}: ChargedButtonProps) {
|
||||
const [progress, setProgress] = useState(0);
|
||||
const [isCharging, setIsCharging] = useState(false);
|
||||
const [isDischarging, setIsDischarging] = useState(false);
|
||||
const [, setIsCharging] = useState(false);
|
||||
const [, setIsDischarging] = useState(false);
|
||||
const rafRef = useRef(0);
|
||||
const startTimeRef = useRef(0);
|
||||
const dischargingRef = useRef(false);
|
||||
@@ -36,6 +36,10 @@ export default function ChargedButton({
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => cancelRaf();
|
||||
}, []);
|
||||
|
||||
const onPointerDown = () => {
|
||||
if (disabled || dischargingRef.current) return;
|
||||
cancelRaf();
|
||||
@@ -83,26 +87,37 @@ export default function ChargedButton({
|
||||
rafRef.current = requestAnimationFrame(updateProgress);
|
||||
};
|
||||
|
||||
const clipPercent = (1 - progress) * 100;
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={styles["charged-button"] + ((disabled) ? " " + styles["button-disabled"] : "") + (className ? " " + className : "")}
|
||||
className={`${styles["charged-button"]} ${disabled ? styles["button-disabled"] : ""} ${className || ""}`.trim()}
|
||||
style={style}
|
||||
onPointerDown={onPointerDown}
|
||||
onTouchStart={onPointerDown}
|
||||
onPointerUp={onPointerUp}
|
||||
onTouchEnd={onPointerUp}
|
||||
onPointerCancel={onPointerUp}
|
||||
onTouchCancel={onPointerUp}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
>
|
||||
<span className={styles["charged-button-label"]}>{children}</span>
|
||||
<span
|
||||
className={styles["charged-button-frame"]}
|
||||
aria-hidden="true"
|
||||
style={{ backgroundImage: "url(/buttons/Button_leer.webp)" }}
|
||||
/>
|
||||
|
||||
<span
|
||||
className={styles["charged-button-fill"]}
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
clipPath: `inset(0 ${100 - progress * 100}% 0 0)`,
|
||||
backgroundImage: red ? "url(/buttons/Button_rot_lang.webp)" : "url(/buttons/Button_blau_lang.webp)",
|
||||
clipPath: `inset(0 ${clipPercent}% 0 0)`,
|
||||
WebkitClipPath: `inset(0 ${clipPercent}% 0 0)`,
|
||||
}}
|
||||
/>
|
||||
|
||||
<span className={styles["charged-button-label"]}>{children}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user