buttonWrapper added, npm updates done, changelog added and formatting

This commit is contained in:
Rick van Lieshout 2020-05-10 11:32:06 +02:00
parent 62d607d813
commit d1a1c39ef6
6 changed files with 205 additions and 220 deletions

39
CHANGELOG.md Normal file
View File

@ -0,0 +1,39 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [4.0.0]
I decided to update react-cookie-consent to version 4 because this version has a
buttonWrapper which will break appearance. I consider appearance a major feature.
### Added
- Changelog :D
- A wrapper around the buttons so they always stay together. (still possible to
change with css using buttonWrapperClasses)
### Changed
- Default ids for the buttons (rcc stands for react-cookie-consent,
cookie-consent is blocked by some adblockers nowadays so I abbreviated it)
### Updated
#### dependencies
- js-cookie updated from `2.2.0` to `2.2.1`
#### peer dependencies
- react updated from `16.4.0` to `16.13.1`
#### development dependencies
- @types/js-cookie updated from `2.2.2` to `2.2.6`
- babel-cli updated from `6.24.1` to `6.26.0`
- babel-preset-env updated from `1.5.1` to `1.7.0`
- react updated from `16.8.6` to `16.13.1`

223
README.md
View File

@ -14,13 +14,13 @@ Example branch: https://github.com/Mastermindzh/react-cookie-consent/tree/exampl
## Installation ## Installation
``` shell ```shell
npm install react-cookie-consent npm install react-cookie-consent
``` ```
or use yarn: or use yarn:
``` shell ```shell
yarn add react-cookie-consent yarn add react-cookie-consent
``` ```
@ -28,39 +28,35 @@ yarn add react-cookie-consent
You can import the cookie bar like this: You can import the cookie bar like this:
``` js ```js
import CookieConsent from "react-cookie-consent"; import CookieConsent from "react-cookie-consent";
``` ```
If you want to set/remove cookies yourself you can optionally import `Cookies` (straight from js-cookie) like this: If you want to set/remove cookies yourself you can optionally import `Cookies` (straight from js-cookie) like this:
``` js ```js
import CookieConsent, { Cookies } from "react-cookie-consent"; import CookieConsent, { Cookies } from "react-cookie-consent";
``` ```
Then you can use the component anywhere in your React app like so: Then you can use the component anywhere in your React app like so:
```jsx ```jsx
<CookieConsent> <CookieConsent>This website uses cookies to enhance the user experience.</CookieConsent>
This website uses cookies to enhance the user experience.
</CookieConsent>
``` ```
You can optionally set some props like this (next chapter will show all props): You can optionally set some props like this (next chapter will show all props):
```js ```js
<CookieConsent <CookieConsent
location="bottom" location="bottom"
buttonText="Sure man!!" buttonText="Sure man!!"
cookieName="myAwesomeCookieName2" cookieName="myAwesomeCookieName2"
style={{ background: "#2B373B" }} style={{ background: "#2B373B" }}
buttonStyle={{ color: "#4e503b", fontSize: "13px" }} buttonStyle={{ color: "#4e503b", fontSize: "13px" }}
expires={150} expires={150}
> >
This website uses cookies to enhance the user experience.{" "} This website uses cookies to enhance the user experience.{" "}
<span style={{ fontSize: "10px" }}> <span style={{ fontSize: "10px" }}>This bit of text is smaller :O</span>
This bit of text is smaller :O
</span>
</CookieConsent> </CookieConsent>
``` ```
@ -68,75 +64,72 @@ One of the props (onAccept) is a function, this function will be called after th
```js ```js
<CookieConsent <CookieConsent
acceptOnScroll={true} acceptOnScroll={true}
onAccept={({ acceptedByScrolling }) => { onAccept={({ acceptedByScrolling }) => {
if (acceptedByScrolling) { if (acceptedByScrolling) {
// triggered if user scrolls past threshold // triggered if user scrolls past threshold
alert("Accept was triggered by user scrolling"); alert("Accept was triggered by user scrolling");
} else { } else {
alert("Accept was triggered by clicking the Accept button"); alert("Accept was triggered by clicking the Accept button");
} }
}} }}
> ></CookieConsent>
</CookieConsent>
``` ```
If the decline button is enabled then the (onDecline) prop function can be used, this function will be called after the user has clicked the decline button. You can enable the button and provide a function like so: If the decline button is enabled then the (onDecline) prop function can be used, this function will be called after the user has clicked the decline button. You can enable the button and provide a function like so:
```js ```js
<CookieConsent <CookieConsent
enableDeclineButton enableDeclineButton
onDecline={() => {alert("nay!")}} onDecline={() => {
> alert("nay!");
}}
</CookieConsent> ></CookieConsent>
``` ```
## Props ## Props
| Prop | Type | Default value | Description |
|---------------|:--------------------------------:|---------------|-------------------------------------------------------------------------------------------------------| | Prop | Type | Default value | Description |
| 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 | | 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. |
| disableStyles | boolean | false | If enabled the component will have no default style. (you can still supply style through props) | | children | string or React component | | Content to appear inside the bar |
| 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)| | disableStyles | boolean | false | If enabled the component will have no default style. (you can still supply style through props) |
| acceptOnScroll | boolean | false | Defines whether "accept" should be fired after the user scrolls a certain distance (see acceptOnScrollPercentage) | | 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) |
| acceptOnScrollPercentage | number | 25 | Percentage of the page height the user has to scroll to trigger the accept function if acceptOnScroll is enabled | | acceptOnScroll | boolean | false | Defines whether "accept" should be fired after the user scrolls a certain distance (see acceptOnScrollPercentage) |
| buttonText | string or React component | "I understand" | Text to appear on the button | | acceptOnScrollPercentage | number | 25 | Percentage of the page height the user has to scroll to trigger the accept function if acceptOnScroll is enabled |
| declineButtonText | string or React component | "I decline" | Text to appear on the decline button | | 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. | | declineButtonText | string or React component | "I decline" | Text to appear on the decline button |
| cookieValue | string or boolean or number | true | Value to be saved under the cookieName. | | cookieName | string | "CookieConsent" | Name of the cookie used to track whether the user has agreed. |
| declineCookieValue | string or boolean or number | false | Value to be saved under the cookieName when declined. | | cookieValue | string or boolean or number | true | Value to be saved under the cookieName. |
| setDeclineCookie | boolean | true | Whether to set a cookie when the user clicks "decline" | | declineCookieValue | string or boolean or number | false | Value to be saved under the cookieName when declined. |
| onAccept | function | `({ acceptedByScrolling }) => {}` | Function to be called after the accept button has been clicked. | | setDeclineCookie | boolean | true | Whether to set a cookie when the user clicks "decline" |
| onDecline | function | `() => {}` | Function to be called after the decline button has been clicked. | | onAccept | function | `({ acceptedByScrolling }) => {}` | Function to be called after the accept button has been clicked. |
| debug | boolean | undefined | Bar will be drawn regardless of cookie for debugging purposes. | | onDecline | function | `() => {}` | Function to be called after the decline button has been clicked. |
| expires | number | 365 | Number of days before the cookie expires. | | debug | boolean | undefined | Bar will be drawn regardless of cookie for debugging purposes. |
| extraCookieOptions | object | `{}` | Extra info (apart from expiry date) to add to the cookie| | expires | number | 365 | Number of days before the cookie expires. |
| containerClasses| string | "" | CSS classes to apply to the surrounding container | | extraCookieOptions | object | `{}` | Extra info (apart from expiry date) to add to the cookie |
| buttonClasses | string | "" | CSS classes to apply to the button | | containerClasses | string | "" | CSS classes to apply to the surrounding container |
| declineButtonClasses | string | "" | CSS classes to apply to the decline button | | buttonClasses | string | "" | CSS classes to apply to the button |
| buttonId | string | "" | Id to apply to the button | | buttonWrapperClasses | string | "" | CSS classes to apply to the div wrapping the buttons |
| declineButtonId | string | "" | Id to apply to the decline button | | declineButtonClasses | string | "" | CSS classes to apply to the decline button |
| contentClasses| string | "" | CSS classes to apply to the content | | buttonId | string | "" | Id to apply to the button |
| style | object | [look at source][style] | React styling object for the bar. | | declineButtonId | string | "" | Id to apply to the decline button |
| buttonStyle | object | [look at source][buttonStyle] | React styling object for the button. | | contentClasses | string | "" | CSS classes to apply to the content |
| declineButtonStyle | object | [look at source][declineButtonStyle] | React styling object for the decline button. | | style | object | [look at source][style] | React styling object for the bar. |
| contentStyle | object | [look at source][contentStyle] | React styling object for the content. | | buttonStyle | object | [look at source][buttonstyle] | React styling object for the button. |
| disableButtonStyles | boolean | false | If enabled the button will have no default style. (you can still supply style through props) | | declineButtonStyle | object | [look at source][declinebuttonstyle] | React styling object for the decline button. |
| enableDeclineButton | boolean | false | If enabled the decline button will be rendered | | contentStyle | object | [look at source][contentstyle] | React styling object for the content. |
| flipButtons | boolean | false | If enabled the accept and decline buttons will be flipped | | disableButtonStyles | boolean | false | If enabled the button will have no default style. (you can still supply style through props) |
| ButtonComponent | React component | button | React Component to render as a button. | enableDeclineButton | boolean | false | If enabled the decline button will be rendered |
| flipButtons | boolean | false | If enabled the accept and decline buttons will be flipped |
| ButtonComponent | React component | button | React Component to render as a button. |
## Debugging it ## Debugging it
Because the cookie consent bar will be hidden once accepted, you will have to set the prop `debug={true}` to evaluate styling changes: Because the cookie consent bar will be hidden once accepted, you will have to set the prop `debug={true}` to evaluate styling changes:
```js ```js
<CookieConsent <CookieConsent debug={true}></CookieConsent>
debug={true}
>
</CookieConsent>
``` ```
**Note:** Dont forget to remove the `debug`-property for production. **Note:** Dont forget to remove the `debug`-property for production.
@ -157,19 +150,13 @@ You can use `disableStyles={true}` to disable any built-in styling.
#### changing the bar background to red #### changing the bar background to red
```js ```js
<CookieConsent <CookieConsent style={{ background: "red" }}></CookieConsent>
style={{ background: "red" }}
>
</CookieConsent>
``` ```
#### changing the button font-weight to bold #### changing the button font-weight to bold
```js ```js
<CookieConsent <CookieConsent buttonStyle={{ fontWeight: "bold" }}></CookieConsent>
buttonStyle={{ fontWeight: "bold" }}
>
</CookieConsent>
``` ```
#### Using predefined CSS classes #### Using predefined CSS classes
@ -177,47 +164,45 @@ You can use `disableStyles={true}` to disable any built-in styling.
You can pass predefined CSS classes to the components using the `containerClasses`, `buttonClasses` and `contentClasses` props. The example below uses bootstrap classes: You can pass predefined CSS classes to the components using the `containerClasses`, `buttonClasses` and `contentClasses` props. The example below uses bootstrap classes:
```js ```js
<CookieConsent <CookieConsent
disableStyles={true} disableStyles={true}
location={OPTIONS.BOTTOM} location={OPTIONS.BOTTOM}
buttonClasses="btn btn-primary" buttonClasses="btn btn-primary"
containerClasses="alert alert-warning col-lg-12" containerClasses="alert alert-warning col-lg-12"
contentClasses="text-capitalize" contentClasses="text-capitalize"
> >
This website uses cookies to enhance the user experience.{" "} This website uses cookies to enhance the user experience.{" "}
<span style={{ fontSize: "10px" }}> <span style={{ fontSize: "10px" }}>This bit of text is smaller :O</span>
This bit of text is smaller :O </CookieConsent>
</span>
</CookieConsent>
``` ```
Which results in: Which results in:
![bootstrap styling](https://github.com/Mastermindzh/react-cookie-consent/blob/master/images/css_classes.png?raw=true) ![bootstrap styling](https://github.com/Mastermindzh/react-cookie-consent/blob/master/images/css_classes.png?raw=true)
#### Accept on scroll #### Accept on scroll
You can make the cookiebar disappear after scrolling a certain percentage using acceptOnScroll and acceptOnScrollPercentage. You can make the cookiebar disappear after scrolling a certain percentage using acceptOnScroll and acceptOnScrollPercentage.
```js ```js
<CookieConsent <CookieConsent
acceptOnScroll={true} acceptOnScroll={true}
acceptOnScrollPercentage={50} acceptOnScrollPercentage={50}
onAccept={() => {alert("consent given")}} onAccept={() => {
alert("consent given");
}}
> >
Hello scroller :) Hello scroller :)
</CookieConsent> </CookieConsent>
``` ```
#### Flipping the buttons #### Flipping the buttons
If you enable the decline button you can pass along the "flipButtons" property to turn the buttons around: If you enable the decline button you can pass along the "flipButtons" property to turn the buttons around:
```js ```js
<CookieConsent <CookieConsent enableDeclineButton flipButtons>
enableDeclineButton Flipped buttons
flipButtons
>
Flipped buttons
</CookieConsent> </CookieConsent>
``` ```
@ -226,14 +211,11 @@ Which results in:
![flipped buttons](./images/flipped.png) ![flipped buttons](./images/flipped.png)
#### Extra cookie options #### Extra cookie options
You can add more cookie options using the extraCookieOptions parameter like so: You can add more cookie options using the extraCookieOptions parameter like so:
```js ```js
<CookieConsent <CookieConsent extraCookieOptions={{ domain: "myexample.com" }}>cookie bar</CookieConsent>
extraCookieOptions={{domain: 'myexample.com'}}
>
cookie bar
</CookieConsent>
``` ```
#### rainbows! #### rainbows!
@ -244,23 +226,30 @@ If you're crazy enough you can even make a rainbow colored bar:
```js ```js
<CookieConsent <CookieConsent
buttonText="OMG DOUBLE RAINBOW" buttonText="OMG DOUBLE RAINBOW"
cookieName="myAwesomeCookieName2" cookieName="myAwesomeCookieName2"
style={{ background: "linear-gradient(to right, orange , yellow, green, cyan, blue, violet)", textShadow: "2px 2px black" }} style={{
buttonStyle={{background: "linear-gradient(to left, orange , yellow, green, cyan, blue, violet)", color:"white", fontWeight: "bolder", textShadow: "2px 2px black"}} background: "linear-gradient(to right, orange , yellow, green, cyan, blue, violet)",
textShadow: "2px 2px black",
}}
buttonStyle={{
background: "linear-gradient(to left, orange , yellow, green, cyan, blue, violet)",
color: "white",
fontWeight: "bolder",
textShadow: "2px 2px black",
}}
> >
This website uses cookies to enhance the user experience.{" "} This website uses cookies to enhance the user experience.{" "}
<span style={{ fontSize: "10px" }}> <span style={{ fontSize: "10px" }}>This bit of text is smaller :O</span>
This bit of text is smaller :O
</span>
</CookieConsent> </CookieConsent>
``` ```
<!-- links --> <!-- links -->
[style]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L18-L29 [style]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L18-L29
[buttonStyle]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L30-L40 [buttonstyle]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L30-L40
[declineButtonStyle]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L41-L51 [declinebuttonstyle]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L41-L51
[contentStyle]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L52-L55 [contentstyle]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L52-L55
## Projects using react-cookie-consent ## Projects using react-cookie-consent

2
build/index.d.ts vendored
View File

@ -32,7 +32,7 @@ export interface CookieConsentProps {
disableButtonStyles?: boolean; disableButtonStyles?: boolean;
enableDeclineButton?: boolean; enableDeclineButton?: boolean;
flipButtons?: boolean; flipButtons?: boolean;
ButtonComponent?: Function | React.ReactElement; ButtonComponent?: React.ElementType;
} }
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {} export default class CookieConsent extends React.Component<CookieConsentProps, {}> {}

View File

@ -725,6 +725,7 @@ var CookieConsent = function (_Component) {
containerClasses = _props4.containerClasses, containerClasses = _props4.containerClasses,
contentClasses = _props4.contentClasses, contentClasses = _props4.contentClasses,
buttonClasses = _props4.buttonClasses, buttonClasses = _props4.buttonClasses,
buttonWrapperClasses = _props4.buttonWrapperClasses,
declineButtonClasses = _props4.declineButtonClasses, declineButtonClasses = _props4.declineButtonClasses,
buttonId = _props4.buttonId, buttonId = _props4.buttonId,
declineButtonId = _props4.declineButtonId, declineButtonId = _props4.declineButtonId,
@ -809,15 +810,19 @@ var CookieConsent = function (_Component) {
return _react2.default.createElement( return _react2.default.createElement(
"div", "div",
{ className: "cookieConsent " + containerClasses, style: myStyle }, { className: "" + containerClasses, style: myStyle },
_react2.default.createElement( _react2.default.createElement(
"div", "div",
{ style: myContentStyle, className: contentClasses }, { style: myContentStyle, className: contentClasses },
this.props.children this.props.children
), ),
buttonsToRender.map(function (button) { _react2.default.createElement(
return button; "div",
}) { className: "" + buttonWrapperClasses },
buttonsToRender.map(function (button) {
return button;
})
)
); );
} }
}]); }]);
@ -850,6 +855,7 @@ CookieConsent.propTypes = {
containerClasses: _propTypes2.default.string, containerClasses: _propTypes2.default.string,
contentClasses: _propTypes2.default.string, contentClasses: _propTypes2.default.string,
buttonClasses: _propTypes2.default.string, buttonClasses: _propTypes2.default.string,
buttonWrapperClasses: _propTypes2.default.string,
declineButtonClasses: _propTypes2.default.string, declineButtonClasses: _propTypes2.default.string,
buttonId: _propTypes2.default.string, buttonId: _propTypes2.default.string,
declineButtonId: _propTypes2.default.string, declineButtonId: _propTypes2.default.string,
@ -859,7 +865,7 @@ CookieConsent.propTypes = {
disableButtonStyles: _propTypes2.default.bool, disableButtonStyles: _propTypes2.default.bool,
enableDeclineButton: _propTypes2.default.bool, enableDeclineButton: _propTypes2.default.bool,
flipButtons: _propTypes2.default.bool, flipButtons: _propTypes2.default.bool,
ButtonComponent: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.element]) ButtonComponent: _propTypes2.default.elementType
}; };
CookieConsent.defaultProps = { CookieConsent.defaultProps = {
@ -882,9 +888,10 @@ CookieConsent.defaultProps = {
containerClasses: "", containerClasses: "",
contentClasses: "", contentClasses: "",
buttonClasses: "", buttonClasses: "",
buttonWrapperClasses: "",
declineButtonClasses: "", declineButtonClasses: "",
buttonId: "", buttonId: "rcc-confirm-button",
declineButtonId: "", declineButtonId: "rcc-decline-button",
extraCookieOptions: {}, extraCookieOptions: {},
disableButtonStyles: false, disableButtonStyles: false,
enableDeclineButton: false, enableDeclineButton: false,
@ -1786,7 +1793,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
/***/ (function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";
/* WEBPACK VAR INJECTION */(function(process) {/** @license React v16.12.0 /* WEBPACK VAR INJECTION */(function(process) {/** @license React v16.13.1
* react-is.development.js * react-is.development.js
* *
* Copyright (c) Facebook, Inc. and its affiliates. * Copyright (c) Facebook, Inc. and its affiliates.
@ -1803,8 +1810,6 @@ if (process.env.NODE_ENV !== "production") {
(function() { (function() {
'use strict'; 'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
// nor polyfill, then a plain number is used for performance. // nor polyfill, then a plain number is used for performance.
var hasSymbol = typeof Symbol === 'function' && Symbol.for; var hasSymbol = typeof Symbol === 'function' && Symbol.for;
@ -1824,70 +1829,16 @@ var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8; var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4; var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5; var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6; var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7; var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
function isValidElementType(type) { function isValidElementType(type) {
return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill. return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE); type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
} }
/**
* Forked from fbjs/warning:
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
*
* Only change is we use console.warn instead of console.error,
* and do nothing when 'console' is not supported.
* This really simplifies the code.
* ---
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var lowPriorityWarningWithoutStack = function () {};
{
var printWarning = function (format) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.warn(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
lowPriorityWarningWithoutStack = function (condition, format) {
if (format === undefined) {
throw new Error('`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (!condition) {
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
printWarning.apply(void 0, [format].concat(args));
}
};
}
var lowPriorityWarningWithoutStack$1 = lowPriorityWarningWithoutStack;
function typeOf(object) { function typeOf(object) {
if (typeof object === 'object' && object !== null) { if (typeof object === 'object' && object !== null) {
var $$typeof = object.$$typeof; var $$typeof = object.$$typeof;
@ -1948,8 +1899,9 @@ var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecat
function isAsyncMode(object) { function isAsyncMode(object) {
{ {
if (!hasWarnedAboutDeprecatedIsAsyncMode) { if (!hasWarnedAboutDeprecatedIsAsyncMode) {
hasWarnedAboutDeprecatedIsAsyncMode = true; hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
lowPriorityWarningWithoutStack$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
} }
} }
@ -1992,7 +1944,6 @@ function isSuspense(object) {
return typeOf(object) === REACT_SUSPENSE_TYPE; return typeOf(object) === REACT_SUSPENSE_TYPE;
} }
exports.typeOf = typeOf;
exports.AsyncMode = AsyncMode; exports.AsyncMode = AsyncMode;
exports.ConcurrentMode = ConcurrentMode; exports.ConcurrentMode = ConcurrentMode;
exports.ContextConsumer = ContextConsumer; exports.ContextConsumer = ContextConsumer;
@ -2006,7 +1957,6 @@ exports.Portal = Portal;
exports.Profiler = Profiler; exports.Profiler = Profiler;
exports.StrictMode = StrictMode; exports.StrictMode = StrictMode;
exports.Suspense = Suspense; exports.Suspense = Suspense;
exports.isValidElementType = isValidElementType;
exports.isAsyncMode = isAsyncMode; exports.isAsyncMode = isAsyncMode;
exports.isConcurrentMode = isConcurrentMode; exports.isConcurrentMode = isConcurrentMode;
exports.isContextConsumer = isContextConsumer; exports.isContextConsumer = isContextConsumer;
@ -2020,6 +1970,8 @@ exports.isPortal = isPortal;
exports.isProfiler = isProfiler; exports.isProfiler = isProfiler;
exports.isStrictMode = isStrictMode; exports.isStrictMode = isStrictMode;
exports.isSuspense = isSuspense; exports.isSuspense = isSuspense;
exports.isValidElementType = isValidElementType;
exports.typeOf = typeOf;
})(); })();
} }
@ -2030,7 +1982,7 @@ exports.isSuspense = isSuspense;
/***/ (function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";
/** @license React v16.12.0 /** @license React v16.13.1
* react-is.production.min.js * react-is.production.min.js
* *
* Copyright (c) Facebook, Inc. and its affiliates. * Copyright (c) Facebook, Inc. and its affiliates.
@ -2039,12 +1991,12 @@ exports.isSuspense = isSuspense;
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
Object.defineProperty(exports,"__esModule",{value:!0}); var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?
var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?Symbol.for("react.suspense_list"): Symbol.for("react.suspense_list"):60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.block"):60121,w=b?Symbol.for("react.fundamental"):60117,x=b?Symbol.for("react.responder"):60118,y=b?Symbol.for("react.scope"):60119;
60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.fundamental"):60117,w=b?Symbol.for("react.responder"):60118,x=b?Symbol.for("react.scope"):60119;function y(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case t:case r:case h:return a;default:return u}}case d:return u}}}function z(a){return y(a)===m} function z(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case t:case r:case h:return a;default:return u}}case d:return u}}}function A(a){return z(a)===m}exports.AsyncMode=l;exports.ConcurrentMode=m;exports.ContextConsumer=k;exports.ContextProvider=h;exports.Element=c;exports.ForwardRef=n;exports.Fragment=e;exports.Lazy=t;exports.Memo=r;exports.Portal=d;
exports.typeOf=y;exports.AsyncMode=l;exports.ConcurrentMode=m;exports.ContextConsumer=k;exports.ContextProvider=h;exports.Element=c;exports.ForwardRef=n;exports.Fragment=e;exports.Lazy=t;exports.Memo=r;exports.Portal=d;exports.Profiler=g;exports.StrictMode=f;exports.Suspense=p; exports.Profiler=g;exports.StrictMode=f;exports.Suspense=p;exports.isAsyncMode=function(a){return A(a)||z(a)===l};exports.isConcurrentMode=A;exports.isContextConsumer=function(a){return z(a)===k};exports.isContextProvider=function(a){return z(a)===h};exports.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===c};exports.isForwardRef=function(a){return z(a)===n};exports.isFragment=function(a){return z(a)===e};exports.isLazy=function(a){return z(a)===t};
exports.isValidElementType=function(a){return"string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n||a.$$typeof===v||a.$$typeof===w||a.$$typeof===x)};exports.isAsyncMode=function(a){return z(a)||y(a)===l};exports.isConcurrentMode=z;exports.isContextConsumer=function(a){return y(a)===k};exports.isContextProvider=function(a){return y(a)===h}; exports.isMemo=function(a){return z(a)===r};exports.isPortal=function(a){return z(a)===d};exports.isProfiler=function(a){return z(a)===g};exports.isStrictMode=function(a){return z(a)===f};exports.isSuspense=function(a){return z(a)===p};
exports.isElement=function(a){return"object"===typeof a&&null!==a&&a.$$typeof===c};exports.isForwardRef=function(a){return y(a)===n};exports.isFragment=function(a){return y(a)===e};exports.isLazy=function(a){return y(a)===t};exports.isMemo=function(a){return y(a)===r};exports.isPortal=function(a){return y(a)===d};exports.isProfiler=function(a){return y(a)===g};exports.isStrictMode=function(a){return y(a)===f};exports.isSuspense=function(a){return y(a)===p}; exports.isValidElementType=function(a){return"string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n||a.$$typeof===w||a.$$typeof===x||a.$$typeof===y||a.$$typeof===v)};exports.typeOf=z;
/***/ }) /***/ })

View File

@ -4,15 +4,15 @@
"name": "Rick van Lieshout", "name": "Rick van Lieshout",
"email": "info@rickvanlieshout.com" "email": "info@rickvanlieshout.com"
}, },
"version": "3.0.0", "version": "4.0.0",
"description": "A small, simple and customizable cookie consent bar for use in React applications.", "description": "A small, simple and customizable cookie consent bar for use in React applications.",
"main": "build/index.js", "main": "build/index.js",
"types": "build/index.d.ts", "types": "build/index.d.ts",
"dependencies": { "dependencies": {
"js-cookie": "^2.2.0" "js-cookie": "^2.2.1"
}, },
"peerDependencies": { "peerDependencies": {
"react": "^16.4.0" "react": "^16.13.1"
}, },
"scripts": { "scripts": {
"build": "webpack", "build": "webpack",
@ -40,18 +40,18 @@
}, },
"homepage": "https://github.com/Mastermindzh/react-cookie-consent#readme", "homepage": "https://github.com/Mastermindzh/react-cookie-consent#readme",
"devDependencies": { "devDependencies": {
"@types/js-cookie": "^2.2.2", "@types/js-cookie": "^2.2.6",
"babel-cli": "^6.24.1", "babel-cli": "^6.26.0",
"babel-core": "^6.26.3", "babel-core": "^6.26.3",
"babel-loader": "^7.1.4", "babel-loader": "^7.1.4",
"babel-plugin-transform-object-assign": "^6.22.0", "babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1", "babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.5.1", "babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1", "babel-preset-es2015": "^6.24.1",
"babel-preset-stage-1": "^6.24.1", "babel-preset-stage-1": "^6.24.1",
"copy-webpack-plugin": "^4.6.0", "copy-webpack-plugin": "^4.6.0",
"react": "^16.8.6", "react": "^16.13.1",
"webpack": "^2.6.1" "webpack": "^2.6.1"
} }
} }

View File

@ -5,7 +5,7 @@ import Cookies from "js-cookie";
export const OPTIONS = { export const OPTIONS = {
TOP: "top", TOP: "top",
BOTTOM: "bottom", BOTTOM: "bottom",
NONE: "none" NONE: "none",
}; };
class CookieConsent extends Component { class CookieConsent extends Component {
@ -25,7 +25,7 @@ class CookieConsent extends Component {
left: "0", left: "0",
position: "fixed", position: "fixed",
width: "100%", width: "100%",
zIndex: "999" zIndex: "999",
}, },
buttonStyle: { buttonStyle: {
background: "#ffd42d", background: "#ffd42d",
@ -36,7 +36,7 @@ class CookieConsent extends Component {
cursor: "pointer", cursor: "pointer",
flex: "0 0 auto", flex: "0 0 auto",
padding: "5px 10px", padding: "5px 10px",
margin: "15px" margin: "15px",
}, },
declineButtonStyle: { declineButtonStyle: {
background: "#c12a2a", background: "#c12a2a",
@ -47,12 +47,12 @@ class CookieConsent extends Component {
cursor: "pointer", cursor: "pointer",
flex: "0 0 auto", flex: "0 0 auto",
padding: "5px 10px", padding: "5px 10px",
margin: "15px" margin: "15px",
}, },
contentStyle: { contentStyle: {
flex: "1 0 300px", flex: "1 0 300px",
margin: "15px" margin: "15px",
} },
}; };
this.handleScroll = this.handleScroll.bind(this); this.handleScroll = this.handleScroll.bind(this);
@ -107,7 +107,7 @@ class CookieConsent extends Component {
expires, expires,
hideOnAccept, hideOnAccept,
onAccept, onAccept,
extraCookieOptions extraCookieOptions,
} = this.props; } = this.props;
// fire onAccept // fire onAccept
@ -134,7 +134,7 @@ class CookieConsent extends Component {
hideOnDecline, hideOnDecline,
onDecline, onDecline,
extraCookieOptions, extraCookieOptions,
setDeclineCookie setDeclineCookie,
} = this.props; } = this.props;
// fire onDecline // fire onDecline
@ -170,13 +170,14 @@ class CookieConsent extends Component {
containerClasses, containerClasses,
contentClasses, contentClasses,
buttonClasses, buttonClasses,
buttonWrapperClasses,
declineButtonClasses, declineButtonClasses,
buttonId, buttonId,
declineButtonId, declineButtonId,
disableButtonStyles, disableButtonStyles,
enableDeclineButton, enableDeclineButton,
flipButtons, flipButtons,
ButtonComponent ButtonComponent,
} = this.props; } = this.props;
let myStyle = {}; let myStyle = {};
@ -257,20 +258,22 @@ class CookieConsent extends Component {
} }
return ( return (
<div className={`cookieConsent ${containerClasses}`} style={myStyle}> <div className={`${containerClasses}`} style={myStyle}>
<div style={myContentStyle} className={contentClasses}> <div style={myContentStyle} className={contentClasses}>
{this.props.children} {this.props.children}
</div> </div>
{buttonsToRender.map(button => { <div className={`${buttonWrapperClasses}`}>
return button; {buttonsToRender.map((button) => {
})} return button;
})}
</div>
</div> </div>
); );
} }
} }
CookieConsent.propTypes = { CookieConsent.propTypes = {
location: PropTypes.oneOf(Object.keys(OPTIONS).map(key => OPTIONS[key])), location: PropTypes.oneOf(Object.keys(OPTIONS).map((key) => OPTIONS[key])),
style: PropTypes.object, style: PropTypes.object,
buttonStyle: PropTypes.object, buttonStyle: PropTypes.object,
declineButtonStyle: PropTypes.object, declineButtonStyle: PropTypes.object,
@ -292,6 +295,7 @@ CookieConsent.propTypes = {
containerClasses: PropTypes.string, containerClasses: PropTypes.string,
contentClasses: PropTypes.string, contentClasses: PropTypes.string,
buttonClasses: PropTypes.string, buttonClasses: PropTypes.string,
buttonWrapperClasses: PropTypes.string,
declineButtonClasses: PropTypes.string, declineButtonClasses: PropTypes.string,
buttonId: PropTypes.string, buttonId: PropTypes.string,
declineButtonId: PropTypes.string, declineButtonId: PropTypes.string,
@ -301,7 +305,7 @@ CookieConsent.propTypes = {
disableButtonStyles: PropTypes.bool, disableButtonStyles: PropTypes.bool,
enableDeclineButton: PropTypes.bool, enableDeclineButton: PropTypes.bool,
flipButtons: PropTypes.bool, flipButtons: PropTypes.bool,
ButtonComponent: PropTypes.elementType ButtonComponent: PropTypes.elementType,
}; };
CookieConsent.defaultProps = { CookieConsent.defaultProps = {
@ -324,14 +328,15 @@ CookieConsent.defaultProps = {
containerClasses: "", containerClasses: "",
contentClasses: "", contentClasses: "",
buttonClasses: "", buttonClasses: "",
buttonWrapperClasses: "",
declineButtonClasses: "", declineButtonClasses: "",
buttonId: "", buttonId: "rcc-confirm-button",
declineButtonId: "", declineButtonId: "rcc-decline-button",
extraCookieOptions: {}, extraCookieOptions: {},
disableButtonStyles: false, disableButtonStyles: false,
enableDeclineButton: false, enableDeclineButton: false,
flipButtons: false, flipButtons: false,
ButtonComponent: ({ children, ...props }) => <button {...props}>{children}</button> ButtonComponent: ({ children, ...props }) => <button {...props}>{children}</button>,
}; };
export default CookieConsent; export default CookieConsent;