Auto hide (#19)

This commit is contained in:
Dimitris Fasoulas 2018-06-25 22:35:16 +02:00 committed by Rick van Lieshout
parent c5a4268624
commit 97133f2c80
3 changed files with 14 additions and 4 deletions

View File

@ -80,6 +80,7 @@ One of the props (onAccept) is a function, this function will be called after th
| location | string, "top", "bottom" or "none"| "bottom" | Syntactic sugar to easily enable you to place the bar at the top or the bottom of the browser window. Use "none" to disable. |
| children | string or React component | | Content to appear inside the bar |
| disableStyles | boolean | false | If enabled the component will have no default style. (you can still supply style through props) |
| hideOnAccept | boolean | true | If disabled the component will not hide it self after the accept button has been clicked. You will need to hide yourself (see onAccept)|
| buttonText | string or React component | "I understand" | Text to appear on the button |
| cookieName | string | "CookieConsent" | Name of the cookie used to track whether the user has agreed. |
| onAccept | function | `() => {}` | Function to be called after the accept button has been clicked. |

View File

@ -770,11 +770,14 @@ var CookieConsent = function (_Component) {
value: function accept() {
var _props2 = this.props,
cookieName = _props2.cookieName,
expires = _props2.expires;
expires = _props2.expires,
hideOnAccept = _props2.hideOnAccept;
_jsCookie2.default.set(cookieName, true, { expires: expires });
this.setState({ visible: false });
if (hideOnAccept) {
this.setState({ visible: false });
}
}
}, {
key: "render",
@ -862,6 +865,7 @@ CookieConsent.propTypes = {
contentStyle: _propTypes2.default.object,
children: _propTypes2.default.any, // eslint-disable-line react/forbid-prop-types
disableStyles: _propTypes2.default.bool,
hideOnAccept: _propTypes2.default.bool,
onAccept: _propTypes2.default.func,
buttonText: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func, _propTypes2.default.element]),
cookieName: _propTypes2.default.string,
@ -874,6 +878,7 @@ CookieConsent.propTypes = {
CookieConsent.defaultProps = {
disableStyles: false,
hideOnAccept: true,
location: OPTIONS.BOTTOM,
onAccept: function onAccept() {},
cookieName: "CookieConsent",

View File

@ -57,10 +57,12 @@ class CookieConsent extends Component {
* Set a persistent cookie
*/
accept() {
const { cookieName, expires } = this.props;
const { cookieName, expires, hideOnAccept } = this.props;
Cookies.set(cookieName, true, { expires: expires });
this.setState({ visible: false });
if (hideOnAccept) {
this.setState({ visible: false });
}
}
render() {
@ -138,6 +140,7 @@ CookieConsent.propTypes = {
contentStyle: PropTypes.object,
children: PropTypes.any, // eslint-disable-line react/forbid-prop-types
disableStyles: PropTypes.bool,
hideOnAccept: PropTypes.bool,
onAccept: PropTypes.func,
buttonText: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.element]),
cookieName: PropTypes.string,
@ -150,6 +153,7 @@ CookieConsent.propTypes = {
CookieConsent.defaultProps = {
disableStyles: false,
hideOnAccept: true,
location: OPTIONS.BOTTOM,
onAccept: () => {},
cookieName: "CookieConsent",