2.0.0 • Published 3 years ago

@havlasme/react-cookie-consent v2.0.0

Weekly downloads
-
License
Apache-2.0
Repository
gitlab
Last release
3 years ago

react-cookie-consent

npm version npm download Apache-2.0 license semantic release language grade

React Cookie Consent.

Demo

a minimal demo is in the example directory:

npm run serve:example

Installation

npm install --save @havlasme/react-cookie-consent

or use yarn:

yarn add @havlasme/react-cookie-consent

Usage

import cookie consent component:

import { CookieConsent } from '@havlasme/react-cookie-consent'

optionally import cookie consent stylesheet:

import '@havlasme/react-cookie-consent/dist/react-cookie-consent.min.css'

sample:

<CookieConsent version={20220201} onSubmit={handleSubmit}>
    <h4 className="cc-title">
        Cookie Consent
    </h4>

    <div className="cc-description">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur maximus, eros in rhoncus volutpat, metus diam malesuada velit, quis suscipit
        lacus ligula eget arcu. Duis tempor leo eget leo tristique hendrerit. Proin luctus lobortis libero, et lacinia libero suscipit et. Phasellus
        venenatis metus ut velit maximus, eget lacinia arcu ultrices.
    </div>

    <div className="cc-privacy-policy">
        Read more in
        <a href="#">privacy policy</a>
    </div>

    <CookieConsent.Category checked={true} disabled={true} name="technical" title="Technical">
        <div className="cc-category-description">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris congue commodo purus, nec semper orci hendrerit eget. Nam in purus eget
            neque feugiat consequat id eget odio.
        </div>

        <CookieConsent.Cookie name="cc:consent" expiration="Persistent" type="HTML">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pellentesque placerat massa, eu molestie diam aliquam vitae.
        </CookieConsent.Cookie>
    </CookieConsent.Category>

    <CookieConsent.Category name="analytical" title="Analytical">
        <div className="cc-category-description">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent mollis rutrum hendrerit. Quisque quis dui id lorem elementum consectetur
            a ut orci. Suspendisse aliquet sit amet justo nec viverra. Suspendisse potenti.
        </div>

        <CookieConsent.Cookie name="analytical1" expiration="1 year" type="HTTP">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nunc arcu, tincidunt ac ligula in, tempor consectetur arcu. Mauris nec
            magna finibus, efficitur nunc id, pretium nunc.
        </CookieConsent.Cookie>

        <CookieConsent.Cookie name="analytical2" expiration="1 minute" type="HTTP">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ultricies luctus aliquet. Duis nec urna sit amet eros pharetra auctor
            et sit amet leo. Sed interdum blandit lorem. Maecenas facilisis ut ante et scelerisque.
        </CookieConsent.Cookie>
    </CookieConsent.Category>

    <CookieConsent.Category name="marketing" title="Marketing">
        <div className="cc-category-description">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia ultrices pellentesque. Proin sodales ac tellus in volutpat.
            Curabitur semper tempor dolor vitae posuere. Pellentesque ultrices orci vel scelerisque molestie. Curabitur eget arcu et dolor maximus
            lacinia. Aenean nec turpis ut lectus gravida semper at varius mauris. Sed eget eleifend purus.
        </div>

        <CookieConsent.Cookie name="marketing1" expiration="3 month" type="HTTP">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec augue neque, lobortis eu leo ac, mattis ullamcorper odio. Fusce elementum
            leo nibh, eu tristique augue vestibulum sed.
        </CookieConsent.Cookie>
    </CookieConsent.Category>
</CookieConsent>

Component

CookieConsent

The cookie consent main component, used to position cookie consent on the screen.

prop namedescriptiondefault valueexample value
classNamethe class nameN/A"class1 class2"
expirationthe cookie consent expiration (in seconds)31536000 (1 year)2592000
openis the cookie consent expanded?falsetrue
persistthe cookie consent persistence key"cc:consent""cookie-consent"
versionthe cookie consent versionN/A20220201
onSubmitthe submit event callbackN/A(value) => console.log(event)

CookieConsent.Category

The cookie consent category component, used to describe cookie category.

prop namedescriptiondefault valueexample value
checkedis the cookie category control checked?falsetrue
classNamethe class nameN/A"class1 class2"
disabledis the cookie category control disabled?falsetrue
namethe cookie category name, used as identity in responseN/A"analytical"
titlethe cookie category titleN/A"Analytical"
onChangethe change event callbackN/A(event) => console.log(event)

CookieConsent.Cookie

The cookie consent cookie component, used to describe cookie inside category.

prop namedescriptiondefault valueexample value
classNamethe class nameN/A"class1 class2"
expirationthe cookie expirationN/A"1 month"
namethe cookie nameN/A"cc:consent"
typethe cookie typeN/A"HTTP"

CookieConsent.Portal

The cookie consent portal component, used to displace the cookie consent DOM node outside the parent component DOM hierarchy.

Styling

the cookie consent component can be styled using css:

variabledescriptiondefault value
--cc-theme-backgroundthe cookie consent component background#FFFFFF
--cc-theme-colorthe cookie consent component text color#000000
--cc-theme-portal-backgroundthe portal component backgroundrgba(255, 255, 255, 0.25)
--cc-theme-checkbox-active-backgroundthe checkbox background in active state#0D6EFD
--cc-theme-checkbox-inactive-backgroundthe checkbox background in inactive state#DDDDDD
--cc-theme-checkbox-controlthe checkbox control color#FFFFFF
--cc-theme-partitionthe category / cookie partition color#DDDDDD
2.0.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago