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

nuxt-primevue-plus

v0.2.0

Published

This Nuxt layer makes using the PrimeVue component library easier in Nuxt.

Downloads

5

Readme

PrimeVue Theme Layer for Nuxt 3

This Nuxt layer makes using the PrimeVue component library easier in Nuxt.

Feature Highlights

  • Manages light/dark color scheme selection, with handling of SSR without dark/light flashing.
  • Provides a small color scheme selection button.
  • The createStaticMessage outputs HTML that looks like InlineMessage, for use in noscript.
  • Uses the @primevue/nuxt-module for auto-imports.
  • Imports the CSS file for PrimeIcons.

Getting Started

yarn add nuxt-primevue-plus

Extend from the layer, and add your theme definitions to nuxt.config.ts:

export default defineNuxtConfig({
  extends: ["nuxt-primevue-plus"],

  primevueTheme: {
    // The color scheme used in SSR when there is no indication of user preference.
    defaultColorScheme: "light",
  },
});

You should now have PrimeVue components available, and the light theme should show:

yarn dev

If your browser is set to prefer a dark color scheme, the page will switch to dark, and the next time you reload, the server will use the dark theme from the onset.

You could also just run yarn dev in the layer working directory, which will start a demo playground. Have a look in the .playground directory for examples.

Manual Color Scheme Selection

The <PrimeVueColorSchemeSelector /> is a single-icon button that opens a dropdown menu for selecting the color scheme. The special "System" choice uses the defaultColorScheme option in combination with the browser's preferred color scheme.

The "System" choice is the default.

Button Links

PrimeVue has no built-in support for making buttons into links. For accessibility, it is important that links be links, so we define ButtonLink a component with the same API has Button, but creating a NuxtLink.

noscript Static Messages

If you would like to output a message styled like PrimeVue's InlineMessage inside useHead({ noscript }), the createStaticMessage function can help. It returns HTML directly usable in useHead:

useHead({
  noscript: [
    createStaticMessage({ message: 'This is a demo of static message in noscript', severity: 'success' }),
  ],
});

In Depth

Color Scheme Selection

We use a cookie to transfer preferences from the browser to the SSR. We store both the preferred choice, and the resolved choice, to support switching color scheme as the browser default changes.

If the server sees no cookie, it uses the configured default color scheme based on configuration. It writes a data attribute on <html> that identifies the current color scheme.

When the browser initializes the page, it will look up the preferred color scheme and compare it to what the server set. If it's different, a normal PrimeVue color scheme switch is performed.

The browser writes the cookie, which the server picks up on in the next SSR. This means the user will see a color flash on first access, but will then always see the expected color scheme.

Cookies

There is no cookie choice implemented. While the resolved color scheme could be interpreted as fingerprinting, we'd consider it a weak signal.

The default is to secure: true sameSite: "none", which means the cookie will only be set on TLS connections and localhost. You can override cookie options in nuxt.config.ts, taking the Nuxt useCookie options:

primevueTheme: {
  cookieName: "custom-theme",
  cookieOptions: {
    secure: false,
    // sameSite=none is not allowed for secure=false.
    sameSite: "lax",
  },
}

If you keep seeing flashing, check that the cookie is being set.