react-mui-cookie-dialog
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

React Material Ui Cookie Dialog

Version Downloads

A simple solution for a GDPR compliant Cookie dialog.

Example

import { Typography } from '@material-ui/core';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {
  CookieDialog,
  CookieDialogCategory,
  cookieDialogStringDefaultsGerman,
} from 'react-mui-cookie-dialog';

const categories: CookieDialogCategory[] = [
  {
    key: 'necessary',
    title: 'Necessary Cookies',
    description: 'Necessary Cookie description.',
    isNecessary: true,
  },
  {
    key: 'analytics',
    title: 'Analytics & Personalization',
    description: 'Analytics Cookie description.',
  },
  {
    key: 'marketing',
    title: 'Marketing',
    description: 'Marketing Cookie description.',
  },
];

const App = () => {
  const [cookieDialogVisible, setCookieDialogVisible] = React.useState(true);

  const handleAccept = (acceptedCategories: CookieDialogCategory[]) => {
    // Do something with the accepted categories
    setCookieDialogVisible(false);
  };

  return (
    <div>
      <CookieDialog
        visible={cookieDialogVisible}
        categories={categories}
        onAccept={handleAccept}
        // You can use the german pre defined strings but for every
        // other language you will have to define the strings yourself.
        {...cookieDialogStringDefaultsGerman}
        // Every string can be replaced with a function component like this
        mainDialogTitle={() => <Typography>Example title</Typography>}
      />
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));

Package Sidebar

Install

npm i react-mui-cookie-dialog

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

75.6 kB

Total Files

12

Last publish

Collaborators

  • innfactory