diff --git a/README.md b/README.md index 1c4174f..0f9d0b8 100644 --- a/README.md +++ b/README.md @@ -64,11 +64,19 @@ You can optionally set some props like this (next chapter will show all props): ``` -One of the props (onAccept) is a function, this function will be called after the user has clicked the accept button. You can provide a function like so: +One of the props (onAccept) is a function, this function will be called after the user has clicked the accept button. It is called with an object containing a boolean property `acceptedByScrolling` to indicate if the acceptance was triggered by the user scrolling. You can provide a function like so: ```js {alert("yay!")}} + acceptOnScroll={true} + onAccept={({ acceptedByScrolling }) => { + if (acceptedByScrolling) { + // triggered if user scrolls past threshold + alert("Accept was triggered by user scrolling"); + } else { + alert("Accept was triggered by clicking the Accept button"); + } + }} > @@ -100,7 +108,7 @@ If the decline button is enabled then the (onDecline) prop function can be used, | 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. | +| onAccept | function | `({ acceptedByScrolling }) => {}` | 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. | | expires | number | 365 | Number of days before the cookie expires. | diff --git a/build/index.d.ts b/build/index.d.ts index 5005c13..32c1ffe 100644 --- a/build/index.d.ts +++ b/build/index.d.ts @@ -10,7 +10,7 @@ export interface CookieConsentProps { children?: React.ReactNode; disableStyles?: boolean; hideOnAccept?: boolean; - onAccept?: Function; + onAccept?: ({ acceptedByScrolling }: { acceptedByScrolling?: boolean }) => void; onDecline?: Function; buttonText?: Function | React.ReactNode; declineButtonText?: Function | React.ReactNode; diff --git a/build/index.js b/build/index.js index b30e40a..979642f 100644 --- a/build/index.js +++ b/build/index.js @@ -296,14 +296,14 @@ if (process.env.NODE_ENV === 'production') { /***/ (function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! - * JavaScript Cookie v2.2.0 + * JavaScript Cookie v2.2.1 * https://github.com/js-cookie/js-cookie * * Copyright 2006, 2015 Klaus Hartl & Fagner Brack * Released under the MIT license */ ;(function (factory) { - var registeredInModuleLoader = false; + var registeredInModuleLoader; if (true) { !(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? @@ -337,126 +337,124 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! return result; } + function decode (s) { + return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent); + } + function init (converter) { - function api (key, value, attributes) { - var result; + function api() {} + + function set (key, value, attributes) { if (typeof document === 'undefined') { return; } - // Write + attributes = extend({ + path: '/' + }, api.defaults, attributes); - if (arguments.length > 1) { - attributes = extend({ - path: '/' - }, api.defaults, attributes); - - if (typeof attributes.expires === 'number') { - var expires = new Date(); - expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5); - attributes.expires = expires; - } - - // We're using "expires" because "max-age" is not supported by IE - attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; - - try { - result = JSON.stringify(value); - if (/^[\{\[]/.test(result)) { - value = result; - } - } catch (e) {} - - if (!converter.write) { - value = encodeURIComponent(String(value)) - .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); - } else { - value = converter.write(value, key); - } - - key = encodeURIComponent(String(key)); - key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); - key = key.replace(/[\(\)]/g, escape); - - var stringifiedAttributes = ''; - - for (var attributeName in attributes) { - if (!attributes[attributeName]) { - continue; - } - stringifiedAttributes += '; ' + attributeName; - if (attributes[attributeName] === true) { - continue; - } - stringifiedAttributes += '=' + attributes[attributeName]; - } - return (document.cookie = key + '=' + value + stringifiedAttributes); + if (typeof attributes.expires === 'number') { + attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5); } - // Read + // We're using "expires" because "max-age" is not supported by IE + attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; - if (!key) { - result = {}; + try { + var result = JSON.stringify(value); + if (/^[\{\[]/.test(result)) { + value = result; + } + } catch (e) {} + + value = converter.write ? + converter.write(value, key) : + encodeURIComponent(String(value)) + .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); + + key = encodeURIComponent(String(key)) + .replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent) + .replace(/[\(\)]/g, escape); + + var stringifiedAttributes = ''; + for (var attributeName in attributes) { + if (!attributes[attributeName]) { + continue; + } + stringifiedAttributes += '; ' + attributeName; + if (attributes[attributeName] === true) { + continue; + } + + // Considers RFC 6265 section 5.2: + // ... + // 3. If the remaining unparsed-attributes contains a %x3B (";") + // character: + // Consume the characters of the unparsed-attributes up to, + // not including, the first %x3B (";") character. + // ... + stringifiedAttributes += '=' + attributes[attributeName].split(';')[0]; } + return (document.cookie = key + '=' + value + stringifiedAttributes); + } + + function get (key, json) { + if (typeof document === 'undefined') { + return; + } + + var jar = {}; // To prevent the for loop in the first place assign an empty array - // in case there are no cookies at all. Also prevents odd result when - // calling "get()" + // in case there are no cookies at all. var cookies = document.cookie ? document.cookie.split('; ') : []; - var rdecode = /(%[0-9A-Z]{2})+/g; var i = 0; for (; i < cookies.length; i++) { var parts = cookies[i].split('='); var cookie = parts.slice(1).join('='); - if (!this.json && cookie.charAt(0) === '"') { + if (!json && cookie.charAt(0) === '"') { cookie = cookie.slice(1, -1); } try { - var name = parts[0].replace(rdecode, decodeURIComponent); - cookie = converter.read ? - converter.read(cookie, name) : converter(cookie, name) || - cookie.replace(rdecode, decodeURIComponent); + var name = decode(parts[0]); + cookie = (converter.read || converter)(cookie, name) || + decode(cookie); - if (this.json) { + if (json) { try { cookie = JSON.parse(cookie); } catch (e) {} } - if (key === name) { - result = cookie; - break; - } + jar[name] = cookie; - if (!key) { - result[name] = cookie; + if (key === name) { + break; } } catch (e) {} } - return result; + return key ? jar[key] : jar; } - api.set = api; + api.set = set; api.get = function (key) { - return api.call(api, key); + return get(key, false /* read as raw */); }; - api.getJSON = function () { - return api.apply({ - json: true - }, [].slice.call(arguments)); + api.getJSON = function (key) { + return get(key, true /* read as json */); }; - api.defaults = {}; - api.remove = function (key, attributes) { - api(key, '', extend(attributes, { + set(key, '', extend(attributes, { expires: -1 })); }; + api.defaults = {}; + api.withConverter = init; return api; @@ -639,7 +637,7 @@ var CookieConsent = function (_Component) { var percentage = (rootNode[top] || body[top]) / ((rootNode[height] || body[height]) - rootNode.clientHeight) * 100; if (percentage > this.props.acceptOnScrollPercentage) { - this.accept(); + this.accept({ acceptedByScrolling: true }); } } @@ -649,7 +647,9 @@ var CookieConsent = function (_Component) { }, { key: "accept", - value: function accept() { + value: function accept(_ref) { + var _ref$acceptedByScroll = _ref.acceptedByScrolling, + acceptedByScrolling = _ref$acceptedByScroll === undefined ? false : _ref$acceptedByScroll; var _props2 = this.props, cookieName = _props2.cookieName, cookieValue = _props2.cookieValue, @@ -660,7 +660,7 @@ var CookieConsent = function (_Component) { // fire onAccept - onAccept(); + onAccept({ acceptedByScrolling: acceptedByScrolling }); // remove listener if set window.removeEventListener("scroll", this.handleScroll); @@ -797,7 +797,7 @@ var CookieConsent = function (_Component) { className: buttonClasses, id: buttonId, onClick: function onClick() { - _this2.accept(); + _this2.accept({ acceptedByScrolling: false }); } }, buttonText @@ -889,9 +889,9 @@ CookieConsent.defaultProps = { disableButtonStyles: false, enableDeclineButton: false, flipButtons: false, - ButtonComponent: function ButtonComponent(_ref) { - var children = _ref.children, - props = _objectWithoutProperties(_ref, ["children"]); + ButtonComponent: function ButtonComponent(_ref2) { + var children = _ref2.children, + props = _objectWithoutProperties(_ref2, ["children"]); return _react2.default.createElement( "button", @@ -1786,7 +1786,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(process) {/** @license React v16.8.6 +/* WEBPACK VAR INJECTION */(function(process) {/** @license React v16.12.0 * react-is.development.js * * Copyright (c) Facebook, Inc. and its affiliates. @@ -1808,25 +1808,29 @@ Object.defineProperty(exports, '__esModule', { value: true }); // The Symbol used to tag the ReactElement-like types. If there is no native Symbol // nor polyfill, then a plain number is used for performance. var hasSymbol = typeof Symbol === 'function' && Symbol.for; - var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7; var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca; var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb; var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc; var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2; var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd; -var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; +var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary +// (unstable) APIs that have been removed. Can we remove the symbols? + var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf; var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf; var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1; +var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8; var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4; +var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5; +var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6; +var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7; function isValidElementType(type) { - return typeof type === 'string' || typeof type === 'function' || - // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill. - type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE); + return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill. + type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE); } /** @@ -1842,12 +1846,11 @@ function isValidElementType(type) { * paths. Removing the logging code for production environments will keep the * same logic and follow the same code paths. */ - -var lowPriorityWarning = function () {}; +var lowPriorityWarningWithoutStack = function () {}; { var printWarning = function (format) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } @@ -1855,9 +1858,11 @@ var lowPriorityWarning = function () {}; var message = 'Warning: ' + format.replace(/%s/g, function () { return args[argIndex++]; }); + if (typeof console !== 'undefined') { console.warn(message); } + try { // --- Welcome to debugging React --- // This error was thrown as a convenience so that you can use this stack @@ -1866,25 +1871,27 @@ var lowPriorityWarning = function () {}; } catch (x) {} }; - lowPriorityWarning = function (condition, format) { + lowPriorityWarningWithoutStack = function (condition, format) { if (format === undefined) { - throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument'); + throw new Error('`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument'); } + if (!condition) { - for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { + for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { args[_key2 - 2] = arguments[_key2]; } - printWarning.apply(undefined, [format].concat(args)); + printWarning.apply(void 0, [format].concat(args)); } }; } -var lowPriorityWarning$1 = lowPriorityWarning; +var lowPriorityWarningWithoutStack$1 = lowPriorityWarningWithoutStack; function typeOf(object) { if (typeof object === 'object' && object !== null) { var $$typeof = object.$$typeof; + switch ($$typeof) { case REACT_ELEMENT_TYPE: var type = object.type; @@ -1897,29 +1904,32 @@ function typeOf(object) { case REACT_STRICT_MODE_TYPE: case REACT_SUSPENSE_TYPE: return type; + default: var $$typeofType = type && type.$$typeof; switch ($$typeofType) { case REACT_CONTEXT_TYPE: case REACT_FORWARD_REF_TYPE: + case REACT_LAZY_TYPE: + case REACT_MEMO_TYPE: case REACT_PROVIDER_TYPE: return $$typeofType; + default: return $$typeof; } + } - case REACT_LAZY_TYPE: - case REACT_MEMO_TYPE: + case REACT_PORTAL_TYPE: return $$typeof; } } return undefined; -} +} // AsyncMode is deprecated along with isAsyncMode -// AsyncMode is deprecated along with isAsyncMode var AsyncMode = REACT_ASYNC_MODE_TYPE; var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE; var ContextConsumer = REACT_CONTEXT_TYPE; @@ -1933,17 +1943,16 @@ var Portal = REACT_PORTAL_TYPE; var Profiler = REACT_PROFILER_TYPE; var StrictMode = REACT_STRICT_MODE_TYPE; var Suspense = REACT_SUSPENSE_TYPE; +var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated -var hasWarnedAboutDeprecatedIsAsyncMode = false; - -// AsyncMode should be deprecated function isAsyncMode(object) { { if (!hasWarnedAboutDeprecatedIsAsyncMode) { hasWarnedAboutDeprecatedIsAsyncMode = true; - lowPriorityWarning$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.'); + lowPriorityWarningWithoutStack$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.'); } } + return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE; } function isConcurrentMode(object) { @@ -2021,7 +2030,7 @@ exports.isSuspense = isSuspense; /***/ (function(module, exports, __webpack_require__) { "use strict"; -/** @license React v16.8.6 +/** @license React v16.12.0 * react-is.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. @@ -2031,11 +2040,11 @@ exports.isSuspense = isSuspense; */ Object.defineProperty(exports,"__esModule",{value:!0}); -var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?Symbol.for("react.memo"): -60115,r=b?Symbol.for("react.lazy"):60116;function t(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case h:return a;default:return u}}case r:case q:case d:return u}}}function v(a){return t(a)===m}exports.typeOf=t;exports.AsyncMode=l;exports.ConcurrentMode=m;exports.ContextConsumer=k;exports.ContextProvider=h;exports.Element=c;exports.ForwardRef=n; -exports.Fragment=e;exports.Lazy=r;exports.Memo=q;exports.Portal=d;exports.Profiler=g;exports.StrictMode=f;exports.Suspense=p;exports.isValidElementType=function(a){return"string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||"object"===typeof a&&null!==a&&(a.$$typeof===r||a.$$typeof===q||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n)};exports.isAsyncMode=function(a){return v(a)||t(a)===l};exports.isConcurrentMode=v;exports.isContextConsumer=function(a){return t(a)===k}; -exports.isContextProvider=function(a){return t(a)===h};exports.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===c};exports.isForwardRef=function(a){return t(a)===n};exports.isFragment=function(a){return t(a)===e};exports.isLazy=function(a){return t(a)===r};exports.isMemo=function(a){return t(a)===q};exports.isPortal=function(a){return t(a)===d};exports.isProfiler=function(a){return t(a)===g};exports.isStrictMode=function(a){return t(a)===f}; -exports.isSuspense=function(a){return t(a)===p}; +var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?Symbol.for("react.suspense_list"): +60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.fundamental"):60117,w=b?Symbol.for("react.responder"):60118,x=b?Symbol.for("react.scope"):60119;function y(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case t:case r:case h:return a;default:return u}}case d:return u}}}function z(a){return y(a)===m} +exports.typeOf=y;exports.AsyncMode=l;exports.ConcurrentMode=m;exports.ContextConsumer=k;exports.ContextProvider=h;exports.Element=c;exports.ForwardRef=n;exports.Fragment=e;exports.Lazy=t;exports.Memo=r;exports.Portal=d;exports.Profiler=g;exports.StrictMode=f;exports.Suspense=p; +exports.isValidElementType=function(a){return"string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n||a.$$typeof===v||a.$$typeof===w||a.$$typeof===x)};exports.isAsyncMode=function(a){return z(a)||y(a)===l};exports.isConcurrentMode=z;exports.isContextConsumer=function(a){return y(a)===k};exports.isContextProvider=function(a){return y(a)===h}; +exports.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===c};exports.isForwardRef=function(a){return y(a)===n};exports.isFragment=function(a){return y(a)===e};exports.isLazy=function(a){return y(a)===t};exports.isMemo=function(a){return y(a)===r};exports.isPortal=function(a){return y(a)===d};exports.isProfiler=function(a){return y(a)===g};exports.isStrictMode=function(a){return y(a)===f};exports.isSuspense=function(a){return y(a)===p}; /***/ }) diff --git a/src/index.d.ts b/src/index.d.ts index 5005c13..32c1ffe 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -10,7 +10,7 @@ export interface CookieConsentProps { children?: React.ReactNode; disableStyles?: boolean; hideOnAccept?: boolean; - onAccept?: Function; + onAccept?: ({ acceptedByScrolling }: { acceptedByScrolling?: boolean }) => void; onDecline?: Function; buttonText?: Function | React.ReactNode; declineButtonText?: Function | React.ReactNode; diff --git a/src/index.js b/src/index.js index 1b6273a..b810bc7 100644 --- a/src/index.js +++ b/src/index.js @@ -93,14 +93,14 @@ class CookieConsent extends Component { 100; if (percentage > this.props.acceptOnScrollPercentage) { - this.accept(); + this.accept({ acceptedByScrolling: true }); } } /** * Set a persistent accept cookie */ - accept() { + accept({ acceptedByScrolling = false }) { const { cookieName, cookieValue, @@ -111,7 +111,7 @@ class CookieConsent extends Component { } = this.props; // fire onAccept - onAccept(); + onAccept({ acceptedByScrolling }); // remove listener if set window.removeEventListener("scroll", this.handleScroll); @@ -245,7 +245,7 @@ class CookieConsent extends Component { className={buttonClasses} id={buttonId} onClick={() => { - this.accept(); + this.accept({ acceptedByScrolling: false }); }} > {buttonText}