eisberg labs logo
Eisberg Labs React Components
About UsBlog

Downloads

Mui Next Cookie Consent

React Material Ui cookie consent dialog, compatible with Nextjs cookies.

Installation

Prerequisites are:

npm i --save @eisberg-labs/mui-next-cookie-consent

Usage

Just import the template with defaults:

<CookieConsent>This website uses cookies to enhance the user experience.</CookieConsent>

I use it in a nextjs app like this:


const CookieConsent = dynamic(() => import('@eisberg-labs/mui-next-cookie-consent'), {suspense: true});

export default function Layout({children}) {
  return (
    <>
      <AppHeader/>
      <div className={styles.wrapper}>{children}</div>
      <Suspense><CookieConsent
        cookieOptions={{
          expires: moment().add(1, 'years').toDate()
        }}
        confirmText="I agree"
      >This website uses cookies to enhance the user experience.</CookieConsent></Suspense>
      <Footer/>
    </>
  );
}

You can change the default styling, cookie key, set expires, register callback on Accept.

Api

NameTypeDefaultDescription
defaultNamestring'CookieConsent'Cookie key name for cookie consent
confirmTextReact.ReactNode'I understand'Confirm button text
snackbarClassNamestring'fixed p-3 z-50 bottom-0'snackbar class name
rootClassNamestring'rounded-lg bg-white shadow-2xl p-3'
buttonClassNamestring'bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow'
cookieOptionsCookieSerializeOptionse.g. {expires: moment().add(1, 'days').toDate()}
onAccept()=>voidOptional function that triggers after cookie consent accepted.

License

MIT © Eisberg Labs

Examples

basic-example.tsx

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

4.0.2 (2023-01-25)

Note: Version bump only for package @eisberg-labs/mui-next-cookie-consent

4.0.0 (2023-01-25)

Features

BREAKING CHANGES

3.1.0 (2023-01-03)

Note: Version bump only for package @eisberg-labs/mui-next-cookie-consent

3.0.1 (2023-01-02)

Note: Version bump only for package @eisberg-labs/mui-next-cookie-consent

3.0.0 (2022-12-27)

Features

1.1.1 (2022-12-16)

Note: Version bump only for package @eisberg-labs/mui-next-cookie-consent

1.1.0 (2022-12-16)

Features