1.0.5 • Published 1 year ago

@shamaz332/react-gdpr v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Cookie Notice

A lightweight and customizable React component for informing users about the use of cookies on your website. React Cookie Notice gives you full control over the cookies that will be set by the component.

Look

react-cookie-notice react-cookie-notice

Installation

npm install @shamaz332/react-gdpr --save

Usage

Import:

import CookieNotice from '@shamaz332/react-gdpr';

Usage:

<CookieNotice>
    <h3>This website uses cookies</h3>
    <p>We use cookies that help the website to function and also to track how you interact with it. We will only use the cookies if you consent to it by clicking on "Accept all cookies". You can also manage individual cookie preferences.</p>
</CookieNotice>

Optionally some props can be set. A full list of available props can be found below.

<CookieNotice
    onSave={(cookies) => {
        console.log(cookies);
    }}
    onInit={(cookies) => {
        console.log(cookies);
    }}
    acceptAllButtonText="Accept"
    cookiePrefix="my-cookie-"
    cookies={[
        { name: 'necessary', checked: true, editable: false, default: true, title: 'Essential', text: 'Essential cookies enable basic functions and are necessary for the proper function of the website. The website cannot function properly without these cookies.' },
        { name: 'marketing', checked: false, editable: true, title: 'Marketing', text: 'Marketing cookies are used to track visitors across websites. They are used by third-party advertisers or publishers to display personalized ads.' },
        { name: 'test', checked: false, editable: true, title: 'Title', text: 'Lorem ipsum dolor sit amet.' }
    ]}>
    <h3>This website uses cookies</h3>
    <p>We use cookies that help the website to function and also to track how you interact with it. We will only use the cookies if you consent to it by clicking on "Accept all cookies". You can also manage individual cookie preferences.</p>
</CookieNotice>

Props

NameTypeDefaultDescription
preferencesButtonTextstringCookie preferencesContent of preferences button.
savePreferencesButtonTextstringSave cookie preferencesContent of save preferences button.
acceptAllButtonTextstringAccept all cookiesContent of accept button.
linkOnestring | First Link.
linkTwostring | Second Link.
linkOneTextstring | First Link Text.
linkTwoTextstring | Second Link Text.
cookiesarrayArray of objects**Array of available cookies (see Cookies Property).
cookiePrefixstringreact_cookie_notice_Prefix of the cookie name.
containerClassstringreact-cookie-notice-containerCSS classes of the container div.
contentClassstringreact-cookie-notice-contentCSS classes of the content div.
buttonsClassstringreact-cookie-notice-buttonsCSS classes of the button div.
buttonPrimaryClassstringreact-cookie-notice-button-primaryCSS classes of the primary button.
buttonSecondaryClassstringreact-cookie-notice-button-secondarCSS classes of the secondary button.
onSavefunction(cookies) => {}Function to be called after any cookie is set. Receives an array of all cookies and their informations.
onInitfunction(cookies) => {}Function to be called after the component is initialized. Receives an array of all cookies and their informations.
containerStyleobject{}Inline styling for the container div.
contentStyleobject{}Inline styling for the content div.
cookieStyleobject{}Inline styling for the cookie div.
buttonsStyleobject{}Inline styling for the buttons div.
buttonPrimaryStyleobject{}Inline styling for the primary button.
buttonSecondaryStyleobject{}Inline styling for the secondary button.
cookieOptionsobject{ expires: 365 }Defines additional cookie attributes. See: https://github.com/js-cookie/js-cookie#cookie-attributes
toggleVisibilitybooleantrueToggles the display of the cookie notice. Change value of toggleVisibility to hide or show.
legacyCookiebooleanfalseDefines whether the legacy cookie is set. See: https://web.dev/samesite-cookie-recipes/
legacyCookieOptionsboolean{ expires: 365 }Defines additional legacy cookie attributes. See: https://github.com/js-cookie/js-cookie#cookie-attributes
showCookiePreferencesbooleantrueDefines whether the preferences button is displayed.

** default value of cookies property

[
    { name: 'necessary', checked: true, editable: false, default: true, title: 'Essential', text: '...' },
    { name: 'marketing', checked: false, editable: true, title: 'Marketing', text: '...' }
];

Cookies Property

You can define as many cookies as you want. A default cookie is required, which is identified with the key default.

Example:

[
  { name: 'necessary', checked: true, editable: false, default: true, title: 'Essential', text: '...' },
  ...
];

A cookie object has the following properties:

name Name of the cookie. The cookie will be set with the name: prefix + name

checked Defines whether the cookie is preselected in the checkbox.

editable Defines whether the cookie checkbox can be edited. Required cookies should not be editable, like the necessary cookie.

default A cookie in the list must be default. Usually it is the necessary cookie.

title Text that is displayed next to the checkbox.

text Description of the cookie. Will be displayed below the title.

License

MIT

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago