6 Commits
6.4.0 ... 7.1.0

Author SHA1 Message Date
eaaf6f8797 Added custom attribute props for content and container 2021-12-19 13:30:42 +01:00
8c86599f24 release 7.0.1 2021-12-11 11:13:55 +01:00
719bb2f496 Switch Library Type from CommonJs2 => UMD ( (#135)
Co-authored-by: Peter Krieg <pkrieg2@gmail.com>
2021-12-08 17:37:44 +01:00
9a0c974b2a release 6.4.1 2021-09-23 19:16:15 +02:00
c2f92ec130 added visible prop, and other missing items, to typings 2021-09-23 19:16:02 +02:00
7136086602 release 6.4.0 2021-09-17 18:25:41 +02:00
9 changed files with 813 additions and 712 deletions

View File

@@ -5,6 +5,26 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [[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))] ## [[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. - Added the (optional) scrolling effect back in as it is declared legal in some countries now.

View File

@@ -180,6 +180,10 @@ That option would be interesting if you want to allow user to change their conse
| acceptOnScroll | boolean | false | Defines whether "accept" should be fired after the user scrolls a certain distance (see acceptOnScrollPercentage) | | 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 | | 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 ## Debugging it
Because the cookie consent bar will be hidden once accepted, you will have to set the prop `debug={true}` to evaluate styling changes: Because the cookie consent bar will be hidden once accepted, you will have to set the prop `debug={true}` to evaluate styling changes:

14
build/index.d.ts vendored
View File

@@ -4,6 +4,7 @@ import Cookies from "js-cookie";
export interface CookieConsentProps { export interface CookieConsentProps {
location?: "top" | "bottom" | "none"; location?: "top" | "bottom" | "none";
sameSite?: "strict" | "lax" | "none"; sameSite?: "strict" | "lax" | "none";
visible?: "hidden" | "show" | "byCookieValue";
cookieSecurity?: boolean; cookieSecurity?: boolean;
style?: object; style?: object;
buttonStyle?: object; buttonStyle?: object;
@@ -53,4 +54,17 @@ export default class CookieConsent extends React.Component<CookieConsentProps, {
*/ */
export function getCookieConsentValue(name?: string): string; 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 }; export { Cookies };

View File

@@ -1,5 +1,14 @@
/*! For license information please see index.js.LICENSE.txt */ /*! For license information please see index.js.LICENSE.txt */
!(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 = { var e = {
808: function (e, t, n) { 808: function (e, t, n) {
var o, r, i; var o, r, i;
@@ -171,7 +180,8 @@
Object.defineProperty(e, "__esModule", { value: !0 }); Object.defineProperty(e, "__esModule", { value: !0 });
}); });
var o = {}; var o = {};
!(function () { return (
(function () {
"use strict"; "use strict";
n.r(o), n.r(o),
n.d(o, { n.d(o, {
@@ -179,16 +189,22 @@
return l(); return l();
}, },
OPTIONS: function () { OPTIONS: function () {
return O; return m;
}, },
SAME_SITE_OPTIONS: function () { SAME_SITE_OPTIONS: function () {
return g; return g;
}, },
VISIBLE_OPTIONS: function () {
return S;
},
default: function () { default: function () {
return w; return B;
}, },
getCookieConsentValue: function () { getCookieConsentValue: function () {
return S; return C;
},
resetCookieConsentValue: function () {
return k;
}, },
}); });
const e = require("react"); const e = require("react");
@@ -278,8 +294,8 @@
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
return e; return e;
} }
function m(e) { function O(e) {
return (m = Object.setPrototypeOf return (O = Object.setPrototypeOf
? Object.getPrototypeOf ? Object.getPrototypeOf
: function (e) { : function (e) {
return e.__proto__ || Object.getPrototypeOf(e); return e.__proto__ || Object.getPrototypeOf(e);
@@ -298,24 +314,29 @@
e e
); );
} }
var O = { TOP: "top", BOTTOM: "bottom", NONE: "none" }, var m = { TOP: "top", BOTTOM: "bottom", NONE: "none" },
g = { STRICT: "strict", LAX: "lax", NONE: "none" }, g = { STRICT: "strict", LAX: "lax", NONE: "none" },
S = function () { S = { HIDDEN: "hidden", SHOW: "show", BY_COOKIE_VALUE: "byCookieValue" },
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : k, C = function () {
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : j,
t = l().get(e); t = l().get(e);
return void 0 === t && (t = l().get(C(e))), t; return void 0 === t && (t = l().get(x(e))), t;
}, },
C = 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"); return "".concat(e, "-legacy");
}, },
k = "CookieConsent", j = "CookieConsent",
x = function (e) { w = function (e) {
var t = e.condition, var t = e.condition,
n = e.wrapper, n = e.wrapper,
o = e.children; o = e.children;
return t ? n(o) : o; return t ? n(o) : o;
}, },
j = (function (e) { T = (function (e) {
!(function (e, t) { !(function (e, t) {
if ("function" != typeof t && null !== t) if ("function" != typeof t && null !== t)
throw new TypeError("Super expression must either be null or a function"); throw new TypeError("Super expression must either be null or a function");
@@ -336,7 +357,10 @@
if ("function" == typeof Proxy) return !0; if ("function" == typeof Proxy) return !0;
try { try {
return ( return (
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})), !0 Boolean.prototype.valueOf.call(
Reflect.construct(Boolean, [], function () {})
),
!0
); );
} catch (e) { } catch (e) {
return !1; return !1;
@@ -344,9 +368,9 @@
})()), })()),
function () { function () {
var e, var e,
t = m(r); t = O(r);
if (i) { if (i) {
var n = m(this).constructor; var n = O(this).constructor;
e = Reflect.construct(t, arguments, n); e = Reflect.construct(t, arguments, n);
} else e = t.apply(this, arguments); } else e = t.apply(this, arguments);
return y(this, e); return y(this, e);
@@ -474,21 +498,26 @@
c = this.props.cookieSecurity; c = this.props.cookieSecurity;
void 0 === c && (c = !location || "https:" === location.protocol); void 0 === c && (c = !location || "https:" === location.protocol);
var a = f(f({ expires: r }, o), {}, { sameSite: i, secure: c }); var a = f(f({ expires: r }, o), {}, { sameSite: i, secure: c });
i === g.NONE && l().set(C(e), t, a), l().set(e, t, a); i === g.NONE && l().set(x(e), t, a), l().set(e, t, a);
}, },
}, },
{ {
key: "getCookieValue", key: "getCookieValue",
value: function () { value: function () {
var e = this.props.cookieName; var e = this.props.cookieName;
return S(e); return C(e);
}, },
}, },
{ {
key: "render", key: "render",
value: function () { value: function () {
var e = this; var e = this;
switch (this.props.visible) {
case S.HIDDEN:
return null;
case S.BY_COOKIE_VALUE:
if (!this.state.visible) return null; if (!this.state.visible) return null;
}
var n = this.props, var n = this.props,
o = n.location, o = n.location,
r = n.style, r = n.style,
@@ -502,57 +531,57 @@
b = n.contentClasses, b = n.contentClasses,
y = n.buttonClasses, y = n.buttonClasses,
v = n.buttonWrapperClasses, v = n.buttonWrapperClasses,
m = n.declineButtonClasses, O = n.declineButtonClasses,
h = n.buttonId, h = n.buttonId,
g = n.declineButtonId, g = n.declineButtonId,
S = n.disableButtonStyles, C = n.disableButtonStyles,
C = n.enableDeclineButton, k = n.enableDeclineButton,
k = n.flipButtons, x = n.flipButtons,
j = n.ButtonComponent, j = n.ButtonComponent,
w = n.overlay, T = n.overlay,
T = n.overlayClasses, B = n.overlayClasses,
B = n.overlayStyle, E = n.overlayStyle,
P = n.ariaAcceptLabel, P = n.ariaAcceptLabel,
E = n.ariaDeclineLabel, D = n.ariaDeclineLabel,
D = {},
I = {}, I = {},
N = {},
_ = {}, _ = {},
R = {}; N = {},
R = {},
A = {};
switch ( switch (
(a (a
? ((D = u({}, r)), ? ((I = u({}, r)),
(I = u({}, i)), (_ = u({}, i)),
(N = u({}, c)), (N = u({}, c)),
(_ = u({}, l)), (R = u({}, l)),
(R = u({}, B))) (A = u({}, E)))
: ((D = u({}, f(f({}, this.state.style), r))), : ((I = u({}, f(f({}, this.state.style), r))),
(_ = u({}, f(f({}, this.state.contentStyle), l))), (R = u({}, f(f({}, this.state.contentStyle), l))),
(R = u({}, f(f({}, this.state.overlayStyle), B))), (A = u({}, f(f({}, this.state.overlayStyle), E))),
S C
? ((I = u({}, i)), (N = u({}, c))) ? ((_ = u({}, i)), (N = u({}, c)))
: ((I = u({}, f(f({}, this.state.buttonStyle), i))), : ((_ = u({}, f(f({}, this.state.buttonStyle), i))),
(N = u({}, f(f({}, this.state.declineButtonStyle), c))))), (N = u({}, f(f({}, this.state.declineButtonStyle), c))))),
o) o)
) { ) {
case O.TOP: case m.TOP:
D.top = "0"; I.top = "0";
break; break;
case O.BOTTOM: case m.BOTTOM:
D.bottom = "0"; I.bottom = "0";
} }
var A = []; var L = [];
return ( return (
C && k &&
A.push( L.push(
t().createElement( t().createElement(
j, j,
{ {
key: "declineButton", key: "declineButton",
style: N, style: N,
className: m, className: O,
id: g, id: g,
"aria-label": E, "aria-label": D,
onClick: function () { onClick: function () {
e.decline(); e.decline();
}, },
@@ -560,12 +589,12 @@
p p
) )
), ),
A.push( L.push(
t().createElement( t().createElement(
j, j,
{ {
key: "acceptButton", key: "acceptButton",
style: I, style: _,
className: y, className: y,
id: h, id: h,
"aria-label": P, "aria-label": P,
@@ -576,23 +605,23 @@
s s
) )
), ),
k && A.reverse(), x && L.reverse(),
t().createElement( t().createElement(
x, w,
{ {
condition: w, condition: T,
wrapper: function (e) { wrapper: function (e) {
return t().createElement("div", { style: R, className: T }, e); return t().createElement("div", { style: A, className: B }, e);
}, },
}, },
t().createElement( t().createElement(
"div", "div",
{ className: "".concat(d), style: D }, { className: "".concat(d), style: I },
t().createElement("div", { style: _, className: b }, this.props.children), t().createElement("div", { style: R, className: b }, this.props.children),
t().createElement( t().createElement(
"div", "div",
{ className: "".concat(v) }, { className: "".concat(v) },
A.map(function (e) { L.map(function (e) {
return e; return e;
}) })
) )
@@ -605,10 +634,15 @@
a a
); );
})(e.Component); })(e.Component);
(j.propTypes = { (T.propTypes = {
location: i().oneOf( location: i().oneOf(
Object.keys(O).map(function (e) { Object.keys(m).map(function (e) {
return O[e]; return m[e];
})
),
visible: i().oneOf(
Object.keys(S).map(function (e) {
return S[e];
}) })
), ),
sameSite: i().oneOf( sameSite: i().oneOf(
@@ -655,14 +689,15 @@
acceptOnScroll: i().bool, acceptOnScroll: i().bool,
acceptOnScrollPercentage: i().number, acceptOnScrollPercentage: i().number,
}), }),
(j.defaultProps = { (T.defaultProps = {
disableStyles: !1, disableStyles: !1,
hideOnAccept: !0, hideOnAccept: !0,
hideOnDecline: !0, hideOnDecline: !0,
location: O.BOTTOM, location: m.BOTTOM,
visible: S.BY_COOKIE_VALUE,
onAccept: function () {}, onAccept: function () {},
onDecline: function () {}, onDecline: function () {},
cookieName: k, cookieName: j,
cookieValue: !0, cookieValue: !0,
declineCookieValue: !1, declineCookieValue: !1,
setDeclineCookie: !0, setDeclineCookie: !0,
@@ -715,7 +750,9 @@
acceptOnScroll: !1, acceptOnScroll: !1,
acceptOnScrollPercentage: 25, acceptOnScrollPercentage: 25,
}); });
const w = j; const B = T;
})(), })(),
(module.exports = o); o
);
})(); })();
});

4
package-lock.json generated
View File

@@ -1,11 +1,11 @@
{ {
"name": "react-cookie-consent", "name": "react-cookie-consent",
"version": "6.3.0", "version": "7.0.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"version": "6.3.0", "version": "7.0.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"js-cookie": "^2.2.1", "js-cookie": "^2.2.1",

View File

@@ -4,7 +4,7 @@
"name": "Rick van Lieshout", "name": "Rick van Lieshout",
"email": "info@rickvanlieshout.com" "email": "info@rickvanlieshout.com"
}, },
"version": "6.3.0", "version": "7.0.1",
"description": "A small, simple and customizable cookie consent bar for use in React applications.", "description": "A small, simple and customizable cookie consent bar for use in React applications.",
"main": "build/index.js", "main": "build/index.js",
"types": "build/index.d.ts", "types": "build/index.d.ts",

16
src/index.d.ts vendored
View File

@@ -4,6 +4,7 @@ import Cookies from "js-cookie";
export interface CookieConsentProps { export interface CookieConsentProps {
location?: "top" | "bottom" | "none"; location?: "top" | "bottom" | "none";
sameSite?: "strict" | "lax" | "none"; sameSite?: "strict" | "lax" | "none";
visible?: "hidden" | "show" | "byCookieValue";
cookieSecurity?: boolean; cookieSecurity?: boolean;
style?: object; style?: object;
buttonStyle?: object; buttonStyle?: object;
@@ -41,6 +42,8 @@ export interface CookieConsentProps {
ariaDeclineLabel?: string; ariaDeclineLabel?: string;
acceptOnScroll?: boolean; acceptOnScroll?: boolean;
acceptOnScrollPercentage?: number; acceptOnScrollPercentage?: number;
customContentAttributes: object;
customContainerAttributes: object;
} }
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {} 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; 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 }; export { Cookies };

View File

@@ -15,10 +15,10 @@ export const SAME_SITE_OPTIONS = {
}; };
export const VISIBLE_OPTIONS = { export const VISIBLE_OPTIONS = {
HIDDEN: 'hidden', HIDDEN: "hidden",
SHOW: 'show', SHOW: "show",
BY_COOKIE_VALUE: 'byCookieValue' BY_COOKIE_VALUE: "byCookieValue",
} };
/** /**
* Returns the value of the consent cookie * Returns the value of the consent cookie
@@ -279,6 +279,8 @@ class CookieConsent extends Component {
overlayStyle, overlayStyle,
ariaAcceptLabel, ariaAcceptLabel,
ariaDeclineLabel, ariaDeclineLabel,
customContainerAttributes,
customContentAttributes,
} = this.props; } = this.props;
let myStyle = {}; let myStyle = {};
@@ -372,8 +374,8 @@ class CookieConsent extends Component {
</div> </div>
)} )}
> >
<div className={`${containerClasses}`} style={myStyle}> <div className={`${containerClasses}`} style={myStyle} {...customContainerAttributes}>
<div style={myContentStyle} className={contentClasses}> <div style={myContentStyle} className={contentClasses} {...customContentAttributes}>
{this.props.children} {this.props.children}
</div> </div>
<div className={`${buttonWrapperClasses}`}> <div className={`${buttonWrapperClasses}`}>
@@ -429,6 +431,8 @@ CookieConsent.propTypes = {
ariaDeclineLabel: PropTypes.string, ariaDeclineLabel: PropTypes.string,
acceptOnScroll: PropTypes.bool, acceptOnScroll: PropTypes.bool,
acceptOnScrollPercentage: PropTypes.number, acceptOnScrollPercentage: PropTypes.number,
customContentAttributes: PropTypes.object,
customContainerAttributes: PropTypes.object,
}; };
CookieConsent.defaultProps = { CookieConsent.defaultProps = {
@@ -466,6 +470,8 @@ CookieConsent.defaultProps = {
ariaDeclineLabel: "Decline cookies", ariaDeclineLabel: "Decline cookies",
acceptOnScroll: false, acceptOnScroll: false,
acceptOnScrollPercentage: 25, acceptOnScrollPercentage: 25,
customContentAttributes: {},
customContainerAttributes: {},
}; };
export default CookieConsent; export default CookieConsent;

View File

@@ -6,17 +6,21 @@ module.exports = {
output: { output: {
path: path.resolve(__dirname, "build"), path: path.resolve(__dirname, "build"),
filename: "index.js", 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: { environment: {
arrowFunction: false, // the generated runtime-code should not use arrow functions arrowFunction: false, // the generated runtime-code should not use arrow functions
}, },
globalObject: `typeof self !== 'undefined' ? self : this`,
}, },
module: { module: {
rules: [ rules: [
{ {
test: /\.js$/, test: /\.js$/,
include: path.resolve(__dirname, "src"), include: path.resolve(__dirname, "src"),
exclude: /(node_modules|bower_components|build)/, exclude: /(node_modules|build)/,
use: { use: {
loader: "babel-loader", loader: "babel-loader",
options: { options: {