New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@schlomoh/react-cookieconsent

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@schlomoh/react-cookieconsent

cookie banner written in typescript and react

  • 1.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
80
decreased by-37.98%
Maintainers
1
Weekly downloads
 
Created
Source

React-cookieConsent


Downloads

Installation

npm install @schlomoh/react-cookieConsent

Appearance

example


example


Usage

You can either use the Banner right out of the box without setting any properties or completely customize either one of the consent components in your own taste.


Basic
import {CookieModal} from '@schlomoh/react-cookieConsent'

const MyApp = () => (
    <>
        <CookieBanner > // above the rest of the page
        <MyPage />
    </>
)

Basic
import {CookieBanner} from '@schlomoh/react-cookieConsent'

const MyApp = () => (
    <>
        <CookieModal > // above the rest of the page
        <MyPage />
    </>
)

Customized

(all properties work for both modal and banner)

...

const Content = () => (
    <>
        <h3>I'm using cookies on my site.</h3>
        <p>Bla Bla Bla this is my own informational text.</p>
    </>
)

const containerStyle = {backgroundColor: '#333'};
const buttonStyle = {borderRadius: 0}
const primaryButtonStyle={...buttonStyle, backgroundColoe:'red'}
const secondaryButtonStyle={...buttonStyle, backgroundColoe:'blue'}

const MyApp = () => (
    <>
        <CookieBanner 
            acceptButtonText='I want it'
            declineButtonText='Go away'
            headingColor='white'
            paragraphColor='grey'
            containerStyle={containerStyle}
            primaryButtonStyle={primaryButtonStyle}
            secondaryButtonStyle={secondaryButtonStyle}
            infoContent={<Content />}
        />
        <MyPage />
    </>
)


Preview

example


Management

To let a visitor select their cookie preferences the property enableManagement has to be set to true.

You can then set an array of cookie categories which the user can select from. There is always the category "Necessary" predefined and set to true and disabled by default.

When enableManagement is set you can also override the default text of the button by setting managementButtonText='whatever'. This button is a secondary button.

<>
    <CookieBanner
        enableManagement
        managementButtonText='whatever'
        cookieCategories={['analytics', 'advertisement']}
    />
</>

Preview of the management view

example


Callbacks

You can define the callbacks which are called on either accept or decline. Simply pass a function into the onAccept or onDecline property which gets executed accordingly.

The onAccept event can pass an object with the selected cookies as ICookieObject into your accept callback.

const onAccept = (cookies : ICookieObject) => {
    console.log(cookies);
};

const onDecline = () => {
    console.log('declined');
}

const App = () => (
    <>
        <CookieBanner
        onAccept={onAccept} 
        onDecline={onDecline}
        />
    <>
)

Properties

PropTypeDefaultDescription
onAcceptfunction(cookies?: ICookieObject){}()=>{}Function called when user clicks "accept"
onDeclinefunction(){}()=>{}Function called when user clicks "decline"
infoContentJSX.Element-A JSX component that should contain the heading and paragraph of the greeting view
managementContentJSX.Element-A JSX component rendered in the management view above the cookie checkboxes best containing heading and paragraph text.
acceptButtonTextstring"Accept"String displayed in the accept button
declineButtonTextstring"Decline"String displayed in the decline button
managementButtonTextstring"Manage Cookies"String displayed in the management toggle button
enableManagementbooleanfalseSet to true to display the third button which toggles the management view (where visitors select their cookie preferences).
cookieCategoriesstring[] (array of strings)[]An array listing the available cookie preferences to choose from.
accentColorstring (React.CSSProperties.backgroundColor)'coral'The accent color used for the primary butttons
headingColorstring (React.CSSProperties.color)'black'The color applied to h1, h2, h3, h4 elements inside the views
paragraphColorstring (React.CSSProperties.color)'grey'The color applied to p elements inside the views
containerStyleobject (React.CSSProperties)-Style object overriding the banner or modal style
primaryButtonStyleobject (React.CSSProperties)-Style object overriding the primary buttons' style
secondaryButtonStyleobject (React.CSSProperties)-Style object overriding the secondary buttons' style

Keywords

FAQs

Package last updated on 15 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc