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

@fyblo/spid-cie-button

v1.0.4

Published

A web component to authenticate with SPID and CIE

Downloads

26

Readme

SPID/CIE button component

Opinionated component to support SPID and CIE login buttons according to the Italian government's standards.

[!WARNING]
the CIE button is still under development

This project is inspired by italia/spid-sp-access-button, with a few key differences:

  • It is English-first: while the buttons are provided in Italian as well, the language of the project is English, please refrain from asking any question in a language other than that.
  • It is written in TypeScript and agnostic to any framework (e.g. no jQuery dependency)
  • It is provided as a standard npm package and can be used in any project
  • It is designed to be easily customizable via CSS variables (see Usage)
  • It takes into account modern standards for accessibility and usability (e.g. it is keyboard navigable, screen reader friendly, dark-mode compatible, it scales up and down with the browser's zoom level) and, as such, it does not support Internet Explorer.
  • It takes sensible care of performances (e.g. only the required font glyphs are loaded), i.e. the bundle size is approx ~95% smaller than italia/spid-sp-access-button.
  • It supports SSR, to minimize the Javascript code delivered to the client

Usage

Installation

npm install spid-cie-button
# or
yarn add spid-cie-button
# or
pnpm add spid-cie-button

APIs

The button component exposes the following APIs:

For parts that can be rendered on the server:

import { renderButton, renderDialog, renderHead } from "spid-cie-button/server";

const head = renderHead(); // returns the style tag, that should be included in the head of the page to avoid layout shifts
const button = renderButton({ lang: "it", type: "spid" }); // returns the HTML of the button element, with the specified language ("it" or "en") and type ("spid" vs "cie")

const rpEndpoint = (idp: string) => `https://example.com/spid?idp=${idp}`;
const dialog = renderDialog({ lang: "it", rpEndpoint }); // returns the HTML of the SPID dialog, with the specified language ("it" or "en") and where the actions are controlled by the `rpEndpoint` function

Render dialog accepts extra options to control whether demo and validator endpoint should be added or not:

export type DialogInputExtraOptions = {
  targetSelf?: boolean; // whether it should open a new page on provider click (target='_blank' vs target='_self') or not
  withDemo?: boolean; // whether it should add the demo provider or not
  withValidator?: boolean; // whether it should add the validator provider or not
};

Note that if both withDemo and withValidator are true, an extra Demo provider with validator mode is added.

For the interactions client-side, the following API is available:

import { initDialog } from "spid-cie-button";

initDialog(); // initializes the dialog, making it interactive

The following env variable adds a Demo IDP to the list of IDPs:

VITE_SPID_DEVELOPMENT_MODE=true

Style Customization

To control the style, the following CSS variables are available:

  --spid-button-background;  /* controls the background of the button */
  --spid-button-color;      /* controls the text color of the button */
  --spid-button-background-hover; /* controls the background of the button on hover */
  --spid-button-background-active; /* controls the background of the button when active/selected */
  --spid-button-color-active; /* controls the text color of the button when active/selected */
  --spid-button-scale; /* controls the scale of the button, change it to increase/reduce the button size (default: 1; numeric value) */

  --spid-base-img-size; /* default: 3rem; controls the size of the SPID and CIE logos */

Example

React/Next.js

In a React/Next.js project, you can use the following code to render the button and the dialog:

// SpidButton.ts, note that it could be a Next.js server component
import { renderButton, renderDialog, renderHead } from "spid-cie-button/server";
import { initDialog } from "spid-cie-button";

export default function SpidButton() {
  const head = renderHead();
  const button = renderButton({ lang: "it", type: "spid" });
  const rpEndpoint = (idp: string) => `https://example.com/spid?idp=${idp}`;
  const dialog = renderDialog({ lang: "it", rpEndpoint });
  useEffect(() => {
    initDialog();
  }, []);
  return (
    <div>
      {head}
      <div>{button}</div>
      <div>{dialog}</div>
      <script>initDialog();</script>
    </div>
  );
}

Vue/Nuxt 3+

In a Vue/Nuxt 3+ project, you can use the following code to render the button and the dialog:

<script setup>
import { initDialog } from "spid-cie-button";
import { renderButton, renderDialog, renderHead } from "spid-cie-button/server";

const head = renderHead();
const button = renderButton({ lang: "it", type: "spid" });
const rpEndpoint = (idp: string) => `https://example.com/spid?idp=${idp}`;
const dialog = renderDialog({ lang: "it", rpEndpoint });

const html = head + button + dialog;
// in Nuxt, the server part could be in a /api/ endpoint or in a server component

onMounted(() => initDialog());
</script>

<template>
  <form>
    <section v-html="html">
  </form>
</template>

Development

After cloning run the following commands:

pnpm install

Then, to start the development server:

pnpm dev

To include the demo endpoint in the list of IDPs, you can run the following command:

VITE_SPID_DEVELOPMENT_MODE=true pnpm dev