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

n4v-privacy-sidebar

v0.0.2

Published

An Angular module with a privacy sidebar component based on PrimeNG siderbar.

Downloads

33

Readme

n4v-privacy-sidebar

My n4v-privacy-sidebar is an UI component for Angular >= 4 based on the great PrimeNG UI framework.

It is a finished UI component, which provides a styled bottom bar for explaining cookie usage and asking your app users and site visitors for the permission to use cookies.

Screenshot

Features

  • Ready for usage out of the box
  • Neutral style
  • Translatable (some languages included, see below)
  • Observable to attach your own decisions or workflow based on the decision of visitors
  • Rembers decision of visitor
  • Stylable on your needs

Included languages

The source provides in folder lib/assets/n4v-privacy-sidebar the files

  • de.json for all German based languages
  • en.json for all English based languages

All other browser languages are defaulted to English.

You are welcome to provide some translations of the json-file!

Installation

It is available as npm package and installable with npm command:

npm i --save n4v-privacy-sidebar

The following peer dependencies need to be installed:

  1. @angular/animations
  2. @angular/common
  3. @angular/core
  4. primeng@^5.0.0

Angular is supported in version 4 or 5. The @angular dependencies should be installed already in your app.

Configuration

In your .angular-cli.json file you need to add something like:

  "assets": [
    { "glob": "**/*", "input": "../node_modules/n4v-privacy-sidebar/assets", "output": "./assets" },
    "assets",
    "favicon.ico"
  ],

The path depends on your root-configuration.

It is reponsible that the translated json-files from the library got installed in your app and are available during runtime.
If there is no text viewable in the sidebar, it is most likely a mismatch in the provided path. You can also specify an absolute path.

Code example

At first there is the demo app available in this repository.

All you would need to do is...

import { CookieService, PrivacySidebarModule } from 'n4v-privacy-sidebar';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    BrowserAnimationsModule,
    ...
    PrivacySidebarModule
  ],
  providers: [CookieService],
  bootstrap: [AppComponent]
})
export class AppModule { }

The CookieService should be added to your AppModule or your CoreModule (if available).
This should become an app wide singleton service provider.

The PrivacySidebarModule with its declaration of the <n4v-privacy-sidebar></n4v-privacy-sidebar>-tag can also be imported in a Component.

Then add the <n4v-privacy-sidebar></n4v-privacy-sidebar>-tag to a template.

That's enough to show the complete n4v-privacy-sidebar at the bottom of your site.

Observing visitor decision

At first inject the CookieService to your Component:

import { CookieService } from 'n4v-privacy-sidebar';

export class ...

  constructor(private cookieService: CookieService) {

Then create your Observer-object:

  const observer: Observer<boolean> = {
      complete: () => { console.log('cookieService completed'); },
      error: (err: Error) => { console.error(err.stack); },
      next: value => { console.log('detected a cookieService value change: %s', value.toString()); }
    };
    this.cookieService.subscribe(observer);
  }

If you don't overwrite the standard behavior on yourself, it is enough to handle complete.
On complete the visitor has accepted cookie usage and you can call code to set your cookies.

On a value change in next you can handle true and false value. For example on false you can show the visitor what he will miss without cookies. Just an example.

Customizing

CookieService

  • closeOnClick If you set this to false, you have to handle the removal of the sidebar by yourself.

  • closeOnAccept If you want to close only on decline, set this to false and do some custom stuff.

<n4v-privacy-sidebar>

You can set the following attributes on the <n4v-privacy-sidebar>-tag:

  @Input() styleClass = '';
  @Input() privacyUrl = '';
  @Input() sidebarContent = '';
  @Input() sidebarHeader = '';
  @Input() sidebarFooter = '';
  @Input() acceptCookies = '';
  @Input() declineCookies = '';

This will overwrite the translated content from json-files. So if needed you have to handle translation by yourself.

If you set a styleClass, this will be appended to the HTML class-attributes. So you can style the <n4v-privacy-sidebar> by yourself.

For example, you want to style and there is no need for dependency of the URL on the language, you might use something like:

<n4v-privacy-sidebar styleClass="my-fancy-hip-style" privacyUrl="https://www.example.com/pathToPrivacyPolicy"></n4v-privacy-sidebar>

Last but not least ...

assets/n4v-privacy-sidebar/ab{-xy}.json

{
  "header": "Confirmation for Cookie Usage",
  "content": "Cookies are important ... Click \"Accept cookies\" to go directly to the site.",
  "footer": "I confirm {{LINK}}Privacy Policy{{LINK}} and",
  "accept": "Accept cookies",
  "decline": "Decline cookies",
  "url": "/privacy"
}

I think this is self-explanatory.

{{LINK}} is the open and closing tag, which will get replaced with a real hyperlink to the url-property.
This works also in the <n4v-privacy-sidebar>-attributes from above.

The detection is based on the languages configured in browser with last fallback to en.json.

It is a best match thing.
If you provide en.json and en-us.json (files need to be lowercase), browser has en-US in its language list, en-us.json will be used.
If browser only has en-GB in its list, we will use en.json. If the language list is de-DE, en-GB, en, de and we provide de.json and not de-de.json. Anything else doesn't matter.
Then we will use de.json.

You can provide your own json-files with an assets configuration in .angular-cli.json similiar to the one above.