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. |
|
||||
| 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. |
|
||||
| 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. |
|
||||
| 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. |
|
||||
|
1
build/index.d.ts
vendored
1
build/index.d.ts
vendored
@ -17,6 +17,7 @@ export interface CookieConsentProps {
|
||||
cookieName?: string;
|
||||
cookieValue?: string | boolean | number;
|
||||
declineCookieValue?: string | boolean | number;
|
||||
setDeclineCookie?: PropTypes.bool;
|
||||
debug?: boolean;
|
||||
expires?: number;
|
||||
containerClasses?: string;
|
||||
|
@ -685,7 +685,8 @@ var CookieConsent = function (_Component) {
|
||||
expires = _props3.expires,
|
||||
hideOnDecline = _props3.hideOnDecline,
|
||||
onDecline = _props3.onDecline,
|
||||
extraCookieOptions = _props3.extraCookieOptions;
|
||||
extraCookieOptions = _props3.extraCookieOptions,
|
||||
setDeclineCookie = _props3.setDeclineCookie;
|
||||
|
||||
// fire onDecline
|
||||
|
||||
@ -694,7 +695,9 @@ var CookieConsent = function (_Component) {
|
||||
// remove listener if set
|
||||
window.removeEventListener("scroll", this.handleScroll);
|
||||
|
||||
if (setDeclineCookie) {
|
||||
_jsCookie2.default.set(cookieName, declineCookieValue, _extends({ expires: expires }, extraCookieOptions));
|
||||
}
|
||||
|
||||
if (hideOnDecline) {
|
||||
this.setState({ visible: false });
|
||||
@ -761,12 +764,10 @@ var CookieConsent = function (_Component) {
|
||||
switch (location) {
|
||||
case OPTIONS.TOP:
|
||||
myStyle.top = "0";
|
||||
myStyle.position = "fixed";
|
||||
break;
|
||||
|
||||
case OPTIONS.BOTTOM:
|
||||
myStyle.bottom = "0";
|
||||
myStyle.position = "fixed";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -843,6 +844,7 @@ CookieConsent.propTypes = {
|
||||
cookieName: _propTypes2.default.string,
|
||||
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]),
|
||||
setDeclineCookie: _propTypes2.default.bool,
|
||||
debug: _propTypes2.default.bool,
|
||||
expires: _propTypes2.default.number,
|
||||
containerClasses: _propTypes2.default.string,
|
||||
@ -872,6 +874,7 @@ CookieConsent.defaultProps = {
|
||||
cookieName: "CookieConsent",
|
||||
cookieValue: true,
|
||||
declineCookieValue: false,
|
||||
setDeclineCookie: true,
|
||||
buttonText: "I understand",
|
||||
declineButtonText: "I decline",
|
||||
debug: false,
|
||||
|
1
src/index.d.ts
vendored
1
src/index.d.ts
vendored
@ -17,6 +17,7 @@ export interface CookieConsentProps {
|
||||
cookieName?: string;
|
||||
cookieValue?: string | boolean | number;
|
||||
declineCookieValue?: string | boolean | number;
|
||||
setDeclineCookie?: PropTypes.bool;
|
||||
debug?: boolean;
|
||||
expires?: number;
|
||||
containerClasses?: string;
|
||||
|
@ -133,7 +133,8 @@ class CookieConsent extends Component {
|
||||
expires,
|
||||
hideOnDecline,
|
||||
onDecline,
|
||||
extraCookieOptions
|
||||
extraCookieOptions,
|
||||
setDeclineCookie
|
||||
} = this.props;
|
||||
|
||||
// fire onDecline
|
||||
@ -142,7 +143,9 @@ class CookieConsent extends Component {
|
||||
// remove listener if set
|
||||
window.removeEventListener("scroll", this.handleScroll);
|
||||
|
||||
if (setDeclineCookie) {
|
||||
Cookies.set(cookieName, declineCookieValue, { expires: expires, ...extraCookieOptions });
|
||||
}
|
||||
|
||||
if (hideOnDecline) {
|
||||
this.setState({ visible: false });
|
||||
@ -209,12 +212,10 @@ class CookieConsent extends Component {
|
||||
switch (location) {
|
||||
case OPTIONS.TOP:
|
||||
myStyle.top = "0";
|
||||
myStyle.position = "fixed";
|
||||
break;
|
||||
|
||||
case OPTIONS.BOTTOM:
|
||||
myStyle.bottom = "0";
|
||||
myStyle.position = "fixed";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -285,6 +286,7 @@ CookieConsent.propTypes = {
|
||||
cookieName: PropTypes.string,
|
||||
cookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
||||
declineCookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
||||
setDeclineCookie: PropTypes.bool,
|
||||
debug: PropTypes.bool,
|
||||
expires: PropTypes.number,
|
||||
containerClasses: PropTypes.string,
|
||||
@ -314,6 +316,7 @@ CookieConsent.defaultProps = {
|
||||
cookieName: "CookieConsent",
|
||||
cookieValue: true,
|
||||
declineCookieValue: false,
|
||||
setDeclineCookie: true,
|
||||
buttonText: "I understand",
|
||||
declineButtonText: "I decline",
|
||||
debug: false,
|
||||
|
Loading…
Reference in New Issue
Block a user