Skip to content

Repository files navigation

RendPro React Cookie Notice

A simple and customizable cookie notice bar for use in React websites.

Installation

 bun add @rendpro/react-cookie-notice

or

 npm install @rendpro/react-cookie-notice

or

 yarn add @rendpro/react-cookie-notice

How to use it

First, import the component and styles in your project.

importCookieNoticefrom"@rendpro/react-cookie-notice";import"@rendpro/react-cookie-notice/styles";

Then you can use the component anywhere in you React application

<CookieNoticetext={`This website uses cookies to improve and facilitate access to the website and to keep statistical data. Your continued use of using this site constitutes acceptance of this.`}buttonText="Accept"links={[{name: "Privacy Policy",link: "#"},{name: "How to disable cookie?",link: "#"},{name: "Cybersecurity",link: "#"},]}/>

Configuration

PropTypeDefault valueDescription
backgroundColorstringrgb(26, 26, 24)Banner background color
buttonBackgroundColorstringrgb(231, 181, 46)Button background color
buttonColorstringrgb(26, 26, 24)Button color
buttonTextstringAcceptButton text
classNamestringundefinedClassName for the banner. You can use it to override default styles
expiresnumberDatenew Date().getDate() + 7
foregroundColorstringrgb(168, 168, 168)Banner text color
links{ name: string; link: string; render?: React.FC<{ name: string; link: string; className: string; }> }[][{ name: "Privacy policy", link: "#" },{ name: "How to disable cookie?", link: "#" },{ name: "Cybersecurity", link: "#" }]Links in banner. You can use render prop to render custom component instead of a <a> tag.
linksColorstringrgb(231, 181, 46)Banner links color
setCookiebooleantrueWhether or not to set a cookie
textstringThis website uses cookies to improve and facilitate access to the website and to keep statistical data. Your continued use of using this site constitutes acceptance of this.Banner text
onCookieSet() => voidundefinedRuns when a cookie has been set
onHide() => voidundefinedRuns when a cookie notice has been hidden

Example of using all the props

importReactfrom"react";import{BrowserRouter,Route,Link,Routes}from"react-router-dom";importCookieNoticefrom"@rendpro/react-cookie-notice";import"@rendpro/react-cookie-notice/styles";importstylesfrom'./App.module.css';constApp=()=>(<BrowserRouter><Routes><Routepath="/"element={<CookieNoticelinks={[{name: "Privacy Policy",link: "/policy",render: (props)=>(<Linkto={props.link}className={props.className}>{props.name}</Link>),},{name: "How to disable cookies?",link: "#",},{name: "Cybersecurity",link: "#",},]}buttonText="I Accept"text="This site uses cookies to improve and facilitate access to the service and for statistical data. Continuing to use this site implies acceptance of this state of affairs."backgroundColor="rgb(255, 255, 255)"foregroundColor="rgb(17, 27, 39)"buttonBackgroundColor="rgb(89, 180, 208)"buttonColor="rgb(255, 255, 255)"linksColor="rgb(89, 180, 208)"onCookieSet={()=>console.log("cookie set")}onHide={()=>console.log("is hide")}className={styles.wrapper}/>}/><Routepath="/"element={<h1>Index</h1>}/><Routepath="/policy"element={<h1>Policy</h1>}/></Routes></BrowserRouter>);exportdefaultApp;

License

This package is distributed under the MIT License.

About

A simple and customizable cookie notice bar for use in React websites.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages