mirror of
https://github.com/Mastermindzh/react-cookie-consent.git
synced 2025-01-20 18:41:44 +01:00
no longer setting position when location is passed.
added property "setDeclineCookie" to indicate whether a cookie has to be set on decline. fixes #45 fixes #46
This commit is contained in:
parent
ce0d7e2b0c
commit
1c3a54bd89
@ -99,6 +99,7 @@ If the decline button is enabled then the (onDecline) prop function can be used,
|
|||||||
| cookieName | string | "CookieConsent" | Name of the cookie used to track whether the user has agreed. |
|
| cookieName | string | "CookieConsent" | Name of the cookie used to track whether the user has agreed. |
|
||||||
| cookieValue | string or boolean or number | true | Value to be saved under the cookieName. |
|
| cookieValue | string or boolean or number | true | Value to be saved under the cookieName. |
|
||||||
| declineCookieValue | string or boolean or number | false | Value to be saved under the cookieName when declined. |
|
| declineCookieValue | string or boolean or number | false | Value to be saved under the cookieName when declined. |
|
||||||
|
| setDeclineCookie | boolean | true | Whether to set a cookie when the user clicks "decline" |
|
||||||
| onAccept | function | `() => {}` | Function to be called after the accept button has been clicked. |
|
| onAccept | function | `() => {}` | Function to be called after the accept button has been clicked. |
|
||||||
| onDecline | function | `() => {}` | Function to be called after the decline button has been clicked. |
|
| onDecline | function | `() => {}` | Function to be called after the decline button has been clicked. |
|
||||||
| debug | boolean | undefined | Bar will be drawn regardless of cookie for debugging purposes. |
|
| debug | boolean | undefined | Bar will be drawn regardless of cookie for debugging purposes. |
|
||||||
|
1
build/index.d.ts
vendored
1
build/index.d.ts
vendored
@ -17,6 +17,7 @@ export interface CookieConsentProps {
|
|||||||
cookieName?: string;
|
cookieName?: string;
|
||||||
cookieValue?: string | boolean | number;
|
cookieValue?: string | boolean | number;
|
||||||
declineCookieValue?: string | boolean | number;
|
declineCookieValue?: string | boolean | number;
|
||||||
|
setDeclineCookie?: PropTypes.bool;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
expires?: number;
|
expires?: number;
|
||||||
containerClasses?: string;
|
containerClasses?: string;
|
||||||
|
@ -685,7 +685,8 @@ var CookieConsent = function (_Component) {
|
|||||||
expires = _props3.expires,
|
expires = _props3.expires,
|
||||||
hideOnDecline = _props3.hideOnDecline,
|
hideOnDecline = _props3.hideOnDecline,
|
||||||
onDecline = _props3.onDecline,
|
onDecline = _props3.onDecline,
|
||||||
extraCookieOptions = _props3.extraCookieOptions;
|
extraCookieOptions = _props3.extraCookieOptions,
|
||||||
|
setDeclineCookie = _props3.setDeclineCookie;
|
||||||
|
|
||||||
// fire onDecline
|
// fire onDecline
|
||||||
|
|
||||||
@ -694,7 +695,9 @@ var CookieConsent = function (_Component) {
|
|||||||
// remove listener if set
|
// remove listener if set
|
||||||
window.removeEventListener("scroll", this.handleScroll);
|
window.removeEventListener("scroll", this.handleScroll);
|
||||||
|
|
||||||
_jsCookie2.default.set(cookieName, declineCookieValue, _extends({ expires: expires }, extraCookieOptions));
|
if (setDeclineCookie) {
|
||||||
|
_jsCookie2.default.set(cookieName, declineCookieValue, _extends({ expires: expires }, extraCookieOptions));
|
||||||
|
}
|
||||||
|
|
||||||
if (hideOnDecline) {
|
if (hideOnDecline) {
|
||||||
this.setState({ visible: false });
|
this.setState({ visible: false });
|
||||||
@ -761,12 +764,10 @@ var CookieConsent = function (_Component) {
|
|||||||
switch (location) {
|
switch (location) {
|
||||||
case OPTIONS.TOP:
|
case OPTIONS.TOP:
|
||||||
myStyle.top = "0";
|
myStyle.top = "0";
|
||||||
myStyle.position = "fixed";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPTIONS.BOTTOM:
|
case OPTIONS.BOTTOM:
|
||||||
myStyle.bottom = "0";
|
myStyle.bottom = "0";
|
||||||
myStyle.position = "fixed";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,6 +844,7 @@ CookieConsent.propTypes = {
|
|||||||
cookieName: _propTypes2.default.string,
|
cookieName: _propTypes2.default.string,
|
||||||
cookieValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.bool, _propTypes2.default.number]),
|
cookieValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.bool, _propTypes2.default.number]),
|
||||||
declineCookieValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.bool, _propTypes2.default.number]),
|
declineCookieValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.bool, _propTypes2.default.number]),
|
||||||
|
setDeclineCookie: _propTypes2.default.bool,
|
||||||
debug: _propTypes2.default.bool,
|
debug: _propTypes2.default.bool,
|
||||||
expires: _propTypes2.default.number,
|
expires: _propTypes2.default.number,
|
||||||
containerClasses: _propTypes2.default.string,
|
containerClasses: _propTypes2.default.string,
|
||||||
@ -872,6 +874,7 @@ CookieConsent.defaultProps = {
|
|||||||
cookieName: "CookieConsent",
|
cookieName: "CookieConsent",
|
||||||
cookieValue: true,
|
cookieValue: true,
|
||||||
declineCookieValue: false,
|
declineCookieValue: false,
|
||||||
|
setDeclineCookie: true,
|
||||||
buttonText: "I understand",
|
buttonText: "I understand",
|
||||||
declineButtonText: "I decline",
|
declineButtonText: "I decline",
|
||||||
debug: false,
|
debug: false,
|
||||||
|
1
src/index.d.ts
vendored
1
src/index.d.ts
vendored
@ -17,6 +17,7 @@ export interface CookieConsentProps {
|
|||||||
cookieName?: string;
|
cookieName?: string;
|
||||||
cookieValue?: string | boolean | number;
|
cookieValue?: string | boolean | number;
|
||||||
declineCookieValue?: string | boolean | number;
|
declineCookieValue?: string | boolean | number;
|
||||||
|
setDeclineCookie?: PropTypes.bool;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
expires?: number;
|
expires?: number;
|
||||||
containerClasses?: string;
|
containerClasses?: string;
|
||||||
|
11
src/index.js
11
src/index.js
@ -133,7 +133,8 @@ class CookieConsent extends Component {
|
|||||||
expires,
|
expires,
|
||||||
hideOnDecline,
|
hideOnDecline,
|
||||||
onDecline,
|
onDecline,
|
||||||
extraCookieOptions
|
extraCookieOptions,
|
||||||
|
setDeclineCookie
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
// fire onDecline
|
// fire onDecline
|
||||||
@ -142,7 +143,9 @@ class CookieConsent extends Component {
|
|||||||
// remove listener if set
|
// remove listener if set
|
||||||
window.removeEventListener("scroll", this.handleScroll);
|
window.removeEventListener("scroll", this.handleScroll);
|
||||||
|
|
||||||
Cookies.set(cookieName, declineCookieValue, { expires: expires, ...extraCookieOptions });
|
if (setDeclineCookie) {
|
||||||
|
Cookies.set(cookieName, declineCookieValue, { expires: expires, ...extraCookieOptions });
|
||||||
|
}
|
||||||
|
|
||||||
if (hideOnDecline) {
|
if (hideOnDecline) {
|
||||||
this.setState({ visible: false });
|
this.setState({ visible: false });
|
||||||
@ -209,12 +212,10 @@ class CookieConsent extends Component {
|
|||||||
switch (location) {
|
switch (location) {
|
||||||
case OPTIONS.TOP:
|
case OPTIONS.TOP:
|
||||||
myStyle.top = "0";
|
myStyle.top = "0";
|
||||||
myStyle.position = "fixed";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPTIONS.BOTTOM:
|
case OPTIONS.BOTTOM:
|
||||||
myStyle.bottom = "0";
|
myStyle.bottom = "0";
|
||||||
myStyle.position = "fixed";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,6 +286,7 @@ CookieConsent.propTypes = {
|
|||||||
cookieName: PropTypes.string,
|
cookieName: PropTypes.string,
|
||||||
cookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
cookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
||||||
declineCookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
declineCookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
||||||
|
setDeclineCookie: PropTypes.bool,
|
||||||
debug: PropTypes.bool,
|
debug: PropTypes.bool,
|
||||||
expires: PropTypes.number,
|
expires: PropTypes.number,
|
||||||
containerClasses: PropTypes.string,
|
containerClasses: PropTypes.string,
|
||||||
@ -314,6 +316,7 @@ CookieConsent.defaultProps = {
|
|||||||
cookieName: "CookieConsent",
|
cookieName: "CookieConsent",
|
||||||
cookieValue: true,
|
cookieValue: true,
|
||||||
declineCookieValue: false,
|
declineCookieValue: false,
|
||||||
|
setDeclineCookie: true,
|
||||||
buttonText: "I understand",
|
buttonText: "I understand",
|
||||||
declineButtonText: "I decline",
|
declineButtonText: "I decline",
|
||||||
debug: false,
|
debug: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user