Git Product home page Git Product logo

cookie-consent's Introduction

<cookie-consent>

Published on webcomponents.org Travis build GitHub release

Demo and API docs

A great, simple and fully customizable material design cookie consent that automatically shows up only to the users subject to the cookie law (EU users).

Features

  • Ready out of the box. Just include it and insert a <cookie-consent></cookie-consent> in your web app and you are ready to go!
  • Fully customizable. It can be completely styled and it supports a lot of properties that allows you to easily change its default behavior.
  • Easily detect what the user does. The readonly cookies-status property can be binded to detect whether the user consent is pending, accepted or rejected. It also fires a cookies-status-changed event when the user responds, so you can wait for the user to accept or reject the cookies before doing something with their data.
  • Tested using the web-component-tester

Installation

bower install --save cookie-consent

Usage

Basic usage

<cookie-consent></cookie-consent>

Custom text, policy link and consent rejection

<cookie-consent
  text="This website uses yummy cookies"
  policy-link="/policy"
  rejectable>
</cookie-consent>

Full customization

You can even set an empty text and then use a span with the class .text to insert anything you want (icons, etc.). The same can be done with the policy link. Just use the .policy-link class in an anchor tag inside the cookie-consent.

<cookie-consent use-local-storage>
  <span class="text">
    This website uses cookies 
    <iron-icon icon="editor:insert-emoticon"></iron-icon>
  </span>
  <a href="/policy" class="policy-link">Yay!</a>
</cookie-consent>

Note: the user response is saved by default in a permanent cookie. You can change this behavior by adding the use-local-storage or the use-session-storage properties.

Styling

The following custom properties and mixins are available for styling:

Custom property Description Default
--cookie-consent-background-color The background color of the cookie consent #323232
--cookie-consent-text-color The color of text in the cookie consent #f1f1f1
--cookie-consent-policy-link-color The color of the link to the cookie policy --light-accent-color
--cookie-consent-reject-text-color The main color of the button to reject the cookie policy --disabled-text-color
--cookie-consent-reject-background The background of the button to reject the cookie policy transparent
--cookie-consent-reject-ink-color The color of the ink displayed when the reject button is pressed --disabled-text-color
--cookie-consent-accept-text-color The main color of the button to accept the cookie policy --accent-color
--cookie-consent-accept-background The background of the button to accept the cookie policy transparent
--cookie-consent-accept-ink-color The color of the ink displayed when the accept button is pressed --accent-color
--cookie-consent-accept-button Mixin applied to the accept button {}
--cookie-consent-reject-button Mixin applied to the reject button {}
--cookie-consent-buttons Mixin applied to both the accept and reject buttons {}
--cookie-consent-policy-link Mixin applied to the policy link {}
--cookie-consent-text Mixin applied to the cookie consent text {}
--cookie-consent-toast Mixin applied to the cookie consent toast {}
--cookie-consent Mixin applied to the cookie consent {}

This element uses paper-toast to display the consent. paper-toast applies the mixin --paper-font-common-base but does not import paper-styles/typography.html. In order to apply the Roboto font to this element, make sure you've imported paper-styles/typography.html.

cookie-consent's People

Contributors

danielx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cookie-consent's Issues

Disable ip location

As a DEVELOPER I want to have a property to enable/disable the IP location functionality.

lit-element release?

Hi Dabolus,

are you planning a lit-element or at least Polymer 3 version of this element? If not, do you mind a PR?

Cheers!

Cannot use 'in' operator to search for 'country_code' in null

Hi! Nice component!

I'm using the v1 if this component and I was trying to not check the user country, I just want to always show the cookie banner not matter where they are (At this moment there's no way to disable this in the component) so what I did was to set the geoIpUrl to nothing (geo-ip-url="") and after this the console output this:

cookie-consent.html:274 Uncaught TypeError: Cannot use 'in' operator to search for 'country_code' in null
    at HTMLElement._checkCountryCode (cookie-consent.html:274)
    at HTMLElement.handler (polymer.html:507)
    at HTMLElement.fire (polymer.html:1284)
    at HTMLElement._handleResponse (iron-ajax.html:512)
    at <anonymous>

I checked the component's code and there's a line where you check if there's a property with the name set in geoIpParam inside the response of the iron-request.
https://github.com/Dabolus/cookie-consent/blob/master/cookie-consent.html#L280

Note: This is happenning on the v2 too.

The problem is that before this if you check if response is an object:
https://github.com/Dabolus/cookie-consent/blob/2.0/cookie-consent.html#L277

And in my use case response is null and typeof null === 'object' is true.

I've created 2 PR to fix this in both versions (v1 and v2)

#1
#2

Thanks for your time and regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.