mirror of
https://github.com/Mastermindzh/react-cookie-consent.git
synced 2025-08-23 09:35:04 +02:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
086558f463 | |||
|
712adf9c5b | ||
|
ab046db1e8 | ||
775ec9db96 | |||
eaaf6f8797 | |||
8c86599f24 | |||
719bb2f496 | |||
9a0c974b2a | |||
c2f92ec130 | |||
7136086602 | |||
|
c3ba87e62f | ||
239001cb19 | |||
e024961eae | |||
a19649bbcf |
28
CHANGELOG.md
28
CHANGELOG.md
@@ -5,10 +5,38 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [[7.1.1]](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/7.1.0)
|
||||
|
||||
- `customContentAttributes` and `customContainerAttributes` are now optional in the typing file as they should be
|
||||
|
||||
## [[7.1.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/7.1.0)]
|
||||
|
||||
- Added custom attribute props for content and container
|
||||
|
||||
## [[7.0.1](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/7.0.1)]
|
||||
|
||||
- Configured webpack to remove self from build artefact. Should now work in Nextjs and Gatsby (only tested those..)
|
||||
|
||||
## [[7.0.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/7.0.0)]
|
||||
|
||||
- Switched from CommonJS to UMD module
|
||||
|
||||
## [[6.4.1](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.4.1))]
|
||||
|
||||
- Added missing typing
|
||||
|
||||
## [[6.4.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.4.0))]
|
||||
|
||||
- Added visible prop
|
||||
|
||||
## [[6.3.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.2.3))]
|
||||
|
||||
- Added the (optional) scrolling effect back in as it is declared legal in some countries now.
|
||||
|
||||
## [6.2.4]
|
||||
|
||||
- version bumps :)
|
||||
|
||||
## [[6.2.3](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.2.3)]
|
||||
|
||||
- Added support for IE11, the webpack generated runtime-code should not use arrow functions
|
||||
|
22
README.md
22
README.md
@@ -20,6 +20,7 @@ Example branch: https://github.com/Mastermindzh/react-cookie-consent/tree/exampl
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Using it](#using-it)
|
||||
- [getting the cookies value in your own code](#getting-the-cookies-value-in-your-own-code)
|
||||
- [Props](#props)
|
||||
- [Debugging it](#debugging-it)
|
||||
- [Why are there two cookies? One of which named "Legacy"](#why-are-there-two-cookies-one-of-which-named-legacy)
|
||||
@@ -28,9 +29,11 @@ Example branch: https://github.com/Mastermindzh/react-cookie-consent/tree/exampl
|
||||
- [Changing the bar background to red](#changing-the-bar-background-to-red)
|
||||
- [Changing the button font-weight to bold](#changing-the-button-font-weight-to-bold)
|
||||
- [Using predefined CSS classes](#using-predefined-css-classes)
|
||||
- [Accept on scroll](#accept-on-scroll)
|
||||
- [Flipping the buttons](#flipping-the-buttons)
|
||||
- [Extra cookie options](#extra-cookie-options)
|
||||
- [Rainbows!](#rainbows)
|
||||
- [Overlay](#overlay)
|
||||
- [Contributor information](#contributor-information)
|
||||
- [Projects using react-cookie-consent](#projects-using-react-cookie-consent)
|
||||
|
||||
@@ -120,11 +123,24 @@ import CookieConsent, { Cookies, getCookieConsentValue } from "react-cookie-cons
|
||||
console.log(getCookieConsentValue());
|
||||
```
|
||||
|
||||
### reset the cookies value in your own code
|
||||
|
||||
react-cookie-consent exports a function called `resetCookieConsentValue`. You can use it in order to remove cookie in client-site:
|
||||
|
||||
```js
|
||||
import CookieConsent, { Cookies, resetCookieConsentValue } from "react-cookie-consent";
|
||||
|
||||
console.log(resetCookieConsentValue());
|
||||
```
|
||||
|
||||
That option would be interesting if you want to allow user to change their consent. If you want to show again the consent bar, you must force "visible" prop to show again the bar.
|
||||
|
||||
## Props
|
||||
|
||||
| Prop | Type | Default value | Description |
|
||||
| ------------------------ | :-------------------------------: | ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| ------------------------ | :-----------------------------------------: | ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| location | string, "top", "bottom" or "none" | "bottom" | Syntactic sugar to easily enable you to place the bar at the top or the bottom of the browser window. Use "none" to disable. |
|
||||
| visible | string, "show", "hidden" or "byCookieValue" | "byCookieValue" | Force the consent bar visibility. If "byCookieValue", visibility are defined by cookie consent existence. |
|
||||
| children | string or React component | | Content to appear inside the bar |
|
||||
| disableStyles | boolean | false | If enabled the component will have no default style. (you can still supply style through props) |
|
||||
| hideOnAccept | boolean | true | If disabled the component will not hide it self after the accept button has been clicked. You will need to hide yourself (see onAccept) |
|
||||
@@ -158,11 +174,13 @@ console.log(getCookieConsentValue());
|
||||
| flipButtons | boolean | false | If enabled the accept and decline buttons will be flipped |
|
||||
| ButtonComponent | React component | button | React Component to render as a button. |
|
||||
| sameSite | string, "strict", "lax" or "none" | none | Cookies sameSite attribute value |
|
||||
| cookieSecurity | boolean | undefined | Cookie security level. Defaults to true unless running on http. |
|
||||
| cookieSecurity | boolean ¡ | undefined | Cookie security level. Defaults to true unless running on http. |
|
||||
| ariaAcceptLabel | string | Accept cookies | Aria label to set on the accept button |
|
||||
| ariaDeclineLabel | string | Decline cookies | Aria label to set on the decline button |
|
||||
| acceptOnScroll | boolean | false | Defines whether "accept" should be fired after the user scrolls a certain distance (see acceptOnScrollPercentage) |
|
||||
| acceptOnScrollPercentage | number | 25 | Percentage of the page height the user has to scroll to trigger the accept function if acceptOnScroll is enabled |
|
||||
| customContentAttributes | object | `{}` | Allows you to set custom (data) attributes on the content div |
|
||||
| customContainerAttributes | object | `{}` | Allows you to set custom (data) attributes on the container div |
|
||||
|
||||
## Debugging it
|
||||
|
||||
|
20
build/index.d.ts
vendored
20
build/index.d.ts
vendored
@@ -4,6 +4,7 @@ import Cookies from "js-cookie";
|
||||
export interface CookieConsentProps {
|
||||
location?: "top" | "bottom" | "none";
|
||||
sameSite?: "strict" | "lax" | "none";
|
||||
visible?: "hidden" | "show" | "byCookieValue";
|
||||
cookieSecurity?: boolean;
|
||||
style?: object;
|
||||
buttonStyle?: object;
|
||||
@@ -12,7 +13,7 @@ export interface CookieConsentProps {
|
||||
children?: React.ReactNode;
|
||||
disableStyles?: boolean;
|
||||
hideOnAccept?: boolean;
|
||||
onAccept?: Function;
|
||||
onAccept?: (acceptedByScrolling?: boolean) => void;
|
||||
onDecline?: Function;
|
||||
buttonText?: Function | React.ReactNode;
|
||||
declineButtonText?: Function | React.ReactNode;
|
||||
@@ -39,6 +40,10 @@ export interface CookieConsentProps {
|
||||
overlayStyle?: object;
|
||||
ariaAcceptLabel?: string;
|
||||
ariaDeclineLabel?: string;
|
||||
acceptOnScroll?: boolean;
|
||||
acceptOnScrollPercentage?: number;
|
||||
customContentAttributes?: object;
|
||||
customContainerAttributes?: object;
|
||||
}
|
||||
|
||||
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {}
|
||||
@@ -51,4 +56,17 @@ export default class CookieConsent extends React.Component<CookieConsentProps, {
|
||||
*/
|
||||
export function getCookieConsentValue(name?: string): string;
|
||||
|
||||
/**
|
||||
* Reset the consent cookie
|
||||
* Remove the cookie on browser in order to allow user to change their consent
|
||||
* @param {*} name optional name of the cookie
|
||||
*/
|
||||
export function resetCookieConsentValue(name?: string);
|
||||
|
||||
/**
|
||||
* Get the legacy cookie name by the regular cookie name
|
||||
* @param {string} name of cookie to get
|
||||
*/
|
||||
export function getLegacyCookieName(name: string);
|
||||
|
||||
export { Cookies };
|
||||
|
806
build/index.js
806
build/index.js
@@ -1,34 +1,220 @@
|
||||
/*! For license information please see index.js.LICENSE.txt */
|
||||
module.exports = (function () {
|
||||
!(function (e, t) {
|
||||
"object" == typeof exports && "object" == typeof module
|
||||
? (module.exports = t())
|
||||
: "function" == typeof define && define.amd
|
||||
? define([], t)
|
||||
: "object" == typeof exports
|
||||
? (exports.ReactCookieConsent = t())
|
||||
: (e.ReactCookieConsent = t());
|
||||
})("undefined" != typeof self ? self : this, function () {
|
||||
return (function () {
|
||||
var e = {
|
||||
866: function (e, t, n) {
|
||||
808: function (e, t, n) {
|
||||
var o, r, i;
|
||||
void 0 ===
|
||||
(r =
|
||||
"function" ==
|
||||
typeof (o = i =
|
||||
function () {
|
||||
function e() {
|
||||
for (var e = 0, t = {}; e < arguments.length; e++) {
|
||||
var n = arguments[e];
|
||||
for (var o in n) t[o] = n[o];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
function t(e) {
|
||||
return e.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
|
||||
}
|
||||
return (function n(o) {
|
||||
function r() {}
|
||||
function i(t, n, i) {
|
||||
if ("undefined" != typeof document) {
|
||||
"number" == typeof (i = e({ path: "/" }, r.defaults, i)).expires &&
|
||||
(i.expires = new Date(1 * new Date() + 864e5 * i.expires)),
|
||||
(i.expires = i.expires ? i.expires.toUTCString() : "");
|
||||
try {
|
||||
var c = JSON.stringify(n);
|
||||
/^[\{\[]/.test(c) && (n = c);
|
||||
} catch (e) {}
|
||||
(n = o.write
|
||||
? o.write(n, t)
|
||||
: encodeURIComponent(String(n)).replace(
|
||||
/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,
|
||||
decodeURIComponent
|
||||
)),
|
||||
(t = encodeURIComponent(String(t))
|
||||
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
|
||||
.replace(/[\(\)]/g, escape));
|
||||
var l = "";
|
||||
for (var s in i)
|
||||
i[s] && ((l += "; " + s), !0 !== i[s] && (l += "=" + i[s].split(";")[0]));
|
||||
return (document.cookie = t + "=" + n + l);
|
||||
}
|
||||
}
|
||||
function c(e, n) {
|
||||
if ("undefined" != typeof document) {
|
||||
for (
|
||||
var r = {}, i = document.cookie ? document.cookie.split("; ") : [], c = 0;
|
||||
c < i.length;
|
||||
c++
|
||||
) {
|
||||
var l = i[c].split("="),
|
||||
s = l.slice(1).join("=");
|
||||
n || '"' !== s.charAt(0) || (s = s.slice(1, -1));
|
||||
try {
|
||||
var a = t(l[0]);
|
||||
if (((s = (o.read || o)(s, a) || t(s)), n))
|
||||
try {
|
||||
s = JSON.parse(s);
|
||||
} catch (e) {}
|
||||
if (((r[a] = s), e === a)) break;
|
||||
} catch (e) {}
|
||||
}
|
||||
return e ? r[e] : r;
|
||||
}
|
||||
}
|
||||
return (
|
||||
(r.set = i),
|
||||
(r.get = function (e) {
|
||||
return c(e, !1);
|
||||
}),
|
||||
(r.getJSON = function (e) {
|
||||
return c(e, !0);
|
||||
}),
|
||||
(r.remove = function (t, n) {
|
||||
i(t, "", e(n, { expires: -1 }));
|
||||
}),
|
||||
(r.defaults = {}),
|
||||
(r.withConverter = n),
|
||||
r
|
||||
);
|
||||
})(function () {});
|
||||
})
|
||||
? o.call(t, n, t, e)
|
||||
: o) || (e.exports = r),
|
||||
(e.exports = i());
|
||||
},
|
||||
703: function (e, t, n) {
|
||||
"use strict";
|
||||
n.r(t),
|
||||
n.d(t, {
|
||||
var o = n(414);
|
||||
function r() {}
|
||||
function i() {}
|
||||
(i.resetWarningCache = r),
|
||||
(e.exports = function () {
|
||||
function e(e, t, n, r, i, c) {
|
||||
if (c !== o) {
|
||||
var l = new Error(
|
||||
"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types"
|
||||
);
|
||||
throw ((l.name = "Invariant Violation"), l);
|
||||
}
|
||||
}
|
||||
function t() {
|
||||
return e;
|
||||
}
|
||||
e.isRequired = e;
|
||||
var n = {
|
||||
array: e,
|
||||
bool: e,
|
||||
func: e,
|
||||
number: e,
|
||||
object: e,
|
||||
string: e,
|
||||
symbol: e,
|
||||
any: e,
|
||||
arrayOf: t,
|
||||
element: e,
|
||||
elementType: e,
|
||||
instanceOf: t,
|
||||
node: e,
|
||||
objectOf: t,
|
||||
oneOf: t,
|
||||
oneOfType: t,
|
||||
shape: t,
|
||||
exact: t,
|
||||
checkPropTypes: i,
|
||||
resetWarningCache: r,
|
||||
};
|
||||
return (n.PropTypes = n), n;
|
||||
});
|
||||
},
|
||||
697: function (e, t, n) {
|
||||
e.exports = n(703)();
|
||||
},
|
||||
414: function (e) {
|
||||
"use strict";
|
||||
e.exports = "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";
|
||||
},
|
||||
},
|
||||
t = {};
|
||||
function n(o) {
|
||||
var r = t[o];
|
||||
if (void 0 !== r) return r.exports;
|
||||
var i = (t[o] = { exports: {} });
|
||||
return e[o](i, i.exports, n), i.exports;
|
||||
}
|
||||
(n.n = function (e) {
|
||||
var t =
|
||||
e && e.__esModule
|
||||
? function () {
|
||||
return e.default;
|
||||
}
|
||||
: function () {
|
||||
return e;
|
||||
};
|
||||
return n.d(t, { a: t }), t;
|
||||
}),
|
||||
(n.d = function (e, t) {
|
||||
for (var o in t)
|
||||
n.o(t, o) && !n.o(e, o) && Object.defineProperty(e, o, { enumerable: !0, get: t[o] });
|
||||
}),
|
||||
(n.o = function (e, t) {
|
||||
return Object.prototype.hasOwnProperty.call(e, t);
|
||||
}),
|
||||
(n.r = function (e) {
|
||||
"undefined" != typeof Symbol &&
|
||||
Symbol.toStringTag &&
|
||||
Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }),
|
||||
Object.defineProperty(e, "__esModule", { value: !0 });
|
||||
});
|
||||
var o = {};
|
||||
return (
|
||||
(function () {
|
||||
"use strict";
|
||||
n.r(o),
|
||||
n.d(o, {
|
||||
Cookies: function () {
|
||||
return s();
|
||||
return l();
|
||||
},
|
||||
OPTIONS: function () {
|
||||
return h;
|
||||
},
|
||||
SAME_SITE_OPTIONS: function () {
|
||||
return m;
|
||||
},
|
||||
default: function () {
|
||||
return j;
|
||||
},
|
||||
getCookieConsentValue: function () {
|
||||
return g;
|
||||
},
|
||||
VISIBLE_OPTIONS: function () {
|
||||
return C;
|
||||
},
|
||||
default: function () {
|
||||
return B;
|
||||
},
|
||||
getCookieConsentValue: function () {
|
||||
return S;
|
||||
},
|
||||
resetCookieConsentValue: function () {
|
||||
return k;
|
||||
},
|
||||
});
|
||||
const o = require("react");
|
||||
var r = n.n(o),
|
||||
i = n(697),
|
||||
c = n.n(i),
|
||||
a = n(808),
|
||||
s = n.n(a);
|
||||
function l(e) {
|
||||
return (l =
|
||||
const e = require("react");
|
||||
var t = n.n(e),
|
||||
r = n(697),
|
||||
i = n.n(r),
|
||||
c = n(808),
|
||||
l = n.n(c);
|
||||
function s(e) {
|
||||
return (s =
|
||||
"function" == typeof Symbol && "symbol" == typeof Symbol.iterator
|
||||
? function (e) {
|
||||
return typeof e;
|
||||
@@ -42,6 +228,7 @@ module.exports = (function () {
|
||||
: typeof e;
|
||||
})(e);
|
||||
}
|
||||
var a = ["children"];
|
||||
function u() {
|
||||
return (u =
|
||||
Object.assign ||
|
||||
@@ -70,7 +257,7 @@ module.exports = (function () {
|
||||
var n = null != arguments[t] ? arguments[t] : {};
|
||||
t % 2
|
||||
? p(Object(n), !0).forEach(function (t) {
|
||||
b(e, t, n[t]);
|
||||
O(e, t, n[t]);
|
||||
})
|
||||
: Object.getOwnPropertyDescriptors
|
||||
? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n))
|
||||
@@ -80,20 +267,7 @@ module.exports = (function () {
|
||||
}
|
||||
return e;
|
||||
}
|
||||
function b(e, t, n) {
|
||||
return (
|
||||
t in e
|
||||
? Object.defineProperty(e, t, {
|
||||
value: n,
|
||||
enumerable: !0,
|
||||
configurable: !0,
|
||||
writable: !0,
|
||||
})
|
||||
: (e[t] = n),
|
||||
e
|
||||
);
|
||||
}
|
||||
function y(e, t) {
|
||||
function b(e, t) {
|
||||
for (var n = 0; n < t.length; n++) {
|
||||
var o = t[n];
|
||||
(o.enumerable = o.enumerable || !1),
|
||||
@@ -109,42 +283,60 @@ module.exports = (function () {
|
||||
return (e.__proto__ = t), e;
|
||||
})(e, t);
|
||||
}
|
||||
function v(e, t) {
|
||||
return !t || ("object" !== l(t) && "function" != typeof t)
|
||||
? (function (e) {
|
||||
if (void 0 === e)
|
||||
throw new ReferenceError(
|
||||
"this hasn't been initialised - super() hasn't been called"
|
||||
);
|
||||
return e;
|
||||
})(e)
|
||||
: t;
|
||||
function y(e, t) {
|
||||
if (t && ("object" === s(t) || "function" == typeof t)) return t;
|
||||
if (void 0 !== t)
|
||||
throw new TypeError("Derived constructors may only return object or undefined");
|
||||
return v(e);
|
||||
}
|
||||
function O(e) {
|
||||
return (O = Object.setPrototypeOf
|
||||
function v(e) {
|
||||
if (void 0 === e)
|
||||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||
return e;
|
||||
}
|
||||
function m(e) {
|
||||
return (m = Object.setPrototypeOf
|
||||
? Object.getPrototypeOf
|
||||
: function (e) {
|
||||
return e.__proto__ || Object.getPrototypeOf(e);
|
||||
})(e);
|
||||
}
|
||||
function O(e, t, n) {
|
||||
return (
|
||||
t in e
|
||||
? Object.defineProperty(e, t, {
|
||||
value: n,
|
||||
enumerable: !0,
|
||||
configurable: !0,
|
||||
writable: !0,
|
||||
})
|
||||
: (e[t] = n),
|
||||
e
|
||||
);
|
||||
}
|
||||
var h = { TOP: "top", BOTTOM: "bottom", NONE: "none" },
|
||||
m = { STRICT: "strict", LAX: "lax", NONE: "none" },
|
||||
g = function () {
|
||||
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : C,
|
||||
t = s().get(e);
|
||||
return void 0 === t && (t = s().get(S(e))), t;
|
||||
g = { STRICT: "strict", LAX: "lax", NONE: "none" },
|
||||
C = { HIDDEN: "hidden", SHOW: "show", BY_COOKIE_VALUE: "byCookieValue" },
|
||||
S = function () {
|
||||
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : j,
|
||||
t = l().get(e);
|
||||
return void 0 === t && (t = l().get(x(e))), t;
|
||||
},
|
||||
S = function (e) {
|
||||
k = function () {
|
||||
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : j;
|
||||
l().remove(e);
|
||||
},
|
||||
x = function (e) {
|
||||
return "".concat(e, "-legacy");
|
||||
},
|
||||
C = "CookieConsent",
|
||||
k = function (e) {
|
||||
j = "CookieConsent",
|
||||
w = function (e) {
|
||||
var t = e.condition,
|
||||
n = e.wrapper,
|
||||
o = e.children;
|
||||
return t ? n(o) : o;
|
||||
},
|
||||
x = (function (e) {
|
||||
T = (function (e) {
|
||||
!(function (e, t) {
|
||||
if ("function" != typeof t && null !== t)
|
||||
throw new TypeError("Super expression must either be null or a function");
|
||||
@@ -152,20 +344,23 @@ module.exports = (function () {
|
||||
constructor: { value: e, writable: !0, configurable: !0 },
|
||||
})),
|
||||
t && d(e, t);
|
||||
})(a, e);
|
||||
var t,
|
||||
n,
|
||||
})(s, e);
|
||||
var n,
|
||||
o,
|
||||
r,
|
||||
i,
|
||||
c =
|
||||
((o = a),
|
||||
((r = s),
|
||||
(i = (function () {
|
||||
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
|
||||
if (Reflect.construct.sham) return !1;
|
||||
if ("function" == typeof Proxy) return !0;
|
||||
try {
|
||||
return (
|
||||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})), !0
|
||||
Boolean.prototype.valueOf.call(
|
||||
Reflect.construct(Boolean, [], function () {})
|
||||
),
|
||||
!0
|
||||
);
|
||||
} catch (e) {
|
||||
return !1;
|
||||
@@ -173,20 +368,31 @@ module.exports = (function () {
|
||||
})()),
|
||||
function () {
|
||||
var e,
|
||||
t = O(o);
|
||||
t = m(r);
|
||||
if (i) {
|
||||
var n = O(this).constructor;
|
||||
var n = m(this).constructor;
|
||||
e = Reflect.construct(t, arguments, n);
|
||||
} else e = t.apply(this, arguments);
|
||||
return v(this, e);
|
||||
return y(this, e);
|
||||
});
|
||||
function a(e) {
|
||||
function s(e) {
|
||||
var t;
|
||||
return (
|
||||
(function (e, t) {
|
||||
if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
|
||||
})(this, a),
|
||||
((t = c.call(this, e)).state = {
|
||||
})(this, s),
|
||||
O(v((t = c.call(this, e))), "handleScroll", function () {
|
||||
var e = t.props.acceptOnScrollPercentage,
|
||||
n = document.documentElement,
|
||||
o = document.body,
|
||||
r = "scrollTop",
|
||||
i = "scrollHeight";
|
||||
((n[r] || o[r]) / ((n[i] || o[i]) - n.clientHeight)) * 100 > e && t.accept(!0);
|
||||
}),
|
||||
O(v(t), "removeScrollListener", function () {
|
||||
t.props.acceptOnScroll && window.removeEventListener("scroll", t.handleScroll);
|
||||
}),
|
||||
(t.state = {
|
||||
visible: !1,
|
||||
style: {
|
||||
alignItems: "baseline",
|
||||
@@ -237,24 +443,36 @@ module.exports = (function () {
|
||||
);
|
||||
}
|
||||
return (
|
||||
(t = a),
|
||||
(n = [
|
||||
(n = s),
|
||||
(o = [
|
||||
{
|
||||
key: "componentDidMount",
|
||||
value: function () {
|
||||
var e = this.props.debug;
|
||||
(void 0 === this.getCookieValue() || e) && this.setState({ visible: !0 });
|
||||
(void 0 === this.getCookieValue() || e) &&
|
||||
(this.setState({ visible: !0 }),
|
||||
this.props.acceptOnScroll &&
|
||||
window.addEventListener("scroll", this.handleScroll, { passive: !0 }));
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "componentWillUnmount",
|
||||
value: function () {
|
||||
this.removeScrollListener();
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "accept",
|
||||
value: function () {
|
||||
var e = this.props,
|
||||
t = e.cookieName,
|
||||
n = e.cookieValue,
|
||||
o = e.hideOnAccept,
|
||||
r = e.onAccept;
|
||||
this.setCookie(t, n), r(), o && this.setState({ visible: !1 });
|
||||
var e = arguments.length > 0 && void 0 !== arguments[0] && arguments[0],
|
||||
t = this.props,
|
||||
n = t.cookieName,
|
||||
o = t.cookieValue,
|
||||
r = t.hideOnAccept,
|
||||
i = t.onAccept;
|
||||
this.setCookie(n, o),
|
||||
i(null != e && e),
|
||||
r && (this.setState({ visible: !1 }), this.removeScrollListener());
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -279,84 +497,91 @@ module.exports = (function () {
|
||||
i = n.sameSite,
|
||||
c = this.props.cookieSecurity;
|
||||
void 0 === c && (c = !location || "https:" === location.protocol);
|
||||
var a = f(f({ expires: r }, o), {}, { sameSite: i, secure: c });
|
||||
i === m.NONE && s().set(S(e), t, a), s().set(e, t, a);
|
||||
var s = f(f({ expires: r }, o), {}, { sameSite: i, secure: c });
|
||||
i === g.NONE && l().set(x(e), t, s), l().set(e, t, s);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "getCookieValue",
|
||||
value: function () {
|
||||
var e = this.props.cookieName;
|
||||
return g(e);
|
||||
return S(e);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "render",
|
||||
value: function () {
|
||||
var e = this;
|
||||
switch (this.props.visible) {
|
||||
case C.HIDDEN:
|
||||
return null;
|
||||
case C.BY_COOKIE_VALUE:
|
||||
if (!this.state.visible) return null;
|
||||
var t = this.props,
|
||||
n = t.location,
|
||||
o = t.style,
|
||||
i = t.buttonStyle,
|
||||
c = t.declineButtonStyle,
|
||||
a = t.contentStyle,
|
||||
s = t.disableStyles,
|
||||
l = t.buttonText,
|
||||
p = t.declineButtonText,
|
||||
b = t.containerClasses,
|
||||
y = t.contentClasses,
|
||||
d = t.buttonClasses,
|
||||
v = t.buttonWrapperClasses,
|
||||
O = t.declineButtonClasses,
|
||||
m = t.buttonId,
|
||||
g = t.declineButtonId,
|
||||
S = t.disableButtonStyles,
|
||||
C = t.enableDeclineButton,
|
||||
x = t.flipButtons,
|
||||
j = t.ButtonComponent,
|
||||
T = t.overlay,
|
||||
w = t.overlayClasses,
|
||||
B = t.overlayStyle,
|
||||
P = t.ariaAcceptLabel,
|
||||
D = t.ariaDeclineLabel,
|
||||
E = {},
|
||||
I = {},
|
||||
}
|
||||
var n = this.props,
|
||||
o = n.location,
|
||||
r = n.style,
|
||||
i = n.buttonStyle,
|
||||
c = n.declineButtonStyle,
|
||||
l = n.contentStyle,
|
||||
s = n.disableStyles,
|
||||
a = n.buttonText,
|
||||
p = n.declineButtonText,
|
||||
b = n.containerClasses,
|
||||
d = n.contentClasses,
|
||||
y = n.buttonClasses,
|
||||
v = n.buttonWrapperClasses,
|
||||
m = n.declineButtonClasses,
|
||||
O = n.buttonId,
|
||||
g = n.declineButtonId,
|
||||
S = n.disableButtonStyles,
|
||||
k = n.enableDeclineButton,
|
||||
x = n.flipButtons,
|
||||
j = n.ButtonComponent,
|
||||
T = n.overlay,
|
||||
B = n.overlayClasses,
|
||||
E = n.overlayStyle,
|
||||
P = n.ariaAcceptLabel,
|
||||
D = n.ariaDeclineLabel,
|
||||
I = n.customContainerAttributes,
|
||||
_ = n.customContentAttributes,
|
||||
A = {},
|
||||
N = {},
|
||||
_ = {},
|
||||
R = {};
|
||||
R = {},
|
||||
L = {},
|
||||
V = {};
|
||||
switch (
|
||||
(s
|
||||
? ((E = u({}, o)),
|
||||
(I = u({}, i)),
|
||||
(N = u({}, c)),
|
||||
(_ = u({}, a)),
|
||||
(R = u({}, B)))
|
||||
: ((E = u({}, f(f({}, this.state.style), o))),
|
||||
(_ = u({}, f(f({}, this.state.contentStyle), a))),
|
||||
(R = u({}, f(f({}, this.state.overlayStyle), B))),
|
||||
? ((A = u({}, r)),
|
||||
(N = u({}, i)),
|
||||
(R = u({}, c)),
|
||||
(L = u({}, l)),
|
||||
(V = u({}, E)))
|
||||
: ((A = u({}, f(f({}, this.state.style), r))),
|
||||
(L = u({}, f(f({}, this.state.contentStyle), l))),
|
||||
(V = u({}, f(f({}, this.state.overlayStyle), E))),
|
||||
S
|
||||
? ((I = u({}, i)), (N = u({}, c)))
|
||||
: ((I = u({}, f(f({}, this.state.buttonStyle), i))),
|
||||
(N = u({}, f(f({}, this.state.declineButtonStyle), c))))),
|
||||
n)
|
||||
? ((N = u({}, i)), (R = u({}, c)))
|
||||
: ((N = u({}, f(f({}, this.state.buttonStyle), i))),
|
||||
(R = u({}, f(f({}, this.state.declineButtonStyle), c))))),
|
||||
o)
|
||||
) {
|
||||
case h.TOP:
|
||||
E.top = "0";
|
||||
A.top = "0";
|
||||
break;
|
||||
case h.BOTTOM:
|
||||
E.bottom = "0";
|
||||
A.bottom = "0";
|
||||
}
|
||||
var A = [];
|
||||
var U = [];
|
||||
return (
|
||||
C &&
|
||||
A.push(
|
||||
r().createElement(
|
||||
k &&
|
||||
U.push(
|
||||
t().createElement(
|
||||
j,
|
||||
{
|
||||
key: "declineButton",
|
||||
style: N,
|
||||
className: O,
|
||||
style: R,
|
||||
className: m,
|
||||
id: g,
|
||||
"aria-label": D,
|
||||
onClick: function () {
|
||||
@@ -366,39 +591,43 @@ module.exports = (function () {
|
||||
p
|
||||
)
|
||||
),
|
||||
A.push(
|
||||
r().createElement(
|
||||
U.push(
|
||||
t().createElement(
|
||||
j,
|
||||
{
|
||||
key: "acceptButton",
|
||||
style: I,
|
||||
className: d,
|
||||
id: m,
|
||||
style: N,
|
||||
className: y,
|
||||
id: O,
|
||||
"aria-label": P,
|
||||
onClick: function () {
|
||||
e.accept();
|
||||
},
|
||||
},
|
||||
l
|
||||
a
|
||||
)
|
||||
),
|
||||
x && A.reverse(),
|
||||
r().createElement(
|
||||
k,
|
||||
x && U.reverse(),
|
||||
t().createElement(
|
||||
w,
|
||||
{
|
||||
condition: T,
|
||||
wrapper: function (e) {
|
||||
return r().createElement("div", { style: R, className: w }, e);
|
||||
return t().createElement("div", { style: V, className: B }, e);
|
||||
},
|
||||
},
|
||||
r().createElement(
|
||||
t().createElement(
|
||||
"div",
|
||||
{ className: "".concat(b), style: E },
|
||||
r().createElement("div", { style: _, className: y }, this.props.children),
|
||||
r().createElement(
|
||||
u({ className: "".concat(b), style: A }, I),
|
||||
t().createElement(
|
||||
"div",
|
||||
u({ style: L, className: d }, _),
|
||||
this.props.children
|
||||
),
|
||||
t().createElement(
|
||||
"div",
|
||||
{ className: "".concat(v) },
|
||||
A.map(function (e) {
|
||||
U.map(function (e) {
|
||||
return e;
|
||||
})
|
||||
)
|
||||
@@ -407,66 +636,76 @@ module.exports = (function () {
|
||||
);
|
||||
},
|
||||
},
|
||||
]) && y(t.prototype, n),
|
||||
a
|
||||
]) && b(n.prototype, o),
|
||||
s
|
||||
);
|
||||
})(o.Component);
|
||||
(x.propTypes = {
|
||||
location: c().oneOf(
|
||||
})(e.Component);
|
||||
(T.propTypes = {
|
||||
location: i().oneOf(
|
||||
Object.keys(h).map(function (e) {
|
||||
return h[e];
|
||||
})
|
||||
),
|
||||
sameSite: c().oneOf(
|
||||
Object.keys(m).map(function (e) {
|
||||
return m[e];
|
||||
visible: i().oneOf(
|
||||
Object.keys(C).map(function (e) {
|
||||
return C[e];
|
||||
})
|
||||
),
|
||||
style: c().object,
|
||||
buttonStyle: c().object,
|
||||
declineButtonStyle: c().object,
|
||||
contentStyle: c().object,
|
||||
children: c().any,
|
||||
disableStyles: c().bool,
|
||||
hideOnAccept: c().bool,
|
||||
hideOnDecline: c().bool,
|
||||
onAccept: c().func,
|
||||
onDecline: c().func,
|
||||
buttonText: c().oneOfType([c().string, c().func, c().element]),
|
||||
declineButtonText: c().oneOfType([c().string, c().func, c().element]),
|
||||
cookieName: c().string,
|
||||
cookieValue: c().oneOfType([c().string, c().bool, c().number]),
|
||||
declineCookieValue: c().oneOfType([c().string, c().bool, c().number]),
|
||||
setDeclineCookie: c().bool,
|
||||
debug: c().bool,
|
||||
expires: c().number,
|
||||
containerClasses: c().string,
|
||||
contentClasses: c().string,
|
||||
buttonClasses: c().string,
|
||||
buttonWrapperClasses: c().string,
|
||||
declineButtonClasses: c().string,
|
||||
buttonId: c().string,
|
||||
declineButtonId: c().string,
|
||||
extraCookieOptions: c().object,
|
||||
disableButtonStyles: c().bool,
|
||||
enableDeclineButton: c().bool,
|
||||
flipButtons: c().bool,
|
||||
ButtonComponent: c().elementType,
|
||||
cookieSecurity: c().bool,
|
||||
overlay: c().bool,
|
||||
overlayClasses: c().string,
|
||||
overlayStyle: c().object,
|
||||
ariaAcceptLabel: c().string,
|
||||
ariaDeclineLabel: c().string,
|
||||
sameSite: i().oneOf(
|
||||
Object.keys(g).map(function (e) {
|
||||
return g[e];
|
||||
})
|
||||
),
|
||||
style: i().object,
|
||||
buttonStyle: i().object,
|
||||
declineButtonStyle: i().object,
|
||||
contentStyle: i().object,
|
||||
children: i().any,
|
||||
disableStyles: i().bool,
|
||||
hideOnAccept: i().bool,
|
||||
hideOnDecline: i().bool,
|
||||
onAccept: i().func,
|
||||
onDecline: i().func,
|
||||
buttonText: i().oneOfType([i().string, i().func, i().element]),
|
||||
declineButtonText: i().oneOfType([i().string, i().func, i().element]),
|
||||
cookieName: i().string,
|
||||
cookieValue: i().oneOfType([i().string, i().bool, i().number]),
|
||||
declineCookieValue: i().oneOfType([i().string, i().bool, i().number]),
|
||||
setDeclineCookie: i().bool,
|
||||
debug: i().bool,
|
||||
expires: i().number,
|
||||
containerClasses: i().string,
|
||||
contentClasses: i().string,
|
||||
buttonClasses: i().string,
|
||||
buttonWrapperClasses: i().string,
|
||||
declineButtonClasses: i().string,
|
||||
buttonId: i().string,
|
||||
declineButtonId: i().string,
|
||||
extraCookieOptions: i().object,
|
||||
disableButtonStyles: i().bool,
|
||||
enableDeclineButton: i().bool,
|
||||
flipButtons: i().bool,
|
||||
ButtonComponent: i().elementType,
|
||||
cookieSecurity: i().bool,
|
||||
overlay: i().bool,
|
||||
overlayClasses: i().string,
|
||||
overlayStyle: i().object,
|
||||
ariaAcceptLabel: i().string,
|
||||
ariaDeclineLabel: i().string,
|
||||
acceptOnScroll: i().bool,
|
||||
acceptOnScrollPercentage: i().number,
|
||||
customContentAttributes: i().object,
|
||||
customContainerAttributes: i().object,
|
||||
}),
|
||||
(x.defaultProps = {
|
||||
(T.defaultProps = {
|
||||
disableStyles: !1,
|
||||
hideOnAccept: !0,
|
||||
hideOnDecline: !0,
|
||||
location: h.BOTTOM,
|
||||
visible: C.BY_COOKIE_VALUE,
|
||||
onAccept: function () {},
|
||||
onDecline: function () {},
|
||||
cookieName: C,
|
||||
cookieName: j,
|
||||
cookieValue: !0,
|
||||
declineCookieValue: !1,
|
||||
setDeclineCookie: !0,
|
||||
@@ -485,10 +724,10 @@ module.exports = (function () {
|
||||
disableButtonStyles: !1,
|
||||
enableDeclineButton: !1,
|
||||
flipButtons: !1,
|
||||
sameSite: m.LAX,
|
||||
sameSite: g.LAX,
|
||||
ButtonComponent: function (e) {
|
||||
var t = e.children,
|
||||
n = (function (e, t) {
|
||||
var n = e.children,
|
||||
o = (function (e, t) {
|
||||
if (null == e) return {};
|
||||
var n,
|
||||
o,
|
||||
@@ -509,184 +748,21 @@ module.exports = (function () {
|
||||
(Object.prototype.propertyIsEnumerable.call(e, n) && (r[n] = e[n]));
|
||||
}
|
||||
return r;
|
||||
})(e, ["children"]);
|
||||
return r().createElement("button", n, t);
|
||||
})(e, a);
|
||||
return t().createElement("button", o, n);
|
||||
},
|
||||
overlay: !1,
|
||||
overlayClasses: "",
|
||||
ariaAcceptLabel: "Accept cookies",
|
||||
ariaDeclineLabel: "Decline cookies",
|
||||
acceptOnScroll: !1,
|
||||
acceptOnScrollPercentage: 25,
|
||||
customContentAttributes: {},
|
||||
customContainerAttributes: {},
|
||||
});
|
||||
const j = x;
|
||||
},
|
||||
808: function (e, t, n) {
|
||||
var o, r, i;
|
||||
void 0 ===
|
||||
(r =
|
||||
"function" ==
|
||||
typeof (o = i = function () {
|
||||
function e() {
|
||||
for (var e = 0, t = {}; e < arguments.length; e++) {
|
||||
var n = arguments[e];
|
||||
for (var o in n) t[o] = n[o];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
function t(e) {
|
||||
return e.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
|
||||
}
|
||||
return (function n(o) {
|
||||
function r() {}
|
||||
function i(t, n, i) {
|
||||
if ("undefined" != typeof document) {
|
||||
"number" == typeof (i = e({ path: "/" }, r.defaults, i)).expires &&
|
||||
(i.expires = new Date(1 * new Date() + 864e5 * i.expires)),
|
||||
(i.expires = i.expires ? i.expires.toUTCString() : "");
|
||||
try {
|
||||
var c = JSON.stringify(n);
|
||||
/^[\{\[]/.test(c) && (n = c);
|
||||
} catch (e) {}
|
||||
(n = o.write
|
||||
? o.write(n, t)
|
||||
: encodeURIComponent(String(n)).replace(
|
||||
/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,
|
||||
decodeURIComponent
|
||||
)),
|
||||
(t = encodeURIComponent(String(t))
|
||||
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
|
||||
.replace(/[\(\)]/g, escape));
|
||||
var a = "";
|
||||
for (var s in i)
|
||||
i[s] && ((a += "; " + s), !0 !== i[s] && (a += "=" + i[s].split(";")[0]));
|
||||
return (document.cookie = t + "=" + n + a);
|
||||
}
|
||||
}
|
||||
function c(e, n) {
|
||||
if ("undefined" != typeof document) {
|
||||
for (
|
||||
var r = {}, i = document.cookie ? document.cookie.split("; ") : [], c = 0;
|
||||
c < i.length;
|
||||
c++
|
||||
) {
|
||||
var a = i[c].split("="),
|
||||
s = a.slice(1).join("=");
|
||||
n || '"' !== s.charAt(0) || (s = s.slice(1, -1));
|
||||
try {
|
||||
var l = t(a[0]);
|
||||
if (((s = (o.read || o)(s, l) || t(s)), n))
|
||||
try {
|
||||
s = JSON.parse(s);
|
||||
} catch (e) {}
|
||||
if (((r[l] = s), e === l)) break;
|
||||
} catch (e) {}
|
||||
}
|
||||
return e ? r[e] : r;
|
||||
}
|
||||
}
|
||||
return (
|
||||
(r.set = i),
|
||||
(r.get = function (e) {
|
||||
return c(e, !1);
|
||||
}),
|
||||
(r.getJSON = function (e) {
|
||||
return c(e, !0);
|
||||
}),
|
||||
(r.remove = function (t, n) {
|
||||
i(t, "", e(n, { expires: -1 }));
|
||||
}),
|
||||
(r.defaults = {}),
|
||||
(r.withConverter = n),
|
||||
r
|
||||
const B = T;
|
||||
})(),
|
||||
o
|
||||
);
|
||||
})(function () {});
|
||||
})
|
||||
? o.call(t, n, t, e)
|
||||
: o) || (e.exports = r),
|
||||
(e.exports = i());
|
||||
},
|
||||
703: function (e, t, n) {
|
||||
"use strict";
|
||||
var o = n(414);
|
||||
function r() {}
|
||||
function i() {}
|
||||
(i.resetWarningCache = r),
|
||||
(e.exports = function () {
|
||||
function e(e, t, n, r, i, c) {
|
||||
if (c !== o) {
|
||||
var a = new Error(
|
||||
"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types"
|
||||
);
|
||||
throw ((a.name = "Invariant Violation"), a);
|
||||
}
|
||||
}
|
||||
function t() {
|
||||
return e;
|
||||
}
|
||||
e.isRequired = e;
|
||||
var n = {
|
||||
array: e,
|
||||
bool: e,
|
||||
func: e,
|
||||
number: e,
|
||||
object: e,
|
||||
string: e,
|
||||
symbol: e,
|
||||
any: e,
|
||||
arrayOf: t,
|
||||
element: e,
|
||||
elementType: e,
|
||||
instanceOf: t,
|
||||
node: e,
|
||||
objectOf: t,
|
||||
oneOf: t,
|
||||
oneOfType: t,
|
||||
shape: t,
|
||||
exact: t,
|
||||
checkPropTypes: i,
|
||||
resetWarningCache: r,
|
||||
};
|
||||
return (n.PropTypes = n), n;
|
||||
});
|
||||
},
|
||||
697: function (e, t, n) {
|
||||
e.exports = n(703)();
|
||||
},
|
||||
414: function (e) {
|
||||
"use strict";
|
||||
e.exports = "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";
|
||||
},
|
||||
},
|
||||
t = {};
|
||||
function n(o) {
|
||||
if (t[o]) return t[o].exports;
|
||||
var r = (t[o] = { exports: {} });
|
||||
return e[o](r, r.exports, n), r.exports;
|
||||
}
|
||||
return (
|
||||
(n.n = function (e) {
|
||||
var t =
|
||||
e && e.__esModule
|
||||
? function () {
|
||||
return e.default;
|
||||
}
|
||||
: function () {
|
||||
return e;
|
||||
};
|
||||
return n.d(t, { a: t }), t;
|
||||
}),
|
||||
(n.d = function (e, t) {
|
||||
for (var o in t)
|
||||
n.o(t, o) && !n.o(e, o) && Object.defineProperty(e, o, { enumerable: !0, get: t[o] });
|
||||
}),
|
||||
(n.o = function (e, t) {
|
||||
return Object.prototype.hasOwnProperty.call(e, t);
|
||||
}),
|
||||
(n.r = function (e) {
|
||||
"undefined" != typeof Symbol &&
|
||||
Symbol.toStringTag &&
|
||||
Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }),
|
||||
Object.defineProperty(e, "__esModule", { value: !0 });
|
||||
}),
|
||||
n(866)
|
||||
);
|
||||
})();
|
||||
})();
|
||||
});
|
||||
|
1
example
Submodule
1
example
Submodule
Submodule example added at bff8dd76c5
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "react-cookie-consent",
|
||||
"version": "6.2.4",
|
||||
"version": "7.1.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"version": "6.2.4",
|
||||
"version": "7.1.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"js-cookie": "^2.2.1",
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"name": "Rick van Lieshout",
|
||||
"email": "info@rickvanlieshout.com"
|
||||
},
|
||||
"version": "6.2.4",
|
||||
"version": "7.1.1",
|
||||
"description": "A small, simple and customizable cookie consent bar for use in React applications.",
|
||||
"main": "build/index.js",
|
||||
"types": "build/index.d.ts",
|
||||
@@ -22,7 +22,7 @@
|
||||
"minor": "npm --no-git-tag-version version minor",
|
||||
"major": "npm --no-git-tag-version version major",
|
||||
"preversion": "grep \"\\[$npm_package_version\\]\" CHANGELOG.md > /dev/null || ( echo 'You need to add an entry in CHANGELOG.md for this version.' && false )",
|
||||
"release": "npm run build && git add -A && git tag $npm_package_version && git commit -m 'release $npm_package_version' && git push && git push --tags && npm publish",
|
||||
"release": "npm run build && git add -A && git tag $npm_package_version && git commit -m \"release $npm_package_version\" && git push && git push --tags && npm publish",
|
||||
"release-patch": "npm run patch && npm run release",
|
||||
"release-minor": "npm run minor && npm run release",
|
||||
"release-major": "npm run major && npm run release"
|
||||
|
16
src/index.d.ts
vendored
16
src/index.d.ts
vendored
@@ -4,6 +4,7 @@ import Cookies from "js-cookie";
|
||||
export interface CookieConsentProps {
|
||||
location?: "top" | "bottom" | "none";
|
||||
sameSite?: "strict" | "lax" | "none";
|
||||
visible?: "hidden" | "show" | "byCookieValue";
|
||||
cookieSecurity?: boolean;
|
||||
style?: object;
|
||||
buttonStyle?: object;
|
||||
@@ -41,6 +42,8 @@ export interface CookieConsentProps {
|
||||
ariaDeclineLabel?: string;
|
||||
acceptOnScroll?: boolean;
|
||||
acceptOnScrollPercentage?: number;
|
||||
customContentAttributes?: object;
|
||||
customContainerAttributes?: object;
|
||||
}
|
||||
|
||||
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {}
|
||||
@@ -53,4 +56,17 @@ export default class CookieConsent extends React.Component<CookieConsentProps, {
|
||||
*/
|
||||
export function getCookieConsentValue(name?: string): string;
|
||||
|
||||
/**
|
||||
* Reset the consent cookie
|
||||
* Remove the cookie on browser in order to allow user to change their consent
|
||||
* @param {*} name optional name of the cookie
|
||||
*/
|
||||
export function resetCookieConsentValue(name?: string);
|
||||
|
||||
/**
|
||||
* Get the legacy cookie name by the regular cookie name
|
||||
* @param {string} name of cookie to get
|
||||
*/
|
||||
export function getLegacyCookieName(name: string);
|
||||
|
||||
export { Cookies };
|
||||
|
35
src/index.js
35
src/index.js
@@ -14,6 +14,12 @@ export const SAME_SITE_OPTIONS = {
|
||||
NONE: "none",
|
||||
};
|
||||
|
||||
export const VISIBLE_OPTIONS = {
|
||||
HIDDEN: "hidden",
|
||||
SHOW: "show",
|
||||
BY_COOKIE_VALUE: "byCookieValue",
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the value of the consent cookie
|
||||
* Retrieves the regular value first and if not found the legacy one according
|
||||
@@ -30,6 +36,15 @@ export const getCookieConsentValue = (name = defaultCookieConsentName) => {
|
||||
return cookieValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the consent cookie
|
||||
* Remove the cookie on browser in order to allow user to change their consent
|
||||
* @param {*} name optional name of the cookie
|
||||
*/
|
||||
export const resetCookieConsentValue = (name = defaultCookieConsentName) => {
|
||||
Cookies.remove(name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the legacy cookie name by the regular cookie name
|
||||
* @param {string} name of cookie to get
|
||||
@@ -227,9 +242,17 @@ class CookieConsent extends Component {
|
||||
|
||||
render() {
|
||||
// If the bar shouldn't be visible don't render anything.
|
||||
switch (this.props.visible) {
|
||||
case VISIBLE_OPTIONS.HIDDEN:
|
||||
return null;
|
||||
case VISIBLE_OPTIONS.BY_COOKIE_VALUE:
|
||||
if (!this.state.visible) {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const {
|
||||
location,
|
||||
@@ -256,6 +279,8 @@ class CookieConsent extends Component {
|
||||
overlayStyle,
|
||||
ariaAcceptLabel,
|
||||
ariaDeclineLabel,
|
||||
customContainerAttributes,
|
||||
customContentAttributes,
|
||||
} = this.props;
|
||||
|
||||
let myStyle = {};
|
||||
@@ -349,8 +374,8 @@ class CookieConsent extends Component {
|
||||
</div>
|
||||
)}
|
||||
>
|
||||
<div className={`${containerClasses}`} style={myStyle}>
|
||||
<div style={myContentStyle} className={contentClasses}>
|
||||
<div className={`${containerClasses}`} style={myStyle} {...customContainerAttributes}>
|
||||
<div style={myContentStyle} className={contentClasses} {...customContentAttributes}>
|
||||
{this.props.children}
|
||||
</div>
|
||||
<div className={`${buttonWrapperClasses}`}>
|
||||
@@ -366,6 +391,7 @@ class CookieConsent extends Component {
|
||||
|
||||
CookieConsent.propTypes = {
|
||||
location: PropTypes.oneOf(Object.keys(OPTIONS).map((key) => OPTIONS[key])),
|
||||
visible: PropTypes.oneOf(Object.keys(VISIBLE_OPTIONS).map((key) => VISIBLE_OPTIONS[key])),
|
||||
sameSite: PropTypes.oneOf(Object.keys(SAME_SITE_OPTIONS).map((key) => SAME_SITE_OPTIONS[key])),
|
||||
style: PropTypes.object,
|
||||
buttonStyle: PropTypes.object,
|
||||
@@ -405,6 +431,8 @@ CookieConsent.propTypes = {
|
||||
ariaDeclineLabel: PropTypes.string,
|
||||
acceptOnScroll: PropTypes.bool,
|
||||
acceptOnScrollPercentage: PropTypes.number,
|
||||
customContentAttributes: PropTypes.object,
|
||||
customContainerAttributes: PropTypes.object,
|
||||
};
|
||||
|
||||
CookieConsent.defaultProps = {
|
||||
@@ -412,6 +440,7 @@ CookieConsent.defaultProps = {
|
||||
hideOnAccept: true,
|
||||
hideOnDecline: true,
|
||||
location: OPTIONS.BOTTOM,
|
||||
visible: VISIBLE_OPTIONS.BY_COOKIE_VALUE,
|
||||
onAccept: () => {},
|
||||
onDecline: () => {},
|
||||
cookieName: defaultCookieConsentName,
|
||||
@@ -441,6 +470,8 @@ CookieConsent.defaultProps = {
|
||||
ariaDeclineLabel: "Decline cookies",
|
||||
acceptOnScroll: false,
|
||||
acceptOnScrollPercentage: 25,
|
||||
customContentAttributes: {},
|
||||
customContainerAttributes: {},
|
||||
};
|
||||
|
||||
export default CookieConsent;
|
||||
|
@@ -6,17 +6,21 @@ module.exports = {
|
||||
output: {
|
||||
path: path.resolve(__dirname, "build"),
|
||||
filename: "index.js",
|
||||
libraryTarget: "commonjs2", // THIS IS THE MOST IMPORTANT LINE! :mindblow: I wasted more than 2 days until realize this was the line most important in all this guide.
|
||||
library: {
|
||||
name: "ReactCookieConsent",
|
||||
type: "umd",
|
||||
},
|
||||
environment: {
|
||||
arrowFunction: false, // the generated runtime-code should not use arrow functions
|
||||
},
|
||||
globalObject: `typeof self !== 'undefined' ? self : this`,
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
include: path.resolve(__dirname, "src"),
|
||||
exclude: /(node_modules|bower_components|build)/,
|
||||
exclude: /(node_modules|build)/,
|
||||
use: {
|
||||
loader: "babel-loader",
|
||||
options: {
|
||||
|
Reference in New Issue
Block a user