mirror of
				https://github.com/Mastermindzh/react-cookie-consent.git
				synced 2025-10-31 08:49:04 +01:00 
			
		
		
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			7f5989a539
			...
			a5f421b8bc
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a5f421b8bc | |||
| 7937a90662 | 
							
								
								
									
										6
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | { | ||||||
|  |     "sonarlint.connectedMode.project": { | ||||||
|  |         "connectionId": "public-sonarcloud", | ||||||
|  |         "projectKey": "Mastermindzh_react-cookie-consent" | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -5,6 +5,11 @@ 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/), | 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). | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||||||
|  |  | ||||||
|  | ## [[9.0.0]((https://github.com/Mastermindzh/react-cookie-consent/releases/tag/9.0.0)] | ||||||
|  |  | ||||||
|  | Made all props optional and fixed documentation. | ||||||
|  | Fixes [#191](https://github.com/Mastermindzh/react-cookie-consent/issues/191) and [#193](https://github.com/Mastermindzh/react-cookie-consent/issues/193) | ||||||
|  |  | ||||||
| ## [[8.0.1]((https://github.com/Mastermindzh/react-cookie-consent/releases/tag/8.0.1)] | ## [[8.0.1]((https://github.com/Mastermindzh/react-cookie-consent/releases/tag/8.0.1)] | ||||||
|  |  | ||||||
| ~~Second try of [np](https://github.com/sindresorhus/np)...~~ | ~~Second try of [np](https://github.com/sindresorhus/np)...~~ | ||||||
| @@ -16,7 +21,7 @@ np is not my thing.. reverted to old release strategy | |||||||
| - Switched to tsdx and Typescript | - Switched to tsdx and Typescript | ||||||
| - Added storybook with examples from readme | - Added storybook with examples from readme | ||||||
|  |  | ||||||
| ## [[7.6.0]](https://github.com/Mastermindzh/react-cookie-consent/releases/tag/7.6.0] | ## [[7.6.0]](<https://github.com/Mastermindzh/react-cookie-consent/releases/tag/7.6.0>] | ||||||
|  |  | ||||||
| - Added `customButtonWrapperAttributes` prop which allows to add custom attributes to the button wrapper div | - Added `customButtonWrapperAttributes` prop which allows to add custom attributes to the button wrapper div | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										46
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								README.md
									
									
									
									
									
								
							| @@ -4,7 +4,7 @@ A small, simple and customizable cookie consent bar for use in React application | |||||||
|  |  | ||||||
| [](https://npmjs.org/package/react-cookie-consent) | [](https://npmjs.org/package/react-cookie-consent) | ||||||
|  |  | ||||||
| Demo (storybook): https://mastermindzh.github.io/react-cookie-consent/ | Demo (storybook): <https://mastermindzh.github.io/react-cookie-consent/> | ||||||
|  |  | ||||||
|       |       | ||||||
|  |  | ||||||
| @@ -16,24 +16,28 @@ Demo (storybook): https://mastermindzh.github.io/react-cookie-consent/ | |||||||
|  |  | ||||||
| <!-- toc --> | <!-- toc --> | ||||||
|  |  | ||||||
| - [Installation](#installation) | - [:cookie: react-cookie-consent :cookie:](#cookie-react-cookie-consent-cookie) | ||||||
| - [Using it](#using-it) |   - [Default look](#default-look) | ||||||
|   - [getting the cookies value in your own code](#getting-the-cookies-value-in-your-own-code) |   - [Table of contents](#table-of-contents) | ||||||
| - [Props](#props) |   - [Installation](#installation) | ||||||
| - [Debugging it](#debugging-it) |   - [Using it](#using-it) | ||||||
| - [Why are there two cookies? One of which named "Legacy"](#why-are-there-two-cookies-one-of-which-named-legacy) |     - [getting the cookies value in your own code](#getting-the-cookies-value-in-your-own-code) | ||||||
| - [Styling it](#styling-it) |     - [reset the cookies value in your own code](#reset-the-cookies-value-in-your-own-code) | ||||||
|   - [Examples](#examples) |   - [Props](#props) | ||||||
|     - [Changing the bar background to red](#changing-the-bar-background-to-red) |   - [Debugging it](#debugging-it) | ||||||
|     - [Changing the button font-weight to bold](#changing-the-button-font-weight-to-bold) |   - [Why are there two cookies? One of which named "Legacy"](#why-are-there-two-cookies-one-of-which-named-legacy) | ||||||
|     - [Using predefined CSS classes](#using-predefined-css-classes) |   - [Styling it](#styling-it) | ||||||
|     - [Accept on scroll](#accept-on-scroll) |     - [Examples](#examples) | ||||||
|     - [Flipping the buttons](#flipping-the-buttons) |       - [Changing the bar background to red](#changing-the-bar-background-to-red) | ||||||
|     - [Extra cookie options](#extra-cookie-options) |       - [Changing the button font-weight to bold](#changing-the-button-font-weight-to-bold) | ||||||
|     - [Rainbows!](#rainbows) |       - [Using predefined CSS classes](#using-predefined-css-classes) | ||||||
|     - [Overlay](#overlay) |       - [Accept on scroll](#accept-on-scroll) | ||||||
| - [Contributor information](#contributor-information) |       - [Flipping the buttons](#flipping-the-buttons) | ||||||
| - [Projects using react-cookie-consent](#projects-using-react-cookie-consent) |       - [Extra cookie options](#extra-cookie-options) | ||||||
|  |       - [Rainbows](#rainbows) | ||||||
|  |       - [Overlay](#overlay) | ||||||
|  |   - [Contributor information](#contributor-information) | ||||||
|  |   - [Projects using react-cookie-consent](#projects-using-react-cookie-consent) | ||||||
|  |  | ||||||
| <!-- tocstop --> | <!-- tocstop --> | ||||||
|  |  | ||||||
| @@ -113,12 +117,12 @@ If the decline button is enabled then the (onDecline) prop function can be used, | |||||||
|  |  | ||||||
| ### getting the cookies value in your own code | ### 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: | react-cookie-consent exports a function called `getCookieConsentValue(cookieName: string)`. You can use it in your own code like so: | ||||||
|  |  | ||||||
| ```js | ```js | ||||||
| import CookieConsent, { Cookies, getCookieConsentValue } from "react-cookie-consent"; | import CookieConsent, { Cookies, getCookieConsentValue } from "react-cookie-consent"; | ||||||
|  |  | ||||||
| console.log(getCookieConsentValue()); | console.log(getCookieConsentValue("your_custom_cookie_name")); | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| ### reset the cookies value in your own code | ### reset the cookies value in your own code | ||||||
|   | |||||||
							
								
								
									
										5747
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										5747
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "react-cookie-consent", |   "name": "react-cookie-consent", | ||||||
|   "version": "8.0.1", |   "version": "9.0.0", | ||||||
|   "description": "A small, simple and customizable cookie consent bar for use in React applications.", |   "description": "A small, simple and customizable cookie consent bar for use in React applications.", | ||||||
|   "keywords": [ |   "keywords": [ | ||||||
|     "react", |     "react", | ||||||
|   | |||||||
| @@ -8,54 +8,54 @@ import { | |||||||
|  |  | ||||||
| export interface CookieConsentProps { | export interface CookieConsentProps { | ||||||
|   children?: ReactNode; |   children?: ReactNode; | ||||||
|   style: React.CSSProperties; |   style?: React.CSSProperties; | ||||||
|   buttonStyle: React.CSSProperties; |   buttonStyle?: React.CSSProperties; | ||||||
|   declineButtonStyle: React.CSSProperties; |   declineButtonStyle?: React.CSSProperties; | ||||||
|   contentStyle: React.CSSProperties; |   contentStyle?: React.CSSProperties; | ||||||
|   disableStyles: boolean; |   disableStyles?: boolean; | ||||||
|   hideOnAccept: boolean; |   hideOnAccept?: boolean; | ||||||
|   hideOnDecline: boolean; |   hideOnDecline?: boolean; | ||||||
|   onAccept: (acceptedByScrolling: boolean) => void; |   onAccept?: (acceptedByScrolling: boolean) => void; | ||||||
|   onDecline: () => void; |   onDecline?: () => void; | ||||||
|   buttonText: string | ReactNode | Function; |   buttonText?: string | ReactNode | Function; | ||||||
|   declineButtonText: string | ReactNode | Function; |   declineButtonText?: string | ReactNode | Function; | ||||||
|   cookieName: string; |   cookieName?: string; | ||||||
|   cookieValue: string | object; |   cookieValue?: string | object; | ||||||
|   declineCookieValue: string | object; |   declineCookieValue?: string | object; | ||||||
|   setDeclineCookie: boolean; |   setDeclineCookie?: boolean; | ||||||
|   debug: boolean; |   debug?: boolean; | ||||||
|   expires: number; |   expires?: number; | ||||||
|   containerClasses: string; |   containerClasses?: string; | ||||||
|   contentClasses: string; |   contentClasses?: string; | ||||||
|   buttonClasses: string; |   buttonClasses?: string; | ||||||
|   buttonWrapperClasses: string; |   buttonWrapperClasses?: string; | ||||||
|   declineButtonClasses: string; |   declineButtonClasses?: string; | ||||||
|   buttonId: string; |   buttonId?: string; | ||||||
|   declineButtonId: string; |   declineButtonId?: string; | ||||||
|   overlayClasses: string; |   overlayClasses?: string; | ||||||
|   ariaAcceptLabel: string; |   ariaAcceptLabel?: string; | ||||||
|   ariaDeclineLabel: string; |   ariaDeclineLabel?: string; | ||||||
|   disableButtonStyles: boolean; |   disableButtonStyles?: boolean; | ||||||
|   enableDeclineButton: boolean; |   enableDeclineButton?: boolean; | ||||||
|   flipButtons: boolean; |   flipButtons?: boolean; | ||||||
|   cookieSecurity?: boolean; |   cookieSecurity?: boolean; | ||||||
|   overlay: boolean; |   overlay?: boolean; | ||||||
|   acceptOnOverlayClick: boolean; |   acceptOnOverlayClick?: boolean; | ||||||
|   acceptOnScroll: boolean; |   acceptOnScroll?: boolean; | ||||||
|   acceptOnScrollPercentage: number; |   acceptOnScrollPercentage?: number; | ||||||
|   ButtonComponent: any; |   ButtonComponent?: any; | ||||||
|   extraCookieOptions: Object; |   extraCookieOptions?: Object; | ||||||
|   overlayStyle: Object; |   overlayStyle?: Object; | ||||||
|   customContentAttributes: Object; |   customContentAttributes?: Object; | ||||||
|   customContainerAttributes: Object; |   customContainerAttributes?: Object; | ||||||
|   customButtonProps: Object; |   customButtonProps?: Object; | ||||||
|   customDeclineButtonProps: Object; |   customDeclineButtonProps?: Object; | ||||||
|   customButtonWrapperAttributes: Object; |   customButtonWrapperAttributes?: Object; | ||||||
|   onOverlayClick: () => void; |   onOverlayClick?: () => void; | ||||||
|   // these should be enums |   // these should be enums | ||||||
|   location: string; |   location?: string; | ||||||
|   visible: string; |   visible?: string; | ||||||
|   sameSite: "strict" | "Strict" | "lax" | "Lax" | "none" | "None" | undefined; |   sameSite?: "strict" | "Strict" | "lax" | "Lax" | "none" | "None"; | ||||||
| } | } | ||||||
|  |  | ||||||
| const DefaultButtonComponent: FunctionComponent<{ children: ReactNode; [x: string]: any }> = ({ | const DefaultButtonComponent: FunctionComponent<{ children: ReactNode; [x: string]: any }> = ({ | ||||||
| @@ -65,13 +65,13 @@ const DefaultButtonComponent: FunctionComponent<{ children: ReactNode; [x: strin | |||||||
|   return <button {...props}>{children}</button>; |   return <button {...props}>{children}</button>; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export const defaultCookieConsentProps: CookieConsentProps = { | export const defaultCookieConsentProps = { | ||||||
|   disableStyles: false, |   disableStyles: false, | ||||||
|   hideOnAccept: true, |   hideOnAccept: true, | ||||||
|   hideOnDecline: true, |   hideOnDecline: true, | ||||||
|   location: POSITION_OPTIONS.BOTTOM, |   location: POSITION_OPTIONS.BOTTOM, | ||||||
|   visible: VISIBILITY_OPTIONS.BY_COOKIE_VALUE, |   visible: VISIBILITY_OPTIONS.BY_COOKIE_VALUE, | ||||||
|   onAccept: (_acceptedByScrolling) => {}, |   onAccept: (_acceptedByScrolling: boolean) => {}, | ||||||
|   onDecline: () => {}, |   onDecline: () => {}, | ||||||
|   cookieName: defaultCookieConsentName, |   cookieName: defaultCookieConsentName, | ||||||
|   cookieValue: "true", |   cookieValue: "true", | ||||||
|   | |||||||
| @@ -33,7 +33,10 @@ export class CookieConsent extends Component<CookieConsentProps, CookieConsentSt | |||||||
|    * Set a persistent accept cookie |    * Set a persistent accept cookie | ||||||
|    */ |    */ | ||||||
|   accept(acceptedByScrolling = false) { |   accept(acceptedByScrolling = false) { | ||||||
|     const { cookieName, cookieValue, hideOnAccept, onAccept } = this.props; |     const { cookieName, cookieValue, hideOnAccept, onAccept } = { | ||||||
|  |       ...defaultCookieConsentProps, | ||||||
|  |       ...this.props, | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     this.setCookie(cookieName, cookieValue); |     this.setCookie(cookieName, cookieValue); | ||||||
|  |  | ||||||
| @@ -49,7 +52,10 @@ export class CookieConsent extends Component<CookieConsentProps, CookieConsentSt | |||||||
|    * Handle a click on the overlay |    * Handle a click on the overlay | ||||||
|    */ |    */ | ||||||
|   overlayClick() { |   overlayClick() { | ||||||
|     const { acceptOnOverlayClick, onOverlayClick } = this.props; |     const { acceptOnOverlayClick, onOverlayClick } = { | ||||||
|  |       ...defaultCookieConsentProps, | ||||||
|  |       ...this.props, | ||||||
|  |     }; | ||||||
|     if (acceptOnOverlayClick) { |     if (acceptOnOverlayClick) { | ||||||
|       this.accept(); |       this.accept(); | ||||||
|     } |     } | ||||||
| @@ -60,8 +66,10 @@ export class CookieConsent extends Component<CookieConsentProps, CookieConsentSt | |||||||
|    * Set a persistent decline cookie |    * Set a persistent decline cookie | ||||||
|    */ |    */ | ||||||
|   decline() { |   decline() { | ||||||
|     const { cookieName, declineCookieValue, hideOnDecline, onDecline, setDeclineCookie } = |     const { cookieName, declineCookieValue, hideOnDecline, onDecline, setDeclineCookie } = { | ||||||
|       this.props; |       ...defaultCookieConsentProps, | ||||||
|  |       ...this.props, | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     if (setDeclineCookie) { |     if (setDeclineCookie) { | ||||||
|       this.setCookie(cookieName, declineCookieValue); |       this.setCookie(cookieName, declineCookieValue); | ||||||
| @@ -113,7 +121,7 @@ export class CookieConsent extends Component<CookieConsentProps, CookieConsentSt | |||||||
|    * checks whether scroll has exceeded set amount and fire accept if so. |    * checks whether scroll has exceeded set amount and fire accept if so. | ||||||
|    */ |    */ | ||||||
|   handleScroll = () => { |   handleScroll = () => { | ||||||
|     const { acceptOnScrollPercentage } = this.props; |     const { acceptOnScrollPercentage } = { ...defaultCookieConsentProps, ...this.props }; | ||||||
|  |  | ||||||
|     // (top / height) - height * 100 |     // (top / height) - height * 100 | ||||||
|     const rootNode = document.documentElement; |     const rootNode = document.documentElement; | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| import { FunctionComponent, ReactNode } from "react"; | import { FunctionComponent, ReactNode } from "react"; | ||||||
|  |  | ||||||
| type Props = { | type Props = { | ||||||
|   condition: boolean; |   condition?: boolean; | ||||||
|   wrapper: (_: ReactNode) => any; |   wrapper: (_: ReactNode) => any; | ||||||
|   children: ReactNode; |   children: ReactNode; | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user