From 14dbd311366bf0a61526a064730f57cde52ad8e3 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Tue, 8 Apr 2025 21:16:39 -0700 Subject: add new better styled demo page and components --- site/src/components/CaptchaGrid.tsx | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 site/src/components/CaptchaGrid.tsx (limited to 'site/src/components/CaptchaGrid.tsx') diff --git a/site/src/components/CaptchaGrid.tsx b/site/src/components/CaptchaGrid.tsx new file mode 100644 index 0000000..40b1c09 --- /dev/null +++ b/site/src/components/CaptchaGrid.tsx @@ -0,0 +1,52 @@ +import React, { useState } from "react"; + +interface CaptchaGridProps { + images: string[]; + onSelectionChange: (selectedIndicies: number[]) => void; +} + +const CaptchaGrid: React.FC = ({ images, onSelectionChange }) => { + const [selectedIndicies, setSelectedIndicies] = useState([]); + const handleSelect = (index: number) => { + let newSelectedState: number[]; + if (selectedIndicies.includes(index)) { + newSelectedState = selectedIndicies.filter((i) => i !== index) + } + else { + newSelectedState = [...selectedIndicies, index]; + } + setSelectedIndicies(newSelectedState); // update local view + onSelectionChange(newSelectedState); // pass to parent + + } + + return ( +
+ {images.map((imageUrl, idx) => ( +
handleSelect(idx)} + > + {`Image + {selectedIndicies.includes(idx) && ( +
+
+ + + +
+
+ )} +
+ ))} +
+ ); +}; + +export default CaptchaGrid -- cgit v1.2.3