Added richtext support, and helpers for proxy, llms route
This commit is contained in:
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
|
||||
|
||||
import { CONSENT_CATEGORIES, type ConsentCategory } from './categories.js'
|
||||
import { useConsentContext } from './ConsentContext.js'
|
||||
import { useIsMounted } from './useIsMounted.js'
|
||||
|
||||
/**
|
||||
* Optional class overrides — for when tokens aren't enough, e.g. turning the
|
||||
@@ -53,6 +54,7 @@ const mutedText =
|
||||
'text-[var(--ipal-text-muted,#737373)] dark:text-[var(--ipal-text-muted-dark,#a3a3a3)]'
|
||||
|
||||
export function CookieBanner({ classNames }: { classNames?: CookieBannerClassNames } = {}) {
|
||||
const isMounted = useIsMounted()
|
||||
const { acceptAll, decided, rejectAll, savePreferences, state, texts } = useConsentContext()
|
||||
const [showSettings, setShowSettings] = useState(false)
|
||||
const [choices, setChoices] = useState<Record<ConsentCategory, boolean>>(state)
|
||||
@@ -61,6 +63,10 @@ export function CookieBanner({ classNames }: { classNames?: CookieBannerClassNam
|
||||
setChoices(state)
|
||||
}, [state])
|
||||
|
||||
// Render nothing until mounted — avoids the React 19 hydration mismatch that
|
||||
// projects used to work around with a setTimeout ConsentWrapper. No wrapper
|
||||
// needed now.
|
||||
if (!isMounted) {return null}
|
||||
if (decided) {return null}
|
||||
|
||||
const toggle = (cat: ConsentCategory) => {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { Cookie } from 'lucide-react'
|
||||
|
||||
import { useConsentContext } from './ConsentContext.js'
|
||||
import { useIsMounted } from './useIsMounted.js'
|
||||
|
||||
/**
|
||||
* Floating "cookie settings" button — lets visitors reopen the consent panel
|
||||
@@ -14,8 +15,12 @@ import { useConsentContext } from './ConsentContext.js'
|
||||
* replace the styling outright.
|
||||
*/
|
||||
export function CookieButton({ className }: { className?: string } = {}) {
|
||||
const isMounted = useIsMounted()
|
||||
const { decided, reopen } = useConsentContext()
|
||||
|
||||
// Render nothing until mounted — prevents hydration mismatch (no project
|
||||
// ConsentWrapper workaround needed).
|
||||
if (!isMounted) {return null}
|
||||
if (!decided) {return null}
|
||||
|
||||
const cls =
|
||||
|
||||
@@ -18,3 +18,4 @@ export {
|
||||
serializeConsent,
|
||||
} from './storage.js'
|
||||
export type { ConsentTexts } from './texts.js'
|
||||
export { useIsMounted } from './useIsMounted.js'
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
'use client'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
/**
|
||||
* Returns true only after the component has mounted on the client. Used to gate
|
||||
* consent UI (CookieBanner, CookieButton) so it renders nothing during SSR /
|
||||
* first paint — preventing the React 19 / Next hydration mismatch that projects
|
||||
* were working around with their own setTimeout-based ConsentWrapper. Built into
|
||||
* the components now, so no project wrapper is needed.
|
||||
*/
|
||||
export function useIsMounted(): boolean {
|
||||
const [mounted, setMounted] = useState(false)
|
||||
useEffect(() => {
|
||||
setMounted(true)
|
||||
}, [])
|
||||
return mounted
|
||||
}
|
||||
Reference in New Issue
Block a user