Compare commits
136 Commits
8f1152c04d
...
6.2.3
Author | SHA1 | Date | |
---|---|---|---|
|
0228e7f32c | ||
50216eec3c | |||
3e9e988e96 | |||
1c6f335500 | |||
eb45e7a652 | |||
26306f7490 | |||
7d8f52018d | |||
a494066785 | |||
|
7f15b25e89 | ||
0f4893af4b | |||
|
1ad4474d93 | ||
|
6a5aac9cd7 | ||
c656e311e6 | |||
|
86226dfbe3 | ||
|
d0c619542d | ||
f6243bd987 | |||
d99d88f5b8 | |||
f51e2a0555 | |||
5e4e8406e6 | |||
b1913d223e | |||
cb93ae6387 | |||
35e45c3125 | |||
a7fe76056e | |||
3471a72b1e | |||
777ceb8e1a | |||
72443a758a | |||
|
5910a110ce | ||
a56e806ee2 | |||
13c6909b1a | |||
97bb1e5be0 | |||
|
4fa6476406 | ||
8561858333 | |||
d502d28739 | |||
47f0e98fe4 | |||
6dbd794b6e | |||
|
76ec5ba9e6 | ||
9169c132fe | |||
75ff4a09e6 | |||
d51ea89620 | |||
e7c2b5b39a | |||
22bb46981d | |||
e2fb5f3990 | |||
a64cbc28f9 | |||
|
d7bfb5bfbd | ||
|
3cf103ae3a | ||
|
a45da474b4 | ||
|
ee7ac9ed86 | ||
b3bd42adae | |||
900d724ea5 | |||
d1a1c39ef6 | |||
62d607d813 | |||
|
c1659cef53 | ||
4a37243ec2 | |||
6328f74e78 | |||
12341c9126 | |||
|
7cc1fc3905 | ||
9980d42af6 | |||
7b5e6dc66f | |||
|
11b55f2f8a | ||
7e0cb2059b | |||
959412c96b | |||
51e0c9949c | |||
844b69363e | |||
8d74d5531f | |||
1c3a54bd89 | |||
c174baaba6 | |||
|
3c1d11b509 | ||
f3c5bfcd83 | |||
68a8301cd5 | |||
|
f7a98c925d | ||
98b401dc72 | |||
|
cfbd647c38 | ||
5a807f884b | |||
8aef083015 | |||
|
34ac530629 | ||
ce0d7e2b0c | |||
bd54a23369 | |||
b1ba269ed3 | |||
13701e0a1d | |||
3926fff424 | |||
c82911c903 | |||
|
351b0e1233 | ||
e7a48a8694 | |||
f355409b87 | |||
|
abe9a06399 | ||
67af0cf9f4 | |||
9baff03191 | |||
49f275b3cd | |||
969da3c809 | |||
|
ee24754fc8 | ||
0a5e4ea440 | |||
e8d4dcab3e | |||
a4c30e6a5d | |||
4cc521c977 | |||
666678eade | |||
|
f587c141b0 | ||
|
720063d47b | ||
73271cafe1 | |||
06d41df333 | |||
1822d9ad83 | |||
04c553fded | |||
|
ef192c0e86 | ||
|
673f4fe28f | ||
48995d9a3c | |||
cd634efa9e | |||
55267ebfce | |||
|
f1fdab3bb5 | ||
e6120e4f24 | |||
|
c5a2632ea3 | ||
b3d5470d8c | |||
df6bd5464f | |||
27833943f0 | |||
38b8d752bb | |||
3f6c47ae6d | |||
ace3cf2886 | |||
|
97133f2c80 | ||
c5a4268624 | |||
|
2d1501457b | ||
d601613b5a | |||
f8ef6ca218 | |||
8df1e362c8 | |||
55f62ee575 | |||
869e0b1d13 | |||
0fe4c4c567 | |||
|
cbbbd0422a | ||
|
36a8fae2b9 | ||
ecdf88a7e9 | |||
|
66d6aaa57d | ||
|
dd350edfbd | ||
26cde73055 | |||
|
456d5b4fa0 | ||
8bf481fe59 | |||
431419c3b4 | |||
1ea07ba29f | |||
|
30214d5411 | ||
413ef0c595 |
9
.babelrc
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"presets": ["env"],
|
||||
"presets": ["@babel/preset-env"],
|
||||
"plugins": [
|
||||
"transform-object-rest-spread",
|
||||
"transform-react-jsx"
|
||||
"@babel/plugin-proposal-object-rest-spread",
|
||||
"@babel/plugin-transform-react-jsx",
|
||||
"@babel/plugin-transform-object-assign"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
23
.editorconfig
Normal file
@@ -0,0 +1,23 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
indent_size = 8
|
||||
|
||||
[{deps,tools,build}/**]
|
||||
indent_style = ignore
|
||||
indent_size = ignore
|
||||
end_of_line = ignore
|
||||
trim_trailing_whitespace = ignore
|
||||
charset = ignore
|
||||
|
||||
[{test/fixtures,deps,build,tools/eslint,tools/gyp,tools/icu,tools/msvs}/**]
|
||||
insert_final_newline = false
|
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
node_modules
|
||||
package-lock.json
|
||||
build/index.js.LICENSE.txt
|
||||
|
120
CHANGELOG.md
Normal file
@@ -0,0 +1,120 @@
|
||||
# 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).
|
||||
|
||||
## [[6.2.3](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.2.3)]
|
||||
|
||||
- Added support for IE11, the webpack generated runtime-code should not use arrow functions
|
||||
|
||||
## [[6.2.2](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.2.2)]
|
||||
|
||||
- Fixed the return type of getCookieConsentValue in the dts file.
|
||||
|
||||
## [[6.2.1](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.2.1)]
|
||||
|
||||
Added the `getCookieConsentValue` to the dts file.
|
||||
|
||||
## [[6.2.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.2.0)]
|
||||
|
||||
Added the exported function `getCookieConsentValue` to get the cookie value from custom code
|
||||
|
||||
## [[6.1.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.1.0)]
|
||||
|
||||
Added support for React 17
|
||||
|
||||
## [[6.0.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/6.0.0)]
|
||||
|
||||
### removed
|
||||
|
||||
Accepting by scrolling is no longer allowed and has thus been removed from the package.
|
||||
For details see [issue 88](https://github.com/Mastermindzh/react-cookie-consent/issues/88)
|
||||
|
||||
## [[5.2.0](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/5.2.0)]
|
||||
|
||||
### added
|
||||
|
||||
Added aria labels for both the decline and accept button
|
||||
|
||||
## [[5.1.4](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/5.1.4)]
|
||||
|
||||
### changed
|
||||
|
||||
- set default SameSite attribute to "lax" because browsers are already implementing the cookie policy changes.
|
||||
|
||||
## [[5.1.3](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/5.1.3)]
|
||||
|
||||
### changed
|
||||
|
||||
- Fix missing buttonWrapperClasses prop in type definition
|
||||
|
||||
## [5.1.2]
|
||||
|
||||
### changed
|
||||
|
||||
- Set cookie value before handling side-effects.
|
||||
- The overlay is now conditional. Meaning that the component behaves exactly as it did prior to 5.1.0 when you do not use the overlay
|
||||
|
||||
## [5.1.0]
|
||||
|
||||
A new feature! This time it's an "overlay" on the entire website to block access whilst the cookiebar is displayed.
|
||||
This is all opt-in of course and the README covers it nicely (just add overlay to the props and see what happens).
|
||||
|
||||
We got an update picture, with a cute cat... unfortunately the cat won't be included by default:
|
||||
|
||||

|
||||
|
||||
## [5.0.1]
|
||||
|
||||
- Fixed [Issue
|
||||
69](https://github.com/Mastermindzh/react-cookie-consent/issues/69) by
|
||||
removing location from the proptypes to avoid build-time issues
|
||||
|
||||
## [5.0.0]
|
||||
|
||||
### added
|
||||
|
||||
- CookieSecurity prop - allows securing the cookie
|
||||
- sameSite prop - allows you to set sameSite properties so browser won't warn
|
||||
about non-secure cookies :)
|
||||
|
||||
## [4.1.0]
|
||||
|
||||
### changed
|
||||
|
||||
- Added CookieConsent back in as the default for the containerClasses property.
|
||||
|
||||
## [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`
|
152
CONTRIBUTING.md
Normal file
@@ -0,0 +1,152 @@
|
||||
# Contributing
|
||||
|
||||
When contributing to this repository, please first discuss the change you wish to make via issue,
|
||||
email, or any other method with the owners of this repository before making a changes in order to avoid wasting your time.
|
||||
|
||||
## scope
|
||||
|
||||
Please keep the scope of a PR down to a single change.
|
||||
You can make multiple prs to change multiple things though.
|
||||
|
||||
## builds
|
||||
|
||||
Don't modify anything in the build/ directory please.
|
||||
This will be done on release.
|
||||
|
||||
## Pull Request Process
|
||||
|
||||
1. Code away :D
|
||||
2. Update the README.md with details of changes to the interface, this includes new environment
|
||||
variables, exposed ports, useful file locations and container parameters.
|
||||
_Please don't change the format of the variable table in the README_
|
||||
3. Add the section "[next]" to the CHANGELOG.md and describe what you changed and why.
|
||||
4. Create the PR. yay.
|
||||
|
||||
## Contributor Covenant Code of Conduct
|
||||
|
||||
### Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
### Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
- Demonstrating empathy and kindness toward other people
|
||||
- Being respectful of differing opinions, viewpoints, and experiences
|
||||
- Giving and gracefully accepting constructive feedback
|
||||
- Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
- Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
- The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
### Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
### Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
### Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
[info@rickvanlieshout.com](mailto:info@rickvanlieshout.com).
|
||||
All complaints will be reviewed and investigated fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
### Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
#### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
#### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
#### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
#### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
### Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
283
README.md
@@ -4,20 +4,47 @@ A small, simple and customizable cookie consent bar for use in React application
|
||||
|
||||
[](https://npmjs.org/package/react-cookie-consent)
|
||||
|
||||
Demo: https://mastermindzh.github.io/react-cookie-consent/
|
||||
|
||||
Example branch: https://github.com/Mastermindzh/react-cookie-consent/tree/example
|
||||
|
||||
     
|
||||
|
||||
## Default look
|
||||
|
||||

|
||||
|
||||
## Table of contents
|
||||
|
||||
<!-- toc -->
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Using it](#using-it)
|
||||
- [Props](#props)
|
||||
- [Debugging it](#debugging-it)
|
||||
- [Why are there two cookies? One of which named "Legacy"](#why-are-there-two-cookies-one-of-which-named-legacy)
|
||||
- [Styling it](#styling-it)
|
||||
- [Examples](#examples)
|
||||
- [Changing the bar background to red](#changing-the-bar-background-to-red)
|
||||
- [Changing the button font-weight to bold](#changing-the-button-font-weight-to-bold)
|
||||
- [Using predefined CSS classes](#using-predefined-css-classes)
|
||||
- [Flipping the buttons](#flipping-the-buttons)
|
||||
- [Extra cookie options](#extra-cookie-options)
|
||||
- [Rainbows!](#rainbows)
|
||||
- [Contributor information](#contributor-information)
|
||||
- [Projects using react-cookie-consent](#projects-using-react-cookie-consent)
|
||||
|
||||
<!-- tocstop -->
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
```shell
|
||||
npm install react-cookie-consent
|
||||
```
|
||||
|
||||
or use yarn:
|
||||
|
||||
```
|
||||
```shell
|
||||
yarn add react-cookie-consent
|
||||
```
|
||||
|
||||
@@ -28,32 +55,32 @@ You can import the cookie bar like this:
|
||||
```js
|
||||
import CookieConsent from "react-cookie-consent";
|
||||
```
|
||||
If you want to set/remove cookies yourself you can optionally import Cookie (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
|
||||
import CookieConsent, { Cookies } from "react-cookie-consent";
|
||||
```
|
||||
|
||||
Then you can use the component anywhere in your React app like so:
|
||||
|
||||
```js
|
||||
<CookieConsent>
|
||||
This website uses cookies to enhance the user experience.
|
||||
</CookieConsent>
|
||||
```jsx
|
||||
<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" }}
|
||||
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>
|
||||
```
|
||||
|
||||
@@ -61,53 +88,170 @@ One of the props (onAccept) is a function, this function will be called after th
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
onAccept={() => {alert("yay!")}}
|
||||
>
|
||||
onAccept={() => {
|
||||
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:
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
enableDeclineButton
|
||||
onDecline={() => {
|
||||
alert("nay!");
|
||||
}}
|
||||
></CookieConsent>
|
||||
```
|
||||
|
||||
### getting the cookies value in your own code
|
||||
|
||||
react-cookie-consent exports a function called `getCookieConsentValue`. You can use it in your own code like so:
|
||||
|
||||
```js
|
||||
import CookieConsent, { Cookies, getCookieConsentValue } from "react-cookie-consent";
|
||||
|
||||
console.log(getCookieConsentValue());
|
||||
```
|
||||
|
||||
## Props
|
||||
| Prop | Type | Default value | Description |
|
||||
|---------------|:--------------------------------:|---------------|-------------------------------------------------------------------------------------------------------|
|
||||
| location | String, either "top" or "bottom" | bottom | Syntactic sugar to easily enable you to place the bar at the top or the bottom of the browser window. |
|
||||
| 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) |
|
||||
| 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. |
|
||||
| style | Object |  | React styling object for the bar. |
|
||||
| buttonStyle | Object |  | React styling object for the 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) |
|
||||
| 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 | `() => {}` | 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 |
|
||||
| overlay | boolean | false | Whether to show a page obscuring overlay or not. |
|
||||
| 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 |
|
||||
| overlayClasses | string | "" | CSS classes to apply to the surrounding overlay |
|
||||
| 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. |
|
||||
| overlayStyle | object | [look at source][overlaystyle] | React styling object for the overlay. |
|
||||
| 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. |
|
||||
| sameSite | string, "strict", "lax" or "none" | none | Cookies sameSite attribute value |
|
||||
| cookieSecurity | boolean | undefined | Cookie security level. Defaults to true unless running on http. |
|
||||
| ariaAcceptLabel | string | Accept cookies | Aria label to set on the accept button |
|
||||
| ariaDeclineLabel | string | Decline cookies | Aria label to set on the decline 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>
|
||||
```
|
||||
|
||||
**Note:** Don't forget to remove the `debug`-property for production.
|
||||
|
||||
## Why are there two cookies? One of which named "Legacy"
|
||||
|
||||
The short story is that some browsers don't support the SameSite=None attribute.
|
||||
The modern browsers force you to have SameSite set to something other than none.
|
||||
|
||||
So react-cookie-consent fixes this like so:
|
||||
|
||||
- set the fallback cookie (e.g -legacy) first, this will always succeed (on all browsers)
|
||||
- set the correct cookie second (this will work on modern browsers, fail on older ones)
|
||||
|
||||
This happens on lines [186-192](https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L186-L192)
|
||||
|
||||
When checking the cookie it'll do it in reverse. If the regular cookie exists, it'll use that. If no regular cookie exists it'll check whether the legacy cookie exists. If both are non-existent no consent was given.
|
||||
|
||||
The long story can be found here: [pull-request#68](https://github.com/Mastermindzh/react-cookie-consent/pull/68)
|
||||
|
||||
## Styling it
|
||||
|
||||
You can provide styling for both the bar and the button.
|
||||
You can do this using the `style` and `buttonStyle` prop, both of these will append / replace the default style of the component.
|
||||
You can provide styling for the bar, the button and the content. Note that the bar has a `display: flex` property as default and is parent to its children "content" and "button".
|
||||
|
||||
The styling behaves kind of responsive. The minimum content width has been chosen to be "300px" as a default value. If the button does not fit into the same line it is wrapped around into the next line.
|
||||
|
||||
You can style each component by using the `style`, `buttonStyle` and `contentStyle` prop. These will append / replace the default styles of the components.
|
||||
Alternatively you can provide CSS classnames as `containerClasses`, `buttonClasses` and `contentClasses` to apply predefined CSS classes.
|
||||
|
||||
You can use `disableStyles={true}` to disable any built-in styling.
|
||||
|
||||
### Examples
|
||||
|
||||
#### changing the bar background to red
|
||||
#### Changing the bar background to red
|
||||
|
||||
```js
|
||||
<CookieConsent style={{ background: "red" }}></CookieConsent>
|
||||
```
|
||||
|
||||
#### Changing the button font-weight to bold
|
||||
|
||||
```js
|
||||
<CookieConsent buttonStyle={{ fontWeight: "bold" }}></CookieConsent>
|
||||
```
|
||||
|
||||
#### Using predefined CSS classes
|
||||
|
||||
You can pass predefined CSS classes to the components using the `containerClasses`, `buttonClasses` and `contentClasses` props. The example below uses bootstrap classes:
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
style={{ background: "red" }}
|
||||
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>
|
||||
```
|
||||
|
||||
#### changing the button font-weight to bold
|
||||
Which results in:
|
||||
|
||||

|
||||
|
||||
#### Flipping the buttons
|
||||
|
||||
If you enable the decline button you can pass along the "flipButtons" property to turn the buttons around:
|
||||
|
||||
```js
|
||||
<CookieConsent
|
||||
buttonStyle={{ fontWeight: "bold" }}
|
||||
>
|
||||
<CookieConsent enableDeclineButton flipButtons>
|
||||
Flipped buttons
|
||||
</CookieConsent>
|
||||
```
|
||||
|
||||
#### rainbows!
|
||||
Which results in:
|
||||
|
||||

|
||||
|
||||
#### Extra cookie options
|
||||
|
||||
You can add more cookie options using the extraCookieOptions parameter like so:
|
||||
|
||||
```js
|
||||
<CookieConsent extraCookieOptions={{ domain: "myexample.com" }}>cookie bar</CookieConsent>
|
||||
```
|
||||
|
||||
#### Rainbows!
|
||||
|
||||

|
||||
|
||||
@@ -115,28 +259,57 @@ 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>
|
||||
```
|
||||
|
||||
## Debugging it
|
||||
#### Overlay
|
||||
|
||||
Because the cookie consent bar will be hidden once accepted, you will have to remove the cookie if you want to evaluate changes:
|
||||

|
||||
|
||||
You can also generate a page-obfuscating overlay that will prevent actions other than interacting with the cookie consent button(s).
|
||||
|
||||
```js
|
||||
import CookieConsent, { Cookies } from "react-cookie-consent";
|
||||
|
||||
{Cookies.remove("myAwesomeCookieName2")}
|
||||
<CookieConsent
|
||||
cookieName="myAwesomeCookieName2"
|
||||
>
|
||||
<CookieConsent location="bottom" cookieName="myAwesomeCookieName3" expires={999} overlay>
|
||||
This website uses cookies to enhance the user experience.
|
||||
</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
|
||||
[overlaystyle]: https://github.com/Mastermindzh/react-cookie-consent/blob/master/src/index.js#L62-L69
|
||||
|
||||
## Contributor information
|
||||
|
||||
When making a PR please think about the following things:
|
||||
|
||||
- Update the ChangeLog (or include what you did in the PR and I'll add it, up to you)
|
||||
- No need to build or update the package.json. I will do both on release.
|
||||
- Please don't change code convention / style
|
||||
|
||||
## Projects using react-cookie-consent
|
||||
|
||||
The list below features the projects which use react-cookie-consent (that I know off):
|
||||
|
||||
- [bs-react-cookie-consent](https://github.com/ctbucha/bs-react-cookie-consent)
|
||||
- [comicrelief's storybook](https://github.com/comicrelief/storybook)
|
||||
- [inici Gatsby theme](https://github.com/kuworking/gatsby-theme-kuworking-core)
|
||||
- [Scrivito Example App](https://github.com/Scrivito/scrivito_example_app_js)
|
||||
|
54
build/index.d.ts
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as React from "react";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
export interface CookieConsentProps {
|
||||
location?: "top" | "bottom" | "none";
|
||||
sameSite?: "strict" | "lax" | "none";
|
||||
cookieSecurity?: boolean;
|
||||
style?: object;
|
||||
buttonStyle?: object;
|
||||
declineButtonStyle?: object;
|
||||
contentStyle?: object;
|
||||
children?: React.ReactNode;
|
||||
disableStyles?: boolean;
|
||||
hideOnAccept?: boolean;
|
||||
onAccept?: Function;
|
||||
onDecline?: Function;
|
||||
buttonText?: Function | React.ReactNode;
|
||||
declineButtonText?: Function | React.ReactNode;
|
||||
cookieName?: string;
|
||||
cookieValue?: string | boolean | number;
|
||||
declineCookieValue?: string | boolean | number;
|
||||
setDeclineCookie?: boolean;
|
||||
debug?: boolean;
|
||||
expires?: number;
|
||||
containerClasses?: string;
|
||||
contentClasses?: string;
|
||||
buttonWrapperClasses?: string;
|
||||
buttonClasses?: string;
|
||||
declineButtonClasses?: string;
|
||||
buttonId?: string;
|
||||
declineButtonId?: string;
|
||||
extraCookieOptions?: object;
|
||||
disableButtonStyles?: boolean;
|
||||
enableDeclineButton?: boolean;
|
||||
flipButtons?: boolean;
|
||||
ButtonComponent?: React.ElementType;
|
||||
overlay?: boolean;
|
||||
overlayClasses?: string;
|
||||
overlayStyle?: object;
|
||||
ariaAcceptLabel?: string;
|
||||
ariaDeclineLabel?: string;
|
||||
}
|
||||
|
||||
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {}
|
||||
|
||||
/**
|
||||
* Returns the value of the consent cookie
|
||||
* Retrieves the regular value first and if not found the legacy one according
|
||||
* to: https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients
|
||||
* @param {*} name optional name of the cookie
|
||||
*/
|
||||
export function getCookieConsentValue(name?: string): string;
|
||||
|
||||
export { Cookies };
|
2299
build/index.js
21
example/.gitignore
vendored
@@ -1,21 +0,0 @@
|
||||
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
2433
example/README.md
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "example",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"react": "^16.2.0",
|
||||
"react-cookie-consent": "^1.0.5",
|
||||
"react-dom": "^16.2.0",
|
||||
"react-scripts": "1.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test --env=jsdom",
|
||||
"eject": "react-scripts eject"
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 3.8 KiB |
@@ -1,40 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="theme-color" content="#000000">
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is added to the
|
||||
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
You need to enable JavaScript to run this app.
|
||||
</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
}
|
||||
],
|
||||
"start_url": "./index.html",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #222;
|
||||
height: 150px;
|
||||
padding: 20px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-title {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.App-intro {
|
||||
font-size: large;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
import CookieConsent, { Cookies } from "react-cookie-consent";
|
||||
|
||||
class App extends Component {
|
||||
|
||||
render() {
|
||||
|
||||
Cookies.set("test", "nice")
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<h1 className="App-title">Welcome to React</h1>
|
||||
</header>
|
||||
<p className="App-intro">
|
||||
To get started, edit <code>src/App.js</code> and save to reload.
|
||||
</p>
|
||||
<CookieConsent
|
||||
onAccept={() => {alert("yay!")}}
|
||||
>
|
||||
This website uses cookies to enhance the user experience.{" "}
|
||||
<span style={{ fontSize: "10px" }}>
|
||||
This bit of text is smaller :O
|
||||
</span>
|
||||
</CookieConsent>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
@@ -1,9 +0,0 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import App from './App';
|
||||
|
||||
it('renders without crashing', () => {
|
||||
const div = document.createElement('div');
|
||||
ReactDOM.render(<App />, div);
|
||||
ReactDOM.unmountComponentAtNode(div);
|
||||
});
|
@@ -1,5 +0,0 @@
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: sans-serif;
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import registerServiceWorker from './registerServiceWorker';
|
||||
|
||||
ReactDOM.render(<App />, document.getElementById('root'));
|
||||
registerServiceWorker();
|
@@ -1,7 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
|
||||
<g fill="#61DAFB">
|
||||
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
|
||||
<circle cx="420.9" cy="296.5" r="45.7"/>
|
||||
<path d="M520.5 78.1z"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 2.6 KiB |
@@ -1,117 +0,0 @@
|
||||
// In production, we register a service worker to serve assets from local cache.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on the "N+1" visit to a page, since previously
|
||||
// cached resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
|
||||
// This link also includes instructions on opting out of this behavior.
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.1/8 is considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
|
||||
export default function register() {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Lets check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://goo.gl/SC7cgQ'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not local host. Just register service worker
|
||||
registerValidSW(swUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the old content will have been purged and
|
||||
// the fresh content will have been added to the cache.
|
||||
// It's the perfect time to display a "New content is
|
||||
// available; please refresh." message in your web app.
|
||||
console.log('New content is available; please refresh.');
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl)
|
||||
.then(response => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
if (
|
||||
response.status === 404 ||
|
||||
response.headers.get('content-type').indexOf('javascript') === -1
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister();
|
||||
});
|
||||
}
|
||||
}
|
6640
example/yarn.lock
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 14 KiB |
BIN
images/css_classes.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
images/flipped.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
images/overlay.png
Normal file
After Width: | Height: | Size: 25 KiB |
6321
package-lock.json
generated
Normal file
57
package.json
@@ -4,15 +4,28 @@
|
||||
"name": "Rick van Lieshout",
|
||||
"email": "info@rickvanlieshout.com"
|
||||
},
|
||||
"version": "1.0.8",
|
||||
"version": "6.2.2",
|
||||
"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",
|
||||
"react": "^15.5.4"
|
||||
"js-cookie": "^2.2.1",
|
||||
"prop-types": "^15.7.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.13.1 || ^17.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "webpack"
|
||||
"build": "webpack",
|
||||
"prettier": "prettier 'src/**/*.{js*,ts*,htm*,md,scss}' --write",
|
||||
"patch": "npm --no-git-tag-version version patch",
|
||||
"minor": "npm --no-git-tag-version version minor",
|
||||
"major": "npm --no-git-tag-version version major",
|
||||
"preversion": "grep \"\\[$npm_package_version\\]\" CHANGELOG.md > /dev/null || ( echo 'You need to add an entry in CHANGELOG.md for this version.' && false )",
|
||||
"release": "npm run build && git add -A && git tag $npm_package_version && git commit -m 'release $npm_package_version' && git push && git push --tags && npm publish",
|
||||
"release-patch": "npm run patch && npm run release",
|
||||
"release-minor": "npm run minor && npm run release",
|
||||
"release-major": "npm run major && npm run release"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -30,14 +43,32 @@
|
||||
},
|
||||
"homepage": "https://github.com/Mastermindzh/react-cookie-consent#readme",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-core": "^6.24.1",
|
||||
"babel-loader": "^7.0.0",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.23.0",
|
||||
"babel-plugin-transform-react-jsx": "^6.24.1",
|
||||
"babel-preset-env": "^1.5.1",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"babel-preset-stage-1": "^6.24.1",
|
||||
"webpack": "^2.6.1"
|
||||
"@babel/cli": "^7.12.1",
|
||||
"@babel/core": "^7.12.3",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
|
||||
"@babel/plugin-transform-object-assign": "^7.12.1",
|
||||
"@babel/plugin-transform-react-jsx": "^7.12.1",
|
||||
"@babel/preset-env": "^7.12.1",
|
||||
"@mastermindzh/prettier-config": "^1.0.0",
|
||||
"@types/js-cookie": "^2.2.6",
|
||||
"babel-loader": "^8.1.0",
|
||||
"copy-webpack-plugin": "^6.2.1",
|
||||
"husky": "^4.3.0",
|
||||
"lint-staged": "^10.5.1",
|
||||
"prettier": "^2.1.2",
|
||||
"react": "^16.13.1",
|
||||
"webpack": "^5.3.2",
|
||||
"webpack-cli": "^4.1.0"
|
||||
},
|
||||
"prettier": "@mastermindzh/prettier-config",
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged --allow-empty"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js*,ts*,htm*,md,scss}": [
|
||||
"prettier --write"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
54
src/index.d.ts
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as React from "react";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
export interface CookieConsentProps {
|
||||
location?: "top" | "bottom" | "none";
|
||||
sameSite?: "strict" | "lax" | "none";
|
||||
cookieSecurity?: boolean;
|
||||
style?: object;
|
||||
buttonStyle?: object;
|
||||
declineButtonStyle?: object;
|
||||
contentStyle?: object;
|
||||
children?: React.ReactNode;
|
||||
disableStyles?: boolean;
|
||||
hideOnAccept?: boolean;
|
||||
onAccept?: Function;
|
||||
onDecline?: Function;
|
||||
buttonText?: Function | React.ReactNode;
|
||||
declineButtonText?: Function | React.ReactNode;
|
||||
cookieName?: string;
|
||||
cookieValue?: string | boolean | number;
|
||||
declineCookieValue?: string | boolean | number;
|
||||
setDeclineCookie?: boolean;
|
||||
debug?: boolean;
|
||||
expires?: number;
|
||||
containerClasses?: string;
|
||||
contentClasses?: string;
|
||||
buttonWrapperClasses?: string;
|
||||
buttonClasses?: string;
|
||||
declineButtonClasses?: string;
|
||||
buttonId?: string;
|
||||
declineButtonId?: string;
|
||||
extraCookieOptions?: object;
|
||||
disableButtonStyles?: boolean;
|
||||
enableDeclineButton?: boolean;
|
||||
flipButtons?: boolean;
|
||||
ButtonComponent?: React.ElementType;
|
||||
overlay?: boolean;
|
||||
overlayClasses?: string;
|
||||
overlayStyle?: object;
|
||||
ariaAcceptLabel?: string;
|
||||
ariaDeclineLabel?: string;
|
||||
}
|
||||
|
||||
export default class CookieConsent extends React.Component<CookieConsentProps, {}> {}
|
||||
|
||||
/**
|
||||
* Returns the value of the consent cookie
|
||||
* Retrieves the regular value first and if not found the legacy one according
|
||||
* to: https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients
|
||||
* @param {*} name optional name of the cookie
|
||||
*/
|
||||
export function getCookieConsentValue(name?: string): string;
|
||||
|
||||
export { Cookies };
|
369
src/index.js
@@ -4,60 +4,194 @@ import Cookies from "js-cookie";
|
||||
|
||||
export const OPTIONS = {
|
||||
TOP: "top",
|
||||
BOTTOM: "bottom"
|
||||
BOTTOM: "bottom",
|
||||
NONE: "none",
|
||||
};
|
||||
|
||||
export const SAME_SITE_OPTIONS = {
|
||||
STRICT: "strict",
|
||||
LAX: "lax",
|
||||
NONE: "none",
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the value of the consent cookie
|
||||
* Retrieves the regular value first and if not found the legacy one according
|
||||
* to: https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients
|
||||
* @param {*} name optional name of the cookie
|
||||
*/
|
||||
export const getCookieConsentValue = (name = defaultCookieConsentName) => {
|
||||
let cookieValue = Cookies.get(name);
|
||||
|
||||
// if the cookieValue is undefined check for the legacy cookie
|
||||
if (cookieValue === undefined) {
|
||||
cookieValue = Cookies.get(getLegacyCookieName(name));
|
||||
}
|
||||
return cookieValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the legacy cookie name by the regular cookie name
|
||||
* @param {string} name of cookie to get
|
||||
*/
|
||||
const getLegacyCookieName = (name) => {
|
||||
return `${name}-legacy`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Default name of the cookie which is set by CookieConsent
|
||||
*/
|
||||
const defaultCookieConsentName = "CookieConsent";
|
||||
|
||||
/**
|
||||
* A function to wrap elements with a "wrapper" on a condition
|
||||
* @param {object} wrappingOptions
|
||||
* condition == boolean condition, when to wrap
|
||||
* wrapper == style to wrap. e.g <div>{children}</div>
|
||||
* children == react passes whatever is between tags as children. Don't supply this yourself.
|
||||
*/
|
||||
const ConditionalWrapper = ({ condition, wrapper, children }) => {
|
||||
return condition ? wrapper(children) : children;
|
||||
};
|
||||
|
||||
class CookieConsent extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.accept.bind(this);
|
||||
|
||||
this.state = {
|
||||
visible: true,
|
||||
visible: false,
|
||||
style: {
|
||||
position: "fixed",
|
||||
width: "100%",
|
||||
padding: "15px",
|
||||
alignItems: "baseline",
|
||||
background: "#353535",
|
||||
color: "white",
|
||||
display: "flex",
|
||||
flexWrap: "wrap",
|
||||
justifyContent: "space-between",
|
||||
left: "0",
|
||||
position: "fixed",
|
||||
width: "100%",
|
||||
zIndex: "999",
|
||||
lineHeight: "30px",
|
||||
textAlign: "left"
|
||||
},
|
||||
buttonStyle: {
|
||||
position: "absolute",
|
||||
right: "50px",
|
||||
border: "0",
|
||||
background: "#ffd42d",
|
||||
boxShadow: "none",
|
||||
border: "0",
|
||||
borderRadius: "0px",
|
||||
padding: "5px",
|
||||
color: "black"
|
||||
}
|
||||
boxShadow: "none",
|
||||
color: "black",
|
||||
cursor: "pointer",
|
||||
flex: "0 0 auto",
|
||||
padding: "5px 10px",
|
||||
margin: "15px",
|
||||
},
|
||||
declineButtonStyle: {
|
||||
background: "#c12a2a",
|
||||
border: "0",
|
||||
borderRadius: "0px",
|
||||
boxShadow: "none",
|
||||
color: "#e5e5e5",
|
||||
cursor: "pointer",
|
||||
flex: "0 0 auto",
|
||||
padding: "5px 10px",
|
||||
margin: "15px",
|
||||
},
|
||||
contentStyle: {
|
||||
flex: "1 0 300px",
|
||||
margin: "15px",
|
||||
},
|
||||
overlayStyle: {
|
||||
position: "fixed",
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
zIndex: "999",
|
||||
backgroundColor: "rgba(0,0,0,0.3)",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
componentWillMount(){
|
||||
const { cookieName } = this.props;
|
||||
componentDidMount() {
|
||||
const { debug } = this.props;
|
||||
|
||||
if (Cookies.get(cookieName) != undefined ) {
|
||||
// if cookie undefined or debug
|
||||
if (this.getCookieValue() === undefined || debug) {
|
||||
this.setState({ visible: true });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a persistent accept cookie
|
||||
*/
|
||||
accept() {
|
||||
const { cookieName, cookieValue, hideOnAccept, onAccept } = this.props;
|
||||
|
||||
this.setCookie(cookieName, cookieValue);
|
||||
|
||||
onAccept();
|
||||
|
||||
if (hideOnAccept) {
|
||||
this.setState({ visible: false });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a persistent cookie
|
||||
* Set a persistent decline cookie
|
||||
*/
|
||||
accept() {
|
||||
const { cookieName } = this.props;
|
||||
decline() {
|
||||
const {
|
||||
cookieName,
|
||||
declineCookieValue,
|
||||
hideOnDecline,
|
||||
onDecline,
|
||||
setDeclineCookie,
|
||||
} = this.props;
|
||||
|
||||
Cookies.set(cookieName, true);
|
||||
this.setState({ visible: false });
|
||||
if (setDeclineCookie) {
|
||||
this.setCookie(cookieName, declineCookieValue);
|
||||
}
|
||||
|
||||
onDecline();
|
||||
|
||||
if (hideOnDecline) {
|
||||
this.setState({ visible: false });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to set the consent cookie based on the provided variables
|
||||
* Sets two cookies to handle incompatible browsers, more details:
|
||||
* https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients
|
||||
*/
|
||||
setCookie(cookieName, cookieValue) {
|
||||
const { extraCookieOptions, expires, sameSite } = this.props;
|
||||
let { cookieSecurity } = this.props;
|
||||
|
||||
if (cookieSecurity === undefined) {
|
||||
cookieSecurity = location ? location.protocol === "https:" : true;
|
||||
}
|
||||
|
||||
let cookieOptions = { expires, ...extraCookieOptions, sameSite, secure: cookieSecurity };
|
||||
|
||||
// Fallback for older browsers where can not set SameSite=None, SEE: https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients
|
||||
if (sameSite === SAME_SITE_OPTIONS.NONE) {
|
||||
Cookies.set(getLegacyCookieName(cookieName), cookieValue, cookieOptions);
|
||||
}
|
||||
|
||||
// set the regular cookie
|
||||
Cookies.set(cookieName, cookieValue, cookieOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the consent cookie
|
||||
* Retrieves the regular value first and if not found the legacy one according
|
||||
* to: https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients
|
||||
*/
|
||||
getCookieValue() {
|
||||
const { cookieName } = this.props;
|
||||
return getCookieConsentValue(cookieName);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
// If the bar shouldn't be visible don't render anything.
|
||||
if (!this.state.visible) {
|
||||
return null;
|
||||
@@ -67,25 +201,59 @@ class CookieConsent extends Component {
|
||||
location,
|
||||
style,
|
||||
buttonStyle,
|
||||
declineButtonStyle,
|
||||
contentStyle,
|
||||
disableStyles,
|
||||
onAccept,
|
||||
buttonText
|
||||
buttonText,
|
||||
declineButtonText,
|
||||
containerClasses,
|
||||
contentClasses,
|
||||
buttonClasses,
|
||||
buttonWrapperClasses,
|
||||
declineButtonClasses,
|
||||
buttonId,
|
||||
declineButtonId,
|
||||
disableButtonStyles,
|
||||
enableDeclineButton,
|
||||
flipButtons,
|
||||
ButtonComponent,
|
||||
overlay,
|
||||
overlayClasses,
|
||||
overlayStyle,
|
||||
ariaAcceptLabel,
|
||||
ariaDeclineLabel,
|
||||
} = this.props;
|
||||
|
||||
let myStyle = {},
|
||||
myButtonStyle = {};
|
||||
let myStyle = {};
|
||||
let myButtonStyle = {};
|
||||
let myDeclineButtonStyle = {};
|
||||
let myContentStyle = {};
|
||||
let myOverlayStyle = {};
|
||||
|
||||
if (disableStyles) {
|
||||
// if styles are disabled use the provided styles (or non)
|
||||
// if styles are disabled use the provided styles (or none)
|
||||
myStyle = Object.assign({}, style);
|
||||
myButtonStyle = Object.assign({}, buttonStyle);
|
||||
myDeclineButtonStyle = Object.assign({}, declineButtonStyle);
|
||||
myContentStyle = Object.assign({}, contentStyle);
|
||||
myOverlayStyle = Object.assign({}, overlayStyle);
|
||||
} else {
|
||||
// if styles aren't disabled merge them with the styles that are provided (or use default styles)
|
||||
myStyle = Object.assign({}, { ...this.state.style, ...style });
|
||||
myButtonStyle = Object.assign(
|
||||
{},
|
||||
{ ...this.state.buttonStyle, ...buttonStyle }
|
||||
);
|
||||
myContentStyle = Object.assign({}, { ...this.state.contentStyle, ...contentStyle });
|
||||
myOverlayStyle = Object.assign({}, { ...this.state.overlayStyle, ...overlayStyle });
|
||||
|
||||
// switch to disable JUST the button styles
|
||||
if (disableButtonStyles) {
|
||||
myButtonStyle = Object.assign({}, buttonStyle);
|
||||
myDeclineButtonStyle = Object.assign({}, declineButtonStyle);
|
||||
} else {
|
||||
myButtonStyle = Object.assign({}, { ...this.state.buttonStyle, ...buttonStyle });
|
||||
myDeclineButtonStyle = Object.assign(
|
||||
{},
|
||||
{ ...this.state.declineButtonStyle, ...declineButtonStyle }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// syntactic sugar to enable user to easily select top / bottom
|
||||
@@ -99,40 +267,143 @@ class CookieConsent extends Component {
|
||||
break;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="cookieConsent" style={myStyle}>
|
||||
{this.props.children}
|
||||
<button
|
||||
style={myButtonStyle}
|
||||
const buttonsToRender = [];
|
||||
|
||||
// add decline button
|
||||
enableDeclineButton &&
|
||||
buttonsToRender.push(
|
||||
<ButtonComponent
|
||||
key="declineButton"
|
||||
style={myDeclineButtonStyle}
|
||||
className={declineButtonClasses}
|
||||
id={declineButtonId}
|
||||
aria-label={ariaDeclineLabel}
|
||||
onClick={() => {
|
||||
this.accept();
|
||||
onAccept();
|
||||
this.decline();
|
||||
}}
|
||||
>
|
||||
{buttonText}
|
||||
</button>
|
||||
</div>
|
||||
{declineButtonText}
|
||||
</ButtonComponent>
|
||||
);
|
||||
|
||||
// add accept button
|
||||
buttonsToRender.push(
|
||||
<ButtonComponent
|
||||
key="acceptButton"
|
||||
style={myButtonStyle}
|
||||
className={buttonClasses}
|
||||
id={buttonId}
|
||||
aria-label={ariaAcceptLabel}
|
||||
onClick={() => {
|
||||
this.accept();
|
||||
}}
|
||||
>
|
||||
{buttonText}
|
||||
</ButtonComponent>
|
||||
);
|
||||
|
||||
if (flipButtons) {
|
||||
buttonsToRender.reverse();
|
||||
}
|
||||
|
||||
return (
|
||||
<ConditionalWrapper
|
||||
condition={overlay}
|
||||
wrapper={(children) => (
|
||||
<div style={myOverlayStyle} className={overlayClasses}>
|
||||
{children}
|
||||
</div>
|
||||
)}
|
||||
>
|
||||
<div className={`${containerClasses}`} style={myStyle}>
|
||||
<div style={myContentStyle} className={contentClasses}>
|
||||
{this.props.children}
|
||||
</div>
|
||||
<div className={`${buttonWrapperClasses}`}>
|
||||
{buttonsToRender.map((button) => {
|
||||
return button;
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</ConditionalWrapper>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
CookieConsent.propTypes = {
|
||||
location: PropTypes.oneOf(["top", "bottom"]),
|
||||
location: PropTypes.oneOf(Object.keys(OPTIONS).map((key) => OPTIONS[key])),
|
||||
sameSite: PropTypes.oneOf(Object.keys(SAME_SITE_OPTIONS).map((key) => SAME_SITE_OPTIONS[key])),
|
||||
style: PropTypes.object,
|
||||
buttonStyle: PropTypes.object,
|
||||
declineButtonStyle: PropTypes.object,
|
||||
contentStyle: PropTypes.object,
|
||||
children: PropTypes.any, // eslint-disable-line react/forbid-prop-types
|
||||
disableStyles: PropTypes.bool,
|
||||
hideOnAccept: PropTypes.bool,
|
||||
hideOnDecline: PropTypes.bool,
|
||||
onAccept: PropTypes.func,
|
||||
buttonText: PropTypes.oneOfType([PropTypes.string,PropTypes.func,PropTypes.element]),
|
||||
cookieName: PropTypes.string
|
||||
onDecline: PropTypes.func,
|
||||
buttonText: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.element]),
|
||||
declineButtonText: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.element]),
|
||||
cookieName: PropTypes.string,
|
||||
cookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
||||
declineCookieValue: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.number]),
|
||||
setDeclineCookie: PropTypes.bool,
|
||||
debug: PropTypes.bool,
|
||||
expires: PropTypes.number,
|
||||
containerClasses: PropTypes.string,
|
||||
contentClasses: PropTypes.string,
|
||||
buttonClasses: PropTypes.string,
|
||||
buttonWrapperClasses: PropTypes.string,
|
||||
declineButtonClasses: PropTypes.string,
|
||||
buttonId: PropTypes.string,
|
||||
declineButtonId: PropTypes.string,
|
||||
extraCookieOptions: PropTypes.object,
|
||||
disableButtonStyles: PropTypes.bool,
|
||||
enableDeclineButton: PropTypes.bool,
|
||||
flipButtons: PropTypes.bool,
|
||||
ButtonComponent: PropTypes.elementType,
|
||||
cookieSecurity: PropTypes.bool,
|
||||
overlay: PropTypes.bool,
|
||||
overlayClasses: PropTypes.string,
|
||||
overlayStyle: PropTypes.object,
|
||||
ariaAcceptLabel: PropTypes.string,
|
||||
ariaDeclineLabel: PropTypes.string,
|
||||
};
|
||||
|
||||
CookieConsent.defaultProps = {
|
||||
disableStyles: false,
|
||||
hideOnAccept: true,
|
||||
hideOnDecline: true,
|
||||
location: OPTIONS.BOTTOM,
|
||||
onAccept: () => {},
|
||||
cookieName: "CookieConsent",
|
||||
buttonText: "I understand"
|
||||
onDecline: () => {},
|
||||
cookieName: defaultCookieConsentName,
|
||||
cookieValue: true,
|
||||
declineCookieValue: false,
|
||||
setDeclineCookie: true,
|
||||
buttonText: "I understand",
|
||||
declineButtonText: "I decline",
|
||||
debug: false,
|
||||
expires: 365,
|
||||
containerClasses: "CookieConsent",
|
||||
contentClasses: "",
|
||||
buttonClasses: "",
|
||||
buttonWrapperClasses: "",
|
||||
declineButtonClasses: "",
|
||||
buttonId: "rcc-confirm-button",
|
||||
declineButtonId: "rcc-decline-button",
|
||||
extraCookieOptions: {},
|
||||
disableButtonStyles: false,
|
||||
enableDeclineButton: false,
|
||||
flipButtons: false,
|
||||
sameSite: SAME_SITE_OPTIONS.LAX,
|
||||
ButtonComponent: ({ children, ...props }) => <button {...props}>{children}</button>,
|
||||
overlay: false,
|
||||
overlayClasses: "",
|
||||
ariaAcceptLabel: "Accept cookies",
|
||||
ariaDeclineLabel: "Decline cookies",
|
||||
};
|
||||
|
||||
export default CookieConsent;
|
||||
export {Cookies};
|
||||
export { Cookies };
|
||||
|
17
stale.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 30
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 2
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- good first issue
|
||||
- security
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: stale
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: false
|
@@ -1,27 +1,33 @@
|
||||
var path = require('path');
|
||||
var path = require("path");
|
||||
var CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
|
||||
module.exports = {
|
||||
entry: './src/index.js',
|
||||
entry: "./src/index.js",
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'build'),
|
||||
filename: 'index.js',
|
||||
libraryTarget: 'commonjs2' // THIS IS THE MOST IMPORTANT LINE! :mindblow: I wasted more than 2 days until realize this was the line most important in all this guide.
|
||||
path: path.resolve(__dirname, "build"),
|
||||
filename: "index.js",
|
||||
libraryTarget: "commonjs2", // THIS IS THE MOST IMPORTANT LINE! :mindblow: I wasted more than 2 days until realize this was the line most important in all this guide.
|
||||
environment: {
|
||||
arrowFunction: false, // the generated runtime-code should not use arrow functions
|
||||
},
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
include: path.resolve(__dirname, 'src'),
|
||||
include: path.resolve(__dirname, "src"),
|
||||
exclude: /(node_modules|bower_components|build)/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
loader: "babel-loader",
|
||||
options: {
|
||||
presets: ['env']
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
presets: ["@babel/preset-env"],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
externals: {
|
||||
'react': 'commonjs react' // this line is just to use the React dependency of our parent-testing-project instead of using our own React.
|
||||
}
|
||||
};
|
||||
react: "commonjs react", // this line is just to use the React dependency of our parent-testing-project instead of using our own React.
|
||||
},
|
||||
plugins: [new CopyWebpackPlugin({ patterns: [{ from: "src/index.d.ts", to: "index.d.ts" }] })],
|
||||
};
|
||||
|