mirror of
https://github.com/Mastermindzh/react-cookie-consent.git
synced 2025-08-23 17:44:55 +02:00
Update cookie value (#125)
* Chore: resetCookieConsentValue function * Chore: VISIBLE_OPTIONS enum & render update in order to use it * Readme review
This commit is contained in:
29
src/index.js
29
src/index.js
@@ -14,6 +14,12 @@ export const SAME_SITE_OPTIONS = {
|
||||
NONE: "none",
|
||||
};
|
||||
|
||||
export const VISIBLE_OPTIONS = {
|
||||
HIDDEN: 'hidden',
|
||||
SHOW: 'show',
|
||||
BY_COOKIE_VALUE: 'byCookieValue'
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the consent cookie
|
||||
* Retrieves the regular value first and if not found the legacy one according
|
||||
@@ -30,6 +36,15 @@ export const getCookieConsentValue = (name = defaultCookieConsentName) => {
|
||||
return cookieValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the consent cookie
|
||||
* Remove the cookie on browser in order to allow user to change their consent
|
||||
* @param {*} name optional name of the cookie
|
||||
*/
|
||||
export const resetCookieConsentValue = (name = defaultCookieConsentName) => {
|
||||
Cookies.remove(name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the legacy cookie name by the regular cookie name
|
||||
* @param {string} name of cookie to get
|
||||
@@ -227,8 +242,16 @@ class CookieConsent extends Component {
|
||||
|
||||
render() {
|
||||
// If the bar shouldn't be visible don't render anything.
|
||||
if (!this.state.visible) {
|
||||
return null;
|
||||
switch (this.props.visible) {
|
||||
case VISIBLE_OPTIONS.HIDDEN:
|
||||
return null;
|
||||
case VISIBLE_OPTIONS.BY_COOKIE_VALUE:
|
||||
if (!this.state.visible) {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const {
|
||||
@@ -366,6 +389,7 @@ class CookieConsent extends Component {
|
||||
|
||||
CookieConsent.propTypes = {
|
||||
location: PropTypes.oneOf(Object.keys(OPTIONS).map((key) => OPTIONS[key])),
|
||||
visible: PropTypes.oneOf(Object.keys(VISIBLE_OPTIONS).map((key) => VISIBLE_OPTIONS[key])),
|
||||
sameSite: PropTypes.oneOf(Object.keys(SAME_SITE_OPTIONS).map((key) => SAME_SITE_OPTIONS[key])),
|
||||
style: PropTypes.object,
|
||||
buttonStyle: PropTypes.object,
|
||||
@@ -412,6 +436,7 @@ CookieConsent.defaultProps = {
|
||||
hideOnAccept: true,
|
||||
hideOnDecline: true,
|
||||
location: OPTIONS.BOTTOM,
|
||||
visible: VISIBLE_OPTIONS.BY_COOKIE_VALUE,
|
||||
onAccept: () => {},
|
||||
onDecline: () => {},
|
||||
cookieName: defaultCookieConsentName,
|
||||
|
Reference in New Issue
Block a user