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:
Jo Wo
2018-09-27 15:22:13 +01:00
committed by Rick van Lieshout
parent b3d5470d8c
commit c5a2632ea3
2 changed files with 13 additions and 6 deletions

View File

@@ -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,