mirror of
https://github.com/Mastermindzh/react-cookie-consent.git
synced 2025-01-20 18:41:44 +01:00
prettified the code
This commit is contained in:
parent
c82911c903
commit
3926fff424
67
src/index.js
67
src/index.js
@ -101,7 +101,14 @@ class CookieConsent extends Component {
|
|||||||
* Set a persistent accept cookie
|
* Set a persistent accept cookie
|
||||||
*/
|
*/
|
||||||
accept() {
|
accept() {
|
||||||
const { cookieName, cookieValue, expires, hideOnAccept, onAccept, extraCookieOptions } = this.props;
|
const {
|
||||||
|
cookieName,
|
||||||
|
cookieValue,
|
||||||
|
expires,
|
||||||
|
hideOnAccept,
|
||||||
|
onAccept,
|
||||||
|
extraCookieOptions
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
// fire onAccept
|
// fire onAccept
|
||||||
onAccept();
|
onAccept();
|
||||||
@ -120,7 +127,14 @@ class CookieConsent extends Component {
|
|||||||
* Set a persistent decline cookie
|
* Set a persistent decline cookie
|
||||||
*/
|
*/
|
||||||
decline() {
|
decline() {
|
||||||
const { cookieName, declineCookieValue, expires, hideOnDecline, onDecline, extraCookieOptions } = this.props;
|
const {
|
||||||
|
cookieName,
|
||||||
|
declineCookieValue,
|
||||||
|
expires,
|
||||||
|
hideOnDecline,
|
||||||
|
onDecline,
|
||||||
|
extraCookieOptions
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
// fire onDecline
|
// fire onDecline
|
||||||
onDecline();
|
onDecline();
|
||||||
@ -178,14 +192,16 @@ class CookieConsent extends Component {
|
|||||||
myContentStyle = Object.assign({}, { ...this.state.contentStyle, ...contentStyle });
|
myContentStyle = Object.assign({}, { ...this.state.contentStyle, ...contentStyle });
|
||||||
|
|
||||||
// switch to disable JUST the button styles
|
// switch to disable JUST the button styles
|
||||||
if(disableButtonStyles){
|
if (disableButtonStyles) {
|
||||||
myButtonStyle = Object.assign({}, buttonStyle);
|
myButtonStyle = Object.assign({}, buttonStyle);
|
||||||
myDeclineButtonStyle = Object.assign({}, declineButtonStyle);
|
myDeclineButtonStyle = Object.assign({}, declineButtonStyle);
|
||||||
}else{
|
} else {
|
||||||
myButtonStyle = Object.assign({}, { ...this.state.buttonStyle, ...buttonStyle });
|
myButtonStyle = Object.assign({}, { ...this.state.buttonStyle, ...buttonStyle });
|
||||||
myDeclineButtonStyle = Object.assign({}, { ...this.state.declineButtonStyle, ...declineButtonStyle });
|
myDeclineButtonStyle = Object.assign(
|
||||||
|
{},
|
||||||
|
{ ...this.state.declineButtonStyle, ...declineButtonStyle }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// syntactic sugar to enable user to easily select top / bottom
|
// syntactic sugar to enable user to easily select top / bottom
|
||||||
@ -216,7 +232,7 @@ class CookieConsent extends Component {
|
|||||||
>
|
>
|
||||||
{buttonText}
|
{buttonText}
|
||||||
</ButtonComponent>
|
</ButtonComponent>
|
||||||
{enableDeclineButton &&
|
{enableDeclineButton && (
|
||||||
<ButtonComponent
|
<ButtonComponent
|
||||||
style={myDeclineButtonStyle}
|
style={myDeclineButtonStyle}
|
||||||
className={declineButtonClasses}
|
className={declineButtonClasses}
|
||||||
@ -227,7 +243,7 @@ class CookieConsent extends Component {
|
|||||||
>
|
>
|
||||||
{declineButtonText}
|
{declineButtonText}
|
||||||
</ButtonComponent>
|
</ButtonComponent>
|
||||||
}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -245,27 +261,11 @@ CookieConsent.propTypes = {
|
|||||||
hideOnDecline: PropTypes.bool,
|
hideOnDecline: PropTypes.bool,
|
||||||
onAccept: PropTypes.func,
|
onAccept: PropTypes.func,
|
||||||
onDecline: PropTypes.func,
|
onDecline: PropTypes.func,
|
||||||
buttonText: PropTypes.oneOfType([
|
buttonText: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.element]),
|
||||||
PropTypes.string,
|
declineButtonText: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.element]),
|
||||||
PropTypes.func,
|
|
||||||
PropTypes.element
|
|
||||||
]),
|
|
||||||
declineButtonText: PropTypes.oneOfType([
|
|
||||||
PropTypes.string,
|
|
||||||
PropTypes.func,
|
|
||||||
PropTypes.element
|
|
||||||
]),
|
|
||||||
cookieName: PropTypes.string,
|
cookieName: PropTypes.string,
|
||||||
cookieValue: PropTypes.oneOfType([
|
cookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
||||||
PropTypes.string,
|
declineCookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
||||||
PropTypes.bool,
|
|
||||||
PropTypes.number
|
|
||||||
]),
|
|
||||||
declineCookieValue: PropTypes.oneOfType([
|
|
||||||
PropTypes.string,
|
|
||||||
PropTypes.bool,
|
|
||||||
PropTypes.number
|
|
||||||
]),
|
|
||||||
debug: PropTypes.bool,
|
debug: PropTypes.bool,
|
||||||
expires: PropTypes.number,
|
expires: PropTypes.number,
|
||||||
containerClasses: PropTypes.string,
|
containerClasses: PropTypes.string,
|
||||||
@ -279,10 +279,7 @@ CookieConsent.propTypes = {
|
|||||||
extraCookieOptions: PropTypes.object,
|
extraCookieOptions: PropTypes.object,
|
||||||
disableButtonStyles: PropTypes.bool,
|
disableButtonStyles: PropTypes.bool,
|
||||||
enableDeclineButton: PropTypes.bool,
|
enableDeclineButton: PropTypes.bool,
|
||||||
ButtonComponent: PropTypes.oneOfType([
|
ButtonComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element])
|
||||||
PropTypes.func,
|
|
||||||
PropTypes.element
|
|
||||||
]),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CookieConsent.defaultProps = {
|
CookieConsent.defaultProps = {
|
||||||
@ -292,8 +289,8 @@ CookieConsent.defaultProps = {
|
|||||||
acceptOnScroll: false,
|
acceptOnScroll: false,
|
||||||
acceptOnScrollPercentage: 25,
|
acceptOnScrollPercentage: 25,
|
||||||
location: OPTIONS.BOTTOM,
|
location: OPTIONS.BOTTOM,
|
||||||
onAccept: () => { },
|
onAccept: () => {},
|
||||||
onDecline: () => { },
|
onDecline: () => {},
|
||||||
cookieName: "CookieConsent",
|
cookieName: "CookieConsent",
|
||||||
cookieValue: true,
|
cookieValue: true,
|
||||||
declineCookieValue: false,
|
declineCookieValue: false,
|
||||||
@ -310,7 +307,7 @@ CookieConsent.defaultProps = {
|
|||||||
extraCookieOptions: {},
|
extraCookieOptions: {},
|
||||||
disableButtonStyles: false,
|
disableButtonStyles: false,
|
||||||
enableDeclineButton: false,
|
enableDeclineButton: false,
|
||||||
ButtonComponent: ({ children, ...props }) => <button {...props}>{children}</button>,
|
ButtonComponent: ({ children, ...props }) => <button {...props}>{children}</button>
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CookieConsent;
|
export default CookieConsent;
|
||||||
|
Loading…
Reference in New Issue
Block a user