npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@schlomoh/react-cookieconsent

v1.6.1

Published

Cookie consent components written in typescript and react. Usable with only one line of code.

Downloads

256

Readme

React-cookieConsent

This react cookie consent library provides you with a fully customizable banner or modal

MIT License Downloads

Installation 🧑🏽‍💻

Install the component library using:

  npm install @schlomoh/react-cookieConsent

Features ✨

  • Two seperate components (modal and banner)
  • Fully customizable via css
  • Define custom text to inform the user
  • Pass in callbacks for denial and acception
  • Enable or disable cookie preferences

Preview 👀

Default cookie banner

example

Default cookie Modal

example

Usage / Examples ✏️

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

Cookie modal 💚

Basic

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

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

Cookie banner 💙

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 />
    </>
)

... it then looks like this (dont mind the text👀 earlier screenshot):

example

Enabling cookie preferences 🔧

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.

For example

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

example

Callbacks 👉🏼

You can define callbacks which are called on either accept or decline. Simply pass a function into the onAccept or onDecline property which is 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');
}


// inside your app
const MyApp = () => (
    <>
        <CookieBanner
        onAccept={onAccept} 
        onDecline={onDecline}
        />
    <>
)

Reference 🔎

The ICookieObject:

interface ICookieObject {
  [key: string]: boolean;
}

Example:

{ "advertisement": false, "analytics": true }