0.7.0 • Published 4 years ago

@qeeps/react-gdpr-cookie-banner v0.7.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

React GDPR Cookie Banner

Build Status

A GDPR compliant Cookie Banner component for React.

Preview Preview

Install

yarn add @qeeps/react-gdpr-cookie-banner

or

npm install --save @qeeps/react-gdpr-cookie-banner

Adjustments

This is a fork of https://github.com/Palmabit-IT/react-cookie-law

Custom adjustments are:

1. Change "Accept"-Button to "Accept All"-Button

When user clicks "Accept All" all options are getting selected and respective cookies are set.

2. Change "Decline"-Button to "Accept Selection"-Button

The Decline-Button got removed and therefor a "Accept Selection"-Button got introduced which basically just sets the selected cookies. Initially - if no checkbox is selected - this button just sets the necessary cookies.

3. Checkbox-Labels are clickable:

You can now click the labels to select/deselect the options

4. Introduced options to set an initial state for each checkbox:

NameTypeDefaultDescription
preferencesOptionInitiallyCheckedboolfalseoptional. Sets the inital state of the preferences checkbox
statisticsOptionInitiallyCheckedboolfalseoptional. Sets the inital state of the statistics checkbox
marketingOptionInitiallyCheckedboolfalseoptional. Sets the inital state of the marketing checkbox

Usage

import { CookieBanner } from '@qeeps/react-gdpr-cookie-banner';

React.renderComponent(
  <div>
    <CookieBanner
      message="Cookie banner message"
      onAcceptPreferences = {() => { 
        // load your preferences trackers here
      }}
      onAcceptStatistics = {() => {
        // load your statistics trackers here
      }}
      onAcceptMarketing = {() => {
        // load your marketing trackers here
      }}
    />
  </div>,
  document.body
);

Options

NameTypeDefaultDescription
classNamestringoptional. Classes
messagestringRequired. Custom text of the banner
policyLinkstring"/#"optional. Link to privacy policy page
privacyPolicyLinkTextstring"Privacy Policy"optional. Text for the privacy policy link
necessaryOptionTextstring"Necessary"optional. Text for the necessary cookies checkbox
preferencesOptionTextstring"Preferences"optional. Text for the preferences cookies checkbox
statisticsOptionTextstring"Statistics"optional. Text for the statistics cookies checkbox
marketingOptionTextstring"Marketing"optional. Text for the marketing cookies checkbox
acceptAllButtonTextstring"Accept All"optional. Text for the acceptAll button
acceptSelectionButtonTextstring"Accept Selection"optional. Text for the acceptSelection button
showAcceptSelectionButtonboolfalseoptional. Show or hide the acceptSelection button
dismissOnScrollboolfalseoptional. Enable or disable the dismissing on scroll of the banner
showPreferencesOptionbooltrueoptional. Show or hide the preferences checkbox
showStatisticsOptionbooltrueoptional. Show or hide the statistics checkbox
showMarketingOptionbooltrueoptional. Show or hide the marketing checkbox
preferencesOptionInitiallyCheckedboolfalseoptional. Sets the inital state of the preferences checkbox
statisticsOptionInitiallyCheckedboolfalseoptional. Sets the inital state of the statistics checkbox
marketingOptionInitiallyCheckedboolfalseoptional. Sets the inital state of the marketing checkbox
onAcceptfunctionFunctionoptional. Callback called when the consent is given
onAcceptPreferencesfunctionFunctionoptional. Callback called if preferences cookies is accepted
onAcceptStatisticsfunctionFunctionoptional. Callback called if statistics cookies is accepted
onAcceptMarketingfunctionFunctionoptional. Callback called if marketing cookies is accepted
onDeclinePreferencesfunctionFunctionoptional. Callback called if preferences cookies is declined
onDeclineStatisticsfunctionFunctionoptional. Callback called if statistics cookies is declined
onDeclineMarketingfunctionFunctionoptional. Callback called if marketing cookies is declined

Style

<CookieBanner
  message="Cookie banner message"
  styles={{
    dialog: { backgroundColor: 'red' }
  }}
/>
Style optionDescription
dialogStyle that override .react-cookie-law-dialog class
container.react-cookie-law-container class
messageStyle for banner text (.react-cookie-law-message class)
policyStyle for cookie policy link (.react-cookie-law-policy class)
selectPaneStyle for select pane (.react-cookie-law-select-pane class)
optionWrapperStyle for option checkbox wrapper (.react-cookie-law-option-wrapper class)
optionLabelStyle for the text of checkbox labels
checkboxStyle for checkboxes (.react-cookie-law-option-checkbox class)
buttonWrapperStyle for buttons wrapper (.react-cookie-law-dialog class)
buttonStyle for buttons (.react-cookie-law-dialog class)

To style the buttons differently you can use the following classes:

ClassnameDescription
react-cookie-law-accept-all-btnStyles the Accept All-Button
react-cookie-law-accept-selection-btnStyles the Accept Selection-Button

Example of a custom style:

Preview

Test

yarn test

or

npm test

Author

Original Author

Palmabit-IT

Improvements

Daniel Engelhardt (qeeps.de)

Licence

See the MIT License