added an expires prop, idea inspired by aleplusplus (https://github.com/Mastermindzh/react-cookie-consent/pull/14)

This commit is contained in:
2018-06-07 10:09:05 +02:00
parent 869e0b1d13
commit 55f62ee575
4 changed files with 464 additions and 453 deletions

View File

@@ -56,9 +56,9 @@ class CookieConsent extends Component {
* Set a persistent cookie
*/
accept() {
const { cookieName } = this.props;
const { cookieName, expires } = this.props;
Cookies.set(cookieName, true);
Cookies.set(cookieName, true, { expires: expires });
this.setState({ visible: false });
}
@@ -132,7 +132,8 @@ CookieConsent.propTypes = {
onAccept: PropTypes.func,
buttonText: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.element]),
cookieName: PropTypes.string,
debug: PropTypes.bool
debug: PropTypes.bool,
expires: PropTypes.number
};
CookieConsent.defaultProps = {
@@ -141,7 +142,8 @@ CookieConsent.defaultProps = {
onAccept: () => {},
cookieName: "CookieConsent",
buttonText: "I understand",
debug: false
debug: false,
expires: 365
};
export default CookieConsent;