mirror of
https://github.com/Mastermindzh/react-cookie-consent.git
synced 2025-08-23 09:35:04 +02:00
Fix #56 - add acceptedByScrolling to onAccept
Checking the {acceptedByScrolling} boolean property will allow you to determine whether the acceptance was triggered by the user scrolling (if acceptedByScrolling=true) or explicitly clicking the Accept button (if acceptedByScrolling=false).
This commit is contained in:
2
src/index.d.ts
vendored
2
src/index.d.ts
vendored
@@ -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;
|
||||
|
@@ -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}
|
||||
|
Reference in New Issue
Block a user