Cookie obsługa
This commit is contained in:
51
src/islands/Cookie.jsx
Normal file
51
src/islands/Cookie.jsx
Normal 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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user