This commit is contained in:
Joshua Chen 2022-01-16 17:19:15 +08:00
parent 7a17da02cd
commit 888d259313
No known key found for this signature in database
GPG key ID: C37145B818BDB68F
3 changed files with 10 additions and 3 deletions

View file

@ -15,5 +15,5 @@ declare module '@docusaurus/plugin-google-gtag' {
}
declare module '@theme/CookieConsent' {
export default function CookieConsent(): JSX.Element;
export default function CookieConsent(): JSX.Element | null;
}

View file

@ -5,14 +5,18 @@
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import React, {useState} from 'react';
import clsx from 'clsx';
import styles from './styles.module.css';
import {createStorageSlot} from '@docusaurus/theme-common';
const storage = createStorageSlot('docusaurus.cookieConsent');
export default function CookieConsent(): JSX.Element {
export default function CookieConsent(): JSX.Element | null {
const [dismissed, setDismissed] = useState(false);
if (dismissed) {
return null;
}
return (
<div className={styles.banner}>
<p className={styles.text}>
@ -24,6 +28,7 @@ export default function CookieConsent(): JSX.Element {
className={clsx('clean-btn', styles.button)}
onClick={() => {
storage.set('true');
setDismissed(true);
}}>
Accept
</button>
@ -32,6 +37,7 @@ export default function CookieConsent(): JSX.Element {
className={clsx('clean-btn', styles.button)}
onClick={() => {
storage.set('true');
setDismissed(true);
}}>
Deny
</button>

View file

@ -12,6 +12,7 @@
right: 20px;
width: 300px;
height: 200px;
border-radius: var(--ifm-global-radius);
}
.text {