1.0.1 • Published 3 years ago

@lucky-media/react-headless-cookie v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

@lucky-media/react-headless-cookie

OG

NPM Minified Size JavaScript Style Guide license-mit

This is a headless react cookie package, it comes unopinionated and unstyled. The main purpose we built this package is to allow us configurability while still maintain the Cookie set/hide logic.

The <Cookie> component accepts a <Cookie.Button> component which sets the cookie with the name on settings prop. See below for prop reference.

This package wraps the popular js-cookie.

Install

npm i @lucky-media/react-headless-cookie

Usage

import React from 'react'
import { Cookie } from '@lucky-media/react-headless-cookie'

const styles = {
  width: '100%',
  backgroundColor: '#000',
  color: 'white',
  bottom: '0px',
  padding: '1rem'
}

const App = () => {
  return (
    <Cookie style={styles} settings={{ name: 'cookie' }}>
      <div>This website is using cookies</div>
      <Cookie.Button>Accept</Cookie.Button>
    </Cookie>
  )
}

Props for Cookie component

PropTypeRequiredDescription
childrenNodeyesAccepts React Component nodes / elements to render
styleObjectnoStyle object used for styling the main container of Cookie, has a default value for position, zIndex and display.
classNameStringnoclassName string used for styling the main container of Cookie.
delayNumbernoAdd a delay before showing the popup. Defaults to 2000ms.
settingsObjectyesCookie settings, accepts name (string) and duration (number). More settings can be added check the js-cookie documentation
settings.nameStringyesCookie name
settings.durationNumbernoCookie duration in days, defaults to 180.

Props for Cookie.Button

PropTypeRequiredDescription
childrenNodeyesAccepts React Component / elements nodes to render
styleObjectnostyle object used for styling the button
classNameStringnoclassName string used for styling the button
asStringnoTag on how to render the button, defaults to button

Examples

Checkout these examples we built with Tailwind CSS on how to use the plugin

License

MIT © lucky-media

1.0.1

3 years ago

1.0.0

3 years ago