0.1.10-alpha • Published 2 years ago

@binarypaw/react-cookie-consent v0.1.10-alpha

Weekly downloads
-
License
EPL-2.0
Repository
github
Last release
2 years ago

Cookie consent

In times of GDPR and other data protection regulations, managing cookies decently has become more and more important. This library should make this process a bit easier for your website. React-cookie-consent is a frontend library that allows users of your website to configure cookies. It does not prevent your website from setting cookies without consent but it does provide you with a list of cookies that the user agreed to.

Installation

Add the library to you project with the following command: npm install @binarypaw/react-cookie-consent

Usage

The library exposes one react component which must be added to the top-level of your application. Make sure to include the separate css file being delivered.

import React from "react";
import { CookieConsent } from "@binarypaw/react-cookie-consent";
import "@binarypaw/react-cookie-consent/dist/cookieConsent.css";

function App() {
	return (
		<>
			<CookieConsent />
			<div>Your content</div>
		</>
	);
}

You want a fast start? Have a look at our example. All component props are documented in the properties section

Example

import React from "react";
import { CookieConsent } from "@binarypaw/react-cookie-consent";
import "@binarypaw/react-cookie-consent/dist/cookieConsent.css";

function App() {
	const name = "BinaryPaw";
	const preamble = "We bake great cookies ;)";
	const privacyLink = "https://example.com";
	const cookies = [{
		group: "General",
		name: "APSID",
		desc: "This cookie refers to the current session we use to identify your machine.",
		consent: false,
		mandatory: true,
	}];
	const thirdParties = [{
		name: "Rainbow",
		desc: "The rainbow service uses cookies to make your website look like a rainbow",
		privacyLink: "https://example.com",
		optOutLink: "https://example.com",
	}];
	const handleSave = (cookies) => {
		console.log(cookies);
	};

	return (
	<CookieConsent
		name={name}
		preamble={preamble}
		privacyPolicyLink={privacyLink}
		cookies={cookies}
		thirdPartyProvider={thirdParties}
		onSave={handleSave}
	/>
	);
}

Properties

NameDescriptionTypeDefault
nameyour websites namestringn/a
activated?activates/deactivates the whole cookie-consentbooleantrue
language?language for prewritten texts"en" or "de""en"
preambleshort description explaining what cookies are used forstringn/a
privacyPolicyLinkprivacy policy link of your websitestringn/a
cookiePolicyLink?cookie policy link of your websitestringn/a
cookies?all the cookies your website usesICookie[][]
thirdPartyProvider?list of all third-party providersIThirdPartyProvider[][]
onSave?function is being called when the user saves it's cookie choicesFunctionn/a
colors?Changes preset colorsIThemeColorsn/a

name

Choose any name which is then being displayed on the cookie-consent banner.

activated?

Deactivates or activates the whole cookie-consent library.

language?

Defines the language for all pre-written texts for example buttons.

preamble

The preamble describes the usage of your cookies and must make the user aware that more information can be found in the cookie or privacy policy.

privacyPolicyLink

The weblink to your privacy policy.

cookiePolicyLink?

The weblink to your cookie policy.

cookies?

An array of all cookies being used by your website.

[{
	name:  string;
	group:  string;
	consent:  boolean;
	mandatory:  boolean;
	desc:  string;
}]

thirdPartyProvider?

An array of all third-party providers which your website makes use of.

tpye URLString = `https://${string}.${string}` // normal web url

[{
	name:  string;
	desc:  string;
	privacyLink: URLString;
	optOutLink: URLString;
}]

onSave?

This function will be called every time the user saves his cookie settings. The first parameter of the function is the whole list of cookies. function onSave(cookies: Array<ICookie>) {...}

colors?

The colors prop let's you edit every color used by the theme in order to make it fit with your own custom theme.

type ColorString = `#${string}` // 6-digit hex-code

{
	text?:  ColorString;
	secondary?:  ColorString;
	bg?:  ColorString;
	accept?:  ColorString;
	decline?:  ColorString;
	accent?:  ColorString;
}

License

Cookie-Consent is licensed under EPL 2.0. Read more here: EPL 2.0.

0.1.10-alpha

2 years ago

0.1.9-alpha

2 years ago

0.1.8-alpha

2 years ago

0.1.7-alpha

2 years ago

0.1.6-alpha

2 years ago

0.1.5-alpha

2 years ago

0.1.4-alpha

2 years ago

0.1.3-alpha

2 years ago

0.1.2-alpha

2 years ago

0.1.1-alpha

2 years ago

0.1.0-alpha

2 years ago