Cookie obsługa

This commit is contained in:
dm
2025-11-23 12:34:47 +01:00
parent 17ed3f74f0
commit 20ef0d5293
7 changed files with 242 additions and 1 deletions

51
src/islands/Cookie.jsx Normal file
View File

@@ -0,0 +1,51 @@
import { useEffect, useState } from "preact/hooks";
import "../styles/cookie.css";
export default function Cookie({ config }) {
const [visible, setVisible] = useState(false);
useEffect(() => {
const consent = localStorage.getItem("cookie-consent");
// Jeśli brak zgody pokaż po 150ms (animacja)
if (!consent) {
setTimeout(() => setVisible(true), 150);
}
}, []);
const handle = (value) => {
localStorage.setItem("cookie-consent", value);
setVisible(false);
};
if (!config?.enabled) return null;
return (
<div
id="cookie-banner"
style={{
transform: visible ? "translateY(0)" : "translateY(100%)",
}}
>
<div class="cookie-panel-inner max-w-4xl mx-auto flex flex-col md:flex-row items-start md:items-center justify-between gap-4">
<p class="text-sm leading-snug">
{config.text.message}
<a href={config.links.privacy} class="cookie-privacy-link ml-1">
{config.text.more}
</a>
</p>
<div class="flex gap-3 shrink-0">
<button onClick={() => handle("accepted")} class="cookie-accept">
{config.text.accept}
</button>
<button onClick={() => handle("rejected")} class="cookie-reject">
{config.text.reject}
</button>
</div>
</div>
</div>
);
}