react-cookie-consent
Advanced tools
Comparing version 6.1.0 to 6.2.0
@@ -9,5 +9,6 @@ /*! For license information please see index.js.LICENSE.txt */ | ||
Cookies: () => s(), | ||
OPTIONS: () => O, | ||
SAME_SITE_OPTIONS: () => v, | ||
default: () => S, | ||
OPTIONS: () => h, | ||
SAME_SITE_OPTIONS: () => m, | ||
default: () => j, | ||
getCookieConsentValue: () => g, | ||
}); | ||
@@ -63,3 +64,3 @@ const o = require("react"); | ||
? p(Object(n), !0).forEach(function (t) { | ||
y(e, t, n[t]); | ||
b(e, t, n[t]); | ||
}) | ||
@@ -74,3 +75,3 @@ : Object.getOwnPropertyDescriptors | ||
} | ||
function y(e, t, n) { | ||
function b(e, t, n) { | ||
return ( | ||
@@ -88,3 +89,3 @@ t in e | ||
} | ||
function b(e, t) { | ||
function y(e, t) { | ||
for (var n = 0; n < t.length; n++) { | ||
@@ -105,3 +106,3 @@ var o = t[n]; | ||
} | ||
function m(e, t) { | ||
function v(e, t) { | ||
return !t || ("object" !== l(t) && "function" != typeof t) | ||
@@ -117,4 +118,4 @@ ? (function (e) { | ||
} | ||
function h(e) { | ||
return (h = Object.setPrototypeOf | ||
function O(e) { | ||
return (O = Object.setPrototypeOf | ||
? Object.getPrototypeOf | ||
@@ -125,5 +126,14 @@ : function (e) { | ||
} | ||
var O = { TOP: "top", BOTTOM: "bottom", NONE: "none" }, | ||
v = { STRICT: "strict", LAX: "lax", NONE: "none" }, | ||
g = function (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; | ||
}, | ||
S = function (e) { | ||
return "".concat(e, "-legacy"); | ||
}, | ||
C = "CookieConsent", | ||
k = function (e) { | ||
var t = e.condition, | ||
@@ -134,3 +144,3 @@ n = e.wrapper, | ||
}, | ||
C = (function (e) { | ||
x = (function (e) { | ||
!(function (e, t) { | ||
@@ -164,8 +174,8 @@ if ("function" != typeof t && null !== t) | ||
var e, | ||
t = h(o); | ||
t = O(o); | ||
if (i) { | ||
var n = h(this).constructor; | ||
var n = O(this).constructor; | ||
e = Reflect.construct(t, arguments, n); | ||
} else e = t.apply(this, arguments); | ||
return m(this, e); | ||
return v(this, e); | ||
}); | ||
@@ -263,8 +273,2 @@ function a(e) { | ||
{ | ||
key: "getLegacyCookieName", | ||
value: function (e) { | ||
return "".concat(e, "-legacy"); | ||
}, | ||
}, | ||
{ | ||
key: "setCookie", | ||
@@ -279,3 +283,3 @@ value: function (e, t) { | ||
var a = f(f({ expires: r }, o), {}, { sameSite: i, secure: c }); | ||
i === v.NONE && s().set(this.getLegacyCookieName(e), t, a), s().set(e, t, a); | ||
i === m.NONE && s().set(S(e), t, a), s().set(e, t, a); | ||
}, | ||
@@ -286,5 +290,4 @@ }, | ||
value: function () { | ||
var e = this.props.cookieName, | ||
t = s().get(e); | ||
return void 0 === t && (t = s().get(this.getLegacyCookieName(e))), t; | ||
var e = this.props.cookieName; | ||
return g(e); | ||
}, | ||
@@ -306,11 +309,11 @@ }, | ||
p = t.declineButtonText, | ||
y = t.containerClasses, | ||
b = t.contentClasses, | ||
b = t.containerClasses, | ||
y = t.contentClasses, | ||
d = t.buttonClasses, | ||
m = t.buttonWrapperClasses, | ||
h = t.declineButtonClasses, | ||
v = t.buttonId, | ||
C = t.declineButtonId, | ||
v = t.buttonWrapperClasses, | ||
O = t.declineButtonClasses, | ||
m = t.buttonId, | ||
g = t.declineButtonId, | ||
S = t.disableButtonStyles, | ||
k = t.enableDeclineButton, | ||
C = t.enableDeclineButton, | ||
x = t.flipButtons, | ||
@@ -324,4 +327,4 @@ j = t.ButtonComponent, | ||
E = {}, | ||
I = {}, | ||
N = {}, | ||
I = {}, | ||
_ = {}, | ||
@@ -332,4 +335,4 @@ R = {}; | ||
? ((E = u({}, o)), | ||
(N = u({}, i)), | ||
(I = u({}, c)), | ||
(I = u({}, i)), | ||
(N = u({}, c)), | ||
(_ = u({}, a)), | ||
@@ -341,11 +344,11 @@ (R = u({}, B))) | ||
S | ||
? ((N = u({}, i)), (I = u({}, c))) | ||
: ((N = u({}, f(f({}, this.state.buttonStyle), i))), | ||
(I = u({}, f(f({}, this.state.declineButtonStyle), c))))), | ||
? ((I = u({}, i)), (N = u({}, c))) | ||
: ((I = u({}, f(f({}, this.state.buttonStyle), i))), | ||
(N = u({}, f(f({}, this.state.declineButtonStyle), c))))), | ||
n) | ||
) { | ||
case O.TOP: | ||
case h.TOP: | ||
E.top = "0"; | ||
break; | ||
case O.BOTTOM: | ||
case h.BOTTOM: | ||
E.bottom = "0"; | ||
@@ -355,3 +358,3 @@ } | ||
return ( | ||
k && | ||
C && | ||
A.push( | ||
@@ -362,5 +365,5 @@ r().createElement( | ||
key: "declineButton", | ||
style: I, | ||
className: h, | ||
id: C, | ||
style: N, | ||
className: O, | ||
id: g, | ||
"aria-label": D, | ||
@@ -379,5 +382,5 @@ onClick: function () { | ||
key: "acceptButton", | ||
style: N, | ||
style: I, | ||
className: d, | ||
id: v, | ||
id: m, | ||
"aria-label": P, | ||
@@ -393,3 +396,3 @@ onClick: function () { | ||
r().createElement( | ||
g, | ||
k, | ||
{ | ||
@@ -403,7 +406,7 @@ condition: T, | ||
"div", | ||
{ className: "".concat(y), style: E }, | ||
r().createElement("div", { style: _, className: b }, this.props.children), | ||
{ className: "".concat(b), style: E }, | ||
r().createElement("div", { style: _, className: y }, this.props.children), | ||
r().createElement( | ||
"div", | ||
{ className: "".concat(m) }, | ||
{ className: "".concat(v) }, | ||
A.map(function (e) { | ||
@@ -418,15 +421,15 @@ return e; | ||
}, | ||
]) && b(t.prototype, n), | ||
]) && y(t.prototype, n), | ||
a | ||
); | ||
})(o.Component); | ||
(C.propTypes = { | ||
(x.propTypes = { | ||
location: c().oneOf( | ||
Object.keys(O).map(function (e) { | ||
return O[e]; | ||
Object.keys(h).map(function (e) { | ||
return h[e]; | ||
}) | ||
), | ||
sameSite: c().oneOf( | ||
Object.keys(v).map(function (e) { | ||
return v[e]; | ||
Object.keys(m).map(function (e) { | ||
return m[e]; | ||
}) | ||
@@ -471,10 +474,10 @@ ), | ||
}), | ||
(C.defaultProps = { | ||
(x.defaultProps = { | ||
disableStyles: !1, | ||
hideOnAccept: !0, | ||
hideOnDecline: !0, | ||
location: O.BOTTOM, | ||
location: h.BOTTOM, | ||
onAccept: function () {}, | ||
onDecline: function () {}, | ||
cookieName: "CookieConsent", | ||
cookieName: C, | ||
cookieValue: !0, | ||
@@ -498,3 +501,3 @@ declineCookieValue: !1, | ||
flipButtons: !1, | ||
sameSite: v.LAX, | ||
sameSite: m.LAX, | ||
ButtonComponent: function (e) { | ||
@@ -531,3 +534,3 @@ var t = e.children, | ||
}); | ||
const S = C; | ||
const j = x; | ||
}, | ||
@@ -534,0 +537,0 @@ 808: (e, t, n) => { |
@@ -8,2 +8,17 @@ # Changelog | ||
## [[6.2.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.2.0)] | ||
Added the exported function `getCookieConsentValue` to get the cookie value from custom code | ||
## [[6.1.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.1.0)] | ||
Added support for React 17 | ||
## [[6.0.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.0.0)] | ||
### removed | ||
Accepting by scrolling is no longer allowed and has thus been removed from the package. | ||
For details see [issue 88](https://github.com/Mastermindzh/react-cookie-consent/issues/88) | ||
## [[5.2.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/5.2.0)] | ||
@@ -10,0 +25,0 @@ |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"description": "A small, simple and customizable cookie consent bar for use in React applications.", | ||
@@ -25,3 +25,4 @@ "main": "build/index.js", | ||
"major": "npm --no-git-tag-version version major", | ||
"release": "npm run build && git add -A && PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag $PACKAGE_VERSION && git commit -m 'release $PACKAGE_VERSION' && git push && git push --tags && npm publish", | ||
"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-patch": "npm run patch && npm run release", | ||
@@ -28,0 +29,0 @@ "release-minor": "npm run minor && npm run release", |
@@ -25,3 +25,3 @@ # :cookie: react-cookie-consent :cookie: | ||
- [Debugging it](#debugging-it) | ||
- [Why are there two cookies? One of which named "Legacy"](#why-are-there-two-cookies--one-of-which-named--legacy-) | ||
- [Why are there two cookies? One of which named "Legacy"](#why-are-there-two-cookies-one-of-which-named-legacy) | ||
- [Styling it](#styling-it) | ||
@@ -109,2 +109,12 @@ - [Examples](#examples) | ||
### getting the cookies value in your own code | ||
react-cookie-consent exports a function called `getCookieConsentValue`. You can use it in your own code like so: | ||
```js | ||
import CookieConsent, { Cookies, getCookieConsentValue } from "react-cookie-consent"; | ||
console.log(getCookieConsentValue()); | ||
``` | ||
## Props | ||
@@ -111,0 +121,0 @@ |
@@ -18,2 +18,31 @@ import React, { Component } from "react"; | ||
/** | ||
* Returns the value of the consent cookie | ||
* Retrieves the regular value first and if not found the legacy one according | ||
* to: https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients | ||
* @param {*} name optional name of the cookie | ||
*/ | ||
export const getCookieConsentValue = (name = defaultCookieConsentName) => { | ||
let cookieValue = Cookies.get(name); | ||
// if the cookieValue is undefined check for the legacy cookie | ||
if (cookieValue === undefined) { | ||
cookieValue = Cookies.get(getLegacyCookieName(name)); | ||
} | ||
return cookieValue; | ||
}; | ||
/** | ||
* Get the legacy cookie name by the regular cookie name | ||
* @param {string} name of cookie to get | ||
*/ | ||
const getLegacyCookieName = (name) => { | ||
return `${name}-legacy`; | ||
}; | ||
/** | ||
* Default name of the cookie which is set by CookieConsent | ||
*/ | ||
const defaultCookieConsentName = "CookieConsent"; | ||
/** | ||
* A function to wrap elements with a "wrapper" on a condition | ||
@@ -133,10 +162,2 @@ * @param {object} wrappingOptions | ||
/** | ||
* Get the legacy cookie name by the regular cookie name | ||
* @param {string} name of cookie to get | ||
*/ | ||
getLegacyCookieName(name) { | ||
return `${name}-legacy`; | ||
} | ||
/** | ||
* Function to set the consent cookie based on the provided variables | ||
@@ -158,3 +179,3 @@ * Sets two cookies to handle incompatible browsers, more details: | ||
if (sameSite === SAME_SITE_OPTIONS.NONE) { | ||
Cookies.set(this.getLegacyCookieName(cookieName), cookieValue, cookieOptions); | ||
Cookies.set(getLegacyCookieName(cookieName), cookieValue, cookieOptions); | ||
} | ||
@@ -173,10 +194,3 @@ | ||
const { cookieName } = this.props; | ||
let cookieValue = Cookies.get(cookieName); | ||
// if the cookieValue is undefined check for the legacy cookie | ||
if (cookieValue === undefined) { | ||
cookieValue = Cookies.get(this.getLegacyCookieName(cookieName)); | ||
} | ||
return cookieValue; | ||
return getCookieConsentValue(cookieName); | ||
} | ||
@@ -371,3 +385,3 @@ | ||
onDecline: () => {}, | ||
cookieName: "CookieConsent", | ||
cookieName: defaultCookieConsentName, | ||
cookieValue: true, | ||
@@ -374,0 +388,0 @@ declineCookieValue: false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
163048
1157
316