added the disableButtonStyles property

This commit is contained in:
2019-02-04 20:38:46 +01:00
parent e8d4dcab3e
commit 0a5e4ea440
6 changed files with 34 additions and 10 deletions

1
src/index.d.ts vendored
View File

@@ -22,6 +22,7 @@ export interface CookieConsentProps {
acceptOnScroll?: boolean;
acceptOnScrollPercentage?: number;
extraCookieOptions?: object;
disableButtonStyles ?: boolean;
}
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {}

View File

@@ -93,6 +93,7 @@ class CookieConsent extends Component {
// fire onAccept
onAccept();
// remove listener if set
window.removeEventListener("scroll", this.handleScroll);
@@ -120,6 +121,7 @@ class CookieConsent extends Component {
contentClasses,
buttonClasses,
buttonId,
disableButtonStyles
} = this.props;
let myStyle = {};
@@ -127,15 +129,22 @@ class CookieConsent extends Component {
let myContentStyle = {};
if (disableStyles) {
// if styles are disabled use the provided styles (or non)
// if styles are disabled use the provided styles (or none)
myStyle = Object.assign({}, style);
myButtonStyle = Object.assign({}, buttonStyle);
myContentStyle = Object.assign({}, contentStyle);
} else {
// if styles aren't disabled merge them with the styles that are provided (or use default styles)
myStyle = Object.assign({}, { ...this.state.style, ...style });
myButtonStyle = Object.assign({}, { ...this.state.buttonStyle, ...buttonStyle });
myContentStyle = Object.assign({}, { ...this.state.contentStyle, ...contentStyle });
// switch to disable JUST the button styles
if(disableButtonStyles){
myButtonStyle = Object.assign({}, buttonStyle);
}else{
myButtonStyle = Object.assign({}, { ...this.state.buttonStyle, ...buttonStyle });
}
}
// syntactic sugar to enable user to easily select top / bottom
@@ -199,7 +208,8 @@ CookieConsent.propTypes = {
buttonId: PropTypes.string,
acceptOnScroll: PropTypes.bool,
acceptOnScrollPercentage: PropTypes.number,
extraCookieOptions: PropTypes.object
extraCookieOptions: PropTypes.object,
disableButtonStyles: PropTypes.bool
};
CookieConsent.defaultProps = {
@@ -218,7 +228,8 @@ CookieConsent.defaultProps = {
contentClasses: "",
buttonClasses: "",
buttonId: "",
extraCookieOptions: {}
extraCookieOptions: {},
disableButtonStyles: false
};
export default CookieConsent;