mirror of
https://github.com/Mastermindzh/react-cookie-consent.git
synced 2025-01-20 18:41:44 +01:00
buttonWrapper added, npm updates done, changelog added and formatting
This commit is contained in:
parent
62d607d813
commit
d1a1c39ef6
39
CHANGELOG.md
Normal file
39
CHANGELOG.md
Normal 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
223
README.md
@ -14,13 +14,13 @@ Example branch: https://github.com/Mastermindzh/react-cookie-consent/tree/exampl
|
||||
|
||||
## Installation
|
||||
|
||||
``` shell
|
||||
```shell
|
||||
npm install react-cookie-consent
|
||||
```
|
||||
|
||||
or use yarn:
|
||||
|
||||
``` shell
|
||||
```shell
|
||||
yarn add react-cookie-consent
|
||||
```
|
||||
|
||||
@ -28,39 +28,35 @@ yarn add react-cookie-consent
|
||||
|
||||
You can import the cookie bar like this:
|
||||
|
||||
``` js
|
||||
```js
|
||||
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:
|
||||
|
||||
``` js
|
||||
```js
|
||||
import CookieConsent, { Cookies } from "react-cookie-consent";
|
||||
```
|
||||
|
||||
Then you can use the component anywhere in your React app like so:
|
||||
|
||||
```jsx
|
||||
<CookieConsent>
|
||||
This website uses cookies to enhance the user experience.
|
||||
</CookieConsent>
|
||||
<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):
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
location="bottom"
|
||||
buttonText="Sure man!!"
|
||||
cookieName="myAwesomeCookieName2"
|
||||
style={{ background: "#2B373B" }}
|
||||
buttonStyle={{ color: "#4e503b", fontSize: "13px" }}
|
||||
expires={150}
|
||||
location="bottom"
|
||||
buttonText="Sure man!!"
|
||||
cookieName="myAwesomeCookieName2"
|
||||
style={{ background: "#2B373B" }}
|
||||
buttonStyle={{ color: "#4e503b", fontSize: "13px" }}
|
||||
expires={150}
|
||||
>
|
||||
This website uses cookies to enhance the user experience.{" "}
|
||||
<span style={{ fontSize: "10px" }}>
|
||||
This bit of text is smaller :O
|
||||
</span>
|
||||
This website uses cookies to enhance the user experience.{" "}
|
||||
<span style={{ fontSize: "10px" }}>This bit of text is smaller :O</span>
|
||||
</CookieConsent>
|
||||
```
|
||||
|
||||
@ -68,75 +64,72 @@ One of the props (onAccept) is a function, this function will be called after th
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
acceptOnScroll={true}
|
||||
onAccept={({ acceptedByScrolling }) => {
|
||||
if (acceptedByScrolling) {
|
||||
// triggered if user scrolls past threshold
|
||||
alert("Accept was triggered by user scrolling");
|
||||
} else {
|
||||
alert("Accept was triggered by clicking the Accept button");
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
</CookieConsent>
|
||||
acceptOnScroll={true}
|
||||
onAccept={({ acceptedByScrolling }) => {
|
||||
if (acceptedByScrolling) {
|
||||
// triggered if user scrolls past threshold
|
||||
alert("Accept was triggered by user scrolling");
|
||||
} else {
|
||||
alert("Accept was triggered by clicking the Accept button");
|
||||
}
|
||||
}}
|
||||
></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:
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
enableDeclineButton
|
||||
onDecline={() => {alert("nay!")}}
|
||||
>
|
||||
|
||||
</CookieConsent>
|
||||
enableDeclineButton
|
||||
onDecline={() => {
|
||||
alert("nay!");
|
||||
}}
|
||||
></CookieConsent>
|
||||
```
|
||||
|
||||
## Props
|
||||
| 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 |
|
||||
| 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)|
|
||||
| acceptOnScroll | boolean | false | Defines whether "accept" should be fired after the user scrolls a certain distance (see acceptOnScrollPercentage) |
|
||||
| acceptOnScrollPercentage | number | 25 | Percentage of the page height the user has to scroll to trigger the accept function if acceptOnScroll is enabled |
|
||||
| buttonText | string or React component | "I understand" | Text to appear on the button |
|
||||
| declineButtonText | string or React component | "I decline" | Text to appear on the decline button |
|
||||
| cookieName | string | "CookieConsent" | Name of the cookie used to track whether the user has agreed. |
|
||||
| cookieValue | string or boolean or number | true | Value to be saved under the cookieName. |
|
||||
| declineCookieValue | string or boolean or number | false | Value to be saved under the cookieName when declined. |
|
||||
| setDeclineCookie | boolean | true | Whether to set a cookie when the user clicks "decline" |
|
||||
| onAccept | function | `({ acceptedByScrolling }) => {}` | Function to be called after the accept button has been clicked. |
|
||||
| onDecline | function | `() => {}` | Function to be called after the decline button has been clicked. |
|
||||
| debug | boolean | undefined | Bar will be drawn regardless of cookie for debugging purposes. |
|
||||
| expires | number | 365 | Number of days before the cookie expires. |
|
||||
| extraCookieOptions | object | `{}` | Extra info (apart from expiry date) to add to the cookie|
|
||||
| containerClasses| string | "" | CSS classes to apply to the surrounding container |
|
||||
| buttonClasses | string | "" | CSS classes to apply to the button |
|
||||
| declineButtonClasses | string | "" | CSS classes to apply to the decline button |
|
||||
| buttonId | string | "" | Id to apply to the button |
|
||||
| declineButtonId | string | "" | Id to apply to the decline button |
|
||||
| contentClasses| string | "" | CSS classes to apply to the content |
|
||||
| style | object | [look at source][style] | React styling object for the bar. |
|
||||
| buttonStyle | object | [look at source][buttonStyle] | React styling object for the button. |
|
||||
| declineButtonStyle | object | [look at source][declineButtonStyle] | React styling object for the decline button. |
|
||||
| contentStyle | object | [look at source][contentStyle] | React styling object for the content. |
|
||||
| disableButtonStyles | boolean | false | If enabled the button will have no default style. (you can still supply style through props) |
|
||||
| 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.
|
||||
|
||||
| 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 |
|
||||
| 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) |
|
||||
| acceptOnScroll | boolean | false | Defines whether "accept" should be fired after the user scrolls a certain distance (see acceptOnScrollPercentage) |
|
||||
| acceptOnScrollPercentage | number | 25 | Percentage of the page height the user has to scroll to trigger the accept function if acceptOnScroll is enabled |
|
||||
| buttonText | string or React component | "I understand" | Text to appear on the button |
|
||||
| declineButtonText | string or React component | "I decline" | Text to appear on the decline button |
|
||||
| cookieName | string | "CookieConsent" | Name of the cookie used to track whether the user has agreed. |
|
||||
| cookieValue | string or boolean or number | true | Value to be saved under the cookieName. |
|
||||
| declineCookieValue | string or boolean or number | false | Value to be saved under the cookieName when declined. |
|
||||
| setDeclineCookie | boolean | true | Whether to set a cookie when the user clicks "decline" |
|
||||
| onAccept | function | `({ acceptedByScrolling }) => {}` | Function to be called after the accept button has been clicked. |
|
||||
| onDecline | function | `() => {}` | Function to be called after the decline button has been clicked. |
|
||||
| debug | boolean | undefined | Bar will be drawn regardless of cookie for debugging purposes. |
|
||||
| expires | number | 365 | Number of days before the cookie expires. |
|
||||
| extraCookieOptions | object | `{}` | Extra info (apart from expiry date) to add to the cookie |
|
||||
| containerClasses | string | "" | CSS classes to apply to the surrounding container |
|
||||
| buttonClasses | string | "" | CSS classes to apply to the button |
|
||||
| buttonWrapperClasses | string | "" | CSS classes to apply to the div wrapping the buttons |
|
||||
| declineButtonClasses | string | "" | CSS classes to apply to the decline button |
|
||||
| buttonId | string | "" | Id to apply to the button |
|
||||
| declineButtonId | string | "" | Id to apply to the decline button |
|
||||
| contentClasses | string | "" | CSS classes to apply to the content |
|
||||
| style | object | [look at source][style] | React styling object for the bar. |
|
||||
| buttonStyle | object | [look at source][buttonstyle] | React styling object for the button. |
|
||||
| declineButtonStyle | object | [look at source][declinebuttonstyle] | React styling object for the decline button. |
|
||||
| contentStyle | object | [look at source][contentstyle] | React styling object for the content. |
|
||||
| disableButtonStyles | boolean | false | If enabled the button will have no default style. (you can still supply style through props) |
|
||||
| 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
|
||||
|
||||
Because the cookie consent bar will be hidden once accepted, you will have to set the prop `debug={true}` to evaluate styling changes:
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
debug={true}
|
||||
>
|
||||
</CookieConsent>
|
||||
<CookieConsent debug={true}></CookieConsent>
|
||||
```
|
||||
|
||||
**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
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
style={{ background: "red" }}
|
||||
>
|
||||
</CookieConsent>
|
||||
<CookieConsent style={{ background: "red" }}></CookieConsent>
|
||||
```
|
||||
|
||||
#### changing the button font-weight to bold
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
buttonStyle={{ fontWeight: "bold" }}
|
||||
>
|
||||
</CookieConsent>
|
||||
<CookieConsent buttonStyle={{ fontWeight: "bold" }}></CookieConsent>
|
||||
```
|
||||
|
||||
#### 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:
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
disableStyles={true}
|
||||
location={OPTIONS.BOTTOM}
|
||||
buttonClasses="btn btn-primary"
|
||||
containerClasses="alert alert-warning col-lg-12"
|
||||
contentClasses="text-capitalize"
|
||||
>
|
||||
This website uses cookies to enhance the user experience.{" "}
|
||||
<span style={{ fontSize: "10px" }}>
|
||||
This bit of text is smaller :O
|
||||
</span>
|
||||
</CookieConsent>
|
||||
<CookieConsent
|
||||
disableStyles={true}
|
||||
location={OPTIONS.BOTTOM}
|
||||
buttonClasses="btn btn-primary"
|
||||
containerClasses="alert alert-warning col-lg-12"
|
||||
contentClasses="text-capitalize"
|
||||
>
|
||||
This website uses cookies to enhance the user experience.{" "}
|
||||
<span style={{ fontSize: "10px" }}>This bit of text is smaller :O</span>
|
||||
</CookieConsent>
|
||||
```
|
||||
|
||||
Which results in:
|
||||
|
||||
![bootstrap styling](https://github.com/Mastermindzh/react-cookie-consent/blob/master/images/css_classes.png?raw=true)
|
||||
|
||||
|
||||
#### Accept on scroll
|
||||
|
||||
You can make the cookiebar disappear after scrolling a certain percentage using acceptOnScroll and acceptOnScrollPercentage.
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
acceptOnScroll={true}
|
||||
acceptOnScrollPercentage={50}
|
||||
onAccept={() => {alert("consent given")}}
|
||||
acceptOnScroll={true}
|
||||
acceptOnScrollPercentage={50}
|
||||
onAccept={() => {
|
||||
alert("consent given");
|
||||
}}
|
||||
>
|
||||
Hello scroller :)
|
||||
Hello scroller :)
|
||||
</CookieConsent>
|
||||
```
|
||||
|
||||
#### Flipping the buttons
|
||||
|
||||
If you enable the decline button you can pass along the "flipButtons" property to turn the buttons around:
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
enableDeclineButton
|
||||
flipButtons
|
||||
>
|
||||
Flipped buttons
|
||||
<CookieConsent enableDeclineButton flipButtons>
|
||||
Flipped buttons
|
||||
</CookieConsent>
|
||||
```
|
||||
|
||||
@ -226,14 +211,11 @@ Which results in:
|
||||
![flipped buttons](./images/flipped.png)
|
||||
|
||||
#### Extra cookie options
|
||||
|
||||
You can add more cookie options using the extraCookieOptions parameter like so:
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
extraCookieOptions={{domain: 'myexample.com'}}
|
||||
>
|
||||
cookie bar
|
||||
</CookieConsent>
|
||||
<CookieConsent extraCookieOptions={{ domain: "myexample.com" }}>cookie bar</CookieConsent>
|
||||
```
|
||||
|
||||
#### rainbows!
|
||||
@ -244,23 +226,30 @@ If you're crazy enough you can even make a rainbow colored bar:
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
buttonText="OMG DOUBLE RAINBOW"
|
||||
cookieName="myAwesomeCookieName2"
|
||||
style={{ 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"}}
|
||||
buttonText="OMG DOUBLE RAINBOW"
|
||||
cookieName="myAwesomeCookieName2"
|
||||
style={{
|
||||
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.{" "}
|
||||
<span style={{ fontSize: "10px" }}>
|
||||
This bit of text is smaller :O
|
||||
</span>
|
||||
This website uses cookies to enhance the user experience.{" "}
|
||||
<span style={{ fontSize: "10px" }}>This bit of text is smaller :O</span>
|
||||
</CookieConsent>
|
||||
```
|
||||
|
||||
<!-- links -->
|
||||
|
||||
[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
|
||||
[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
|
||||
[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
|
||||
[contentstyle]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L52-L55
|
||||
|
||||
## Projects using react-cookie-consent
|
||||
|
||||
|
2
build/index.d.ts
vendored
2
build/index.d.ts
vendored
@ -32,7 +32,7 @@ export interface CookieConsentProps {
|
||||
disableButtonStyles?: boolean;
|
||||
enableDeclineButton?: boolean;
|
||||
flipButtons?: boolean;
|
||||
ButtonComponent?: Function | React.ReactElement;
|
||||
ButtonComponent?: React.ElementType;
|
||||
}
|
||||
|
||||
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {}
|
||||
|
106
build/index.js
106
build/index.js
@ -725,6 +725,7 @@ var CookieConsent = function (_Component) {
|
||||
containerClasses = _props4.containerClasses,
|
||||
contentClasses = _props4.contentClasses,
|
||||
buttonClasses = _props4.buttonClasses,
|
||||
buttonWrapperClasses = _props4.buttonWrapperClasses,
|
||||
declineButtonClasses = _props4.declineButtonClasses,
|
||||
buttonId = _props4.buttonId,
|
||||
declineButtonId = _props4.declineButtonId,
|
||||
@ -809,15 +810,19 @@ var CookieConsent = function (_Component) {
|
||||
|
||||
return _react2.default.createElement(
|
||||
"div",
|
||||
{ className: "cookieConsent " + containerClasses, style: myStyle },
|
||||
{ className: "" + containerClasses, style: myStyle },
|
||||
_react2.default.createElement(
|
||||
"div",
|
||||
{ style: myContentStyle, className: contentClasses },
|
||||
this.props.children
|
||||
),
|
||||
buttonsToRender.map(function (button) {
|
||||
return button;
|
||||
})
|
||||
_react2.default.createElement(
|
||||
"div",
|
||||
{ className: "" + buttonWrapperClasses },
|
||||
buttonsToRender.map(function (button) {
|
||||
return button;
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}]);
|
||||
@ -850,6 +855,7 @@ CookieConsent.propTypes = {
|
||||
containerClasses: _propTypes2.default.string,
|
||||
contentClasses: _propTypes2.default.string,
|
||||
buttonClasses: _propTypes2.default.string,
|
||||
buttonWrapperClasses: _propTypes2.default.string,
|
||||
declineButtonClasses: _propTypes2.default.string,
|
||||
buttonId: _propTypes2.default.string,
|
||||
declineButtonId: _propTypes2.default.string,
|
||||
@ -859,7 +865,7 @@ CookieConsent.propTypes = {
|
||||
disableButtonStyles: _propTypes2.default.bool,
|
||||
enableDeclineButton: _propTypes2.default.bool,
|
||||
flipButtons: _propTypes2.default.bool,
|
||||
ButtonComponent: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.element])
|
||||
ButtonComponent: _propTypes2.default.elementType
|
||||
};
|
||||
|
||||
CookieConsent.defaultProps = {
|
||||
@ -882,9 +888,10 @@ CookieConsent.defaultProps = {
|
||||
containerClasses: "",
|
||||
contentClasses: "",
|
||||
buttonClasses: "",
|
||||
buttonWrapperClasses: "",
|
||||
declineButtonClasses: "",
|
||||
buttonId: "",
|
||||
declineButtonId: "",
|
||||
buttonId: "rcc-confirm-button",
|
||||
declineButtonId: "rcc-decline-button",
|
||||
extraCookieOptions: {},
|
||||
disableButtonStyles: false,
|
||||
enableDeclineButton: false,
|
||||
@ -1786,7 +1793,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"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
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
@ -1803,8 +1810,6 @@ if (process.env.NODE_ENV !== "production") {
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
// 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.
|
||||
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_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
||||
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_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
|
||||
var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
|
||||
|
||||
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.
|
||||
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) {
|
||||
if (typeof object === 'object' && object !== null) {
|
||||
var $$typeof = object.$$typeof;
|
||||
@ -1948,8 +1899,9 @@ var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecat
|
||||
function isAsyncMode(object) {
|
||||
{
|
||||
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
|
||||
hasWarnedAboutDeprecatedIsAsyncMode = true;
|
||||
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.');
|
||||
hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
exports.typeOf = typeOf;
|
||||
exports.AsyncMode = AsyncMode;
|
||||
exports.ConcurrentMode = ConcurrentMode;
|
||||
exports.ContextConsumer = ContextConsumer;
|
||||
@ -2006,7 +1957,6 @@ exports.Portal = Portal;
|
||||
exports.Profiler = Profiler;
|
||||
exports.StrictMode = StrictMode;
|
||||
exports.Suspense = Suspense;
|
||||
exports.isValidElementType = isValidElementType;
|
||||
exports.isAsyncMode = isAsyncMode;
|
||||
exports.isConcurrentMode = isConcurrentMode;
|
||||
exports.isContextConsumer = isContextConsumer;
|
||||
@ -2020,6 +1970,8 @@ exports.isPortal = isPortal;
|
||||
exports.isProfiler = isProfiler;
|
||||
exports.isStrictMode = isStrictMode;
|
||||
exports.isSuspense = isSuspense;
|
||||
exports.isValidElementType = isValidElementType;
|
||||
exports.typeOf = typeOf;
|
||||
})();
|
||||
}
|
||||
|
||||
@ -2030,7 +1982,7 @@ exports.isSuspense = isSuspense;
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
/** @license React v16.12.0
|
||||
/** @license React v16.13.1
|
||||
* react-is.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
@ -2039,12 +1991,12 @@ exports.isSuspense = isSuspense;
|
||||
* 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?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.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}
|
||||
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.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.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};
|
||||
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"):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;
|
||||
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.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.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.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;
|
||||
|
||||
|
||||
/***/ })
|
||||
|
14
package.json
14
package.json
@ -4,15 +4,15 @@
|
||||
"name": "Rick van Lieshout",
|
||||
"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.",
|
||||
"main": "build/index.js",
|
||||
"types": "build/index.d.ts",
|
||||
"dependencies": {
|
||||
"js-cookie": "^2.2.0"
|
||||
"js-cookie": "^2.2.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.4.0"
|
||||
"react": "^16.13.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
@ -40,18 +40,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/Mastermindzh/react-cookie-consent#readme",
|
||||
"devDependencies": {
|
||||
"@types/js-cookie": "^2.2.2",
|
||||
"babel-cli": "^6.24.1",
|
||||
"@types/js-cookie": "^2.2.6",
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-loader": "^7.1.4",
|
||||
"babel-plugin-transform-object-assign": "^6.22.0",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||
"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-stage-1": "^6.24.1",
|
||||
"copy-webpack-plugin": "^4.6.0",
|
||||
"react": "^16.8.6",
|
||||
"react": "^16.13.1",
|
||||
"webpack": "^2.6.1"
|
||||
}
|
||||
}
|
||||
|
41
src/index.js
41
src/index.js
@ -5,7 +5,7 @@ import Cookies from "js-cookie";
|
||||
export const OPTIONS = {
|
||||
TOP: "top",
|
||||
BOTTOM: "bottom",
|
||||
NONE: "none"
|
||||
NONE: "none",
|
||||
};
|
||||
|
||||
class CookieConsent extends Component {
|
||||
@ -25,7 +25,7 @@ class CookieConsent extends Component {
|
||||
left: "0",
|
||||
position: "fixed",
|
||||
width: "100%",
|
||||
zIndex: "999"
|
||||
zIndex: "999",
|
||||
},
|
||||
buttonStyle: {
|
||||
background: "#ffd42d",
|
||||
@ -36,7 +36,7 @@ class CookieConsent extends Component {
|
||||
cursor: "pointer",
|
||||
flex: "0 0 auto",
|
||||
padding: "5px 10px",
|
||||
margin: "15px"
|
||||
margin: "15px",
|
||||
},
|
||||
declineButtonStyle: {
|
||||
background: "#c12a2a",
|
||||
@ -47,12 +47,12 @@ class CookieConsent extends Component {
|
||||
cursor: "pointer",
|
||||
flex: "0 0 auto",
|
||||
padding: "5px 10px",
|
||||
margin: "15px"
|
||||
margin: "15px",
|
||||
},
|
||||
contentStyle: {
|
||||
flex: "1 0 300px",
|
||||
margin: "15px"
|
||||
}
|
||||
margin: "15px",
|
||||
},
|
||||
};
|
||||
|
||||
this.handleScroll = this.handleScroll.bind(this);
|
||||
@ -107,7 +107,7 @@ class CookieConsent extends Component {
|
||||
expires,
|
||||
hideOnAccept,
|
||||
onAccept,
|
||||
extraCookieOptions
|
||||
extraCookieOptions,
|
||||
} = this.props;
|
||||
|
||||
// fire onAccept
|
||||
@ -134,7 +134,7 @@ class CookieConsent extends Component {
|
||||
hideOnDecline,
|
||||
onDecline,
|
||||
extraCookieOptions,
|
||||
setDeclineCookie
|
||||
setDeclineCookie,
|
||||
} = this.props;
|
||||
|
||||
// fire onDecline
|
||||
@ -170,13 +170,14 @@ class CookieConsent extends Component {
|
||||
containerClasses,
|
||||
contentClasses,
|
||||
buttonClasses,
|
||||
buttonWrapperClasses,
|
||||
declineButtonClasses,
|
||||
buttonId,
|
||||
declineButtonId,
|
||||
disableButtonStyles,
|
||||
enableDeclineButton,
|
||||
flipButtons,
|
||||
ButtonComponent
|
||||
ButtonComponent,
|
||||
} = this.props;
|
||||
|
||||
let myStyle = {};
|
||||
@ -257,20 +258,22 @@ class CookieConsent extends Component {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`cookieConsent ${containerClasses}`} style={myStyle}>
|
||||
<div className={`${containerClasses}`} style={myStyle}>
|
||||
<div style={myContentStyle} className={contentClasses}>
|
||||
{this.props.children}
|
||||
</div>
|
||||
{buttonsToRender.map(button => {
|
||||
return button;
|
||||
})}
|
||||
<div className={`${buttonWrapperClasses}`}>
|
||||
{buttonsToRender.map((button) => {
|
||||
return button;
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
buttonStyle: PropTypes.object,
|
||||
declineButtonStyle: PropTypes.object,
|
||||
@ -292,6 +295,7 @@ CookieConsent.propTypes = {
|
||||
containerClasses: PropTypes.string,
|
||||
contentClasses: PropTypes.string,
|
||||
buttonClasses: PropTypes.string,
|
||||
buttonWrapperClasses: PropTypes.string,
|
||||
declineButtonClasses: PropTypes.string,
|
||||
buttonId: PropTypes.string,
|
||||
declineButtonId: PropTypes.string,
|
||||
@ -301,7 +305,7 @@ CookieConsent.propTypes = {
|
||||
disableButtonStyles: PropTypes.bool,
|
||||
enableDeclineButton: PropTypes.bool,
|
||||
flipButtons: PropTypes.bool,
|
||||
ButtonComponent: PropTypes.elementType
|
||||
ButtonComponent: PropTypes.elementType,
|
||||
};
|
||||
|
||||
CookieConsent.defaultProps = {
|
||||
@ -324,14 +328,15 @@ CookieConsent.defaultProps = {
|
||||
containerClasses: "",
|
||||
contentClasses: "",
|
||||
buttonClasses: "",
|
||||
buttonWrapperClasses: "",
|
||||
declineButtonClasses: "",
|
||||
buttonId: "",
|
||||
declineButtonId: "",
|
||||
buttonId: "rcc-confirm-button",
|
||||
declineButtonId: "rcc-decline-button",
|
||||
extraCookieOptions: {},
|
||||
disableButtonStyles: false,
|
||||
enableDeclineButton: false,
|
||||
flipButtons: false,
|
||||
ButtonComponent: ({ children, ...props }) => <button {...props}>{children}</button>
|
||||
ButtonComponent: ({ children, ...props }) => <button {...props}>{children}</button>,
|
||||
};
|
||||
|
||||
export default CookieConsent;
|
||||
|
Loading…
Reference in New Issue
Block a user