mirror of
https://github.com/Mastermindzh/react-cookie-consent.git
synced 2025-08-23 09:35:04 +02:00
Adding a cookieValue
prop (#24)
The PR will: * Add a new prop, `cookieValue`, to component and the README. This prop let's you defined the value of the cookie, instead of always defining the hardcoded value of `true`. This is useful when integrating cookies with other cookie consent banners which need to check the same cookie value. For example we use another consent banner along side this one (on a different sub-domain) which checks that the consent cookie is set to `allowed`. * Tidying up the props table spacing in the README file * Remove a few trailing white-spaces after component names and prop definition.
This commit is contained in:
10
src/index.js
10
src/index.js
@@ -89,14 +89,14 @@ class CookieConsent extends Component {
|
||||
* Set a persistent cookie
|
||||
*/
|
||||
accept() {
|
||||
const { cookieName, expires, hideOnAccept, onAccept, extraCookieOptions } = this.props;
|
||||
const { cookieName, cookieValue, expires, hideOnAccept, onAccept, extraCookieOptions } = this.props;
|
||||
|
||||
// fire onAccept
|
||||
onAccept();
|
||||
// remove listener if set
|
||||
window.removeEventListener("scroll", this.handleScroll);
|
||||
|
||||
Cookies.set(cookieName, true, { expires: expires, ...extraCookieOptions });
|
||||
Cookies.set(cookieName, cookieValue, { expires: expires, ...extraCookieOptions });
|
||||
|
||||
if (hideOnAccept) {
|
||||
this.setState({ visible: false });
|
||||
@@ -184,6 +184,11 @@ CookieConsent.propTypes = {
|
||||
PropTypes.element
|
||||
]),
|
||||
cookieName: PropTypes.string,
|
||||
cookieValue: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.bool,
|
||||
PropTypes.number
|
||||
]),
|
||||
debug: PropTypes.bool,
|
||||
expires: PropTypes.number,
|
||||
containerClasses: PropTypes.string,
|
||||
@@ -202,6 +207,7 @@ CookieConsent.defaultProps = {
|
||||
location: OPTIONS.BOTTOM,
|
||||
onAccept: () => { },
|
||||
cookieName: "CookieConsent",
|
||||
cookieValue: true,
|
||||
buttonText: "I understand",
|
||||
debug: false,
|
||||
expires: 365,
|
||||
|
Reference in New Issue
Block a user