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

nextjs-themes

v4.0.5

Published

Unleash the Power of React Server Components! Use multiple themes on your site with confidence, without losing any advantages of React Server Components.

Downloads

7,054

Readme

Next.js Themes

test Maintainability codecov Version Downloads npm bundle size Contact me on Codementor

Note: react18-themes will now be maintained as nextjs-themes, as server-specific APIs are no longer needed.

🤟 👉 Unleash the Power of React Server Components

  • ✅ Perfect dark mode in 2 lines of code
  • ✅ Fully Treeshakable (import from nextjs-themes/client/component)
  • ✅ Full TypeScript Support
  • ✅ Unleash the full power of React 18 Server components
  • ✅ No flash on load (both SSR and SSG)

Exampand following to see more features.

This project was inspired by next-themes. Unlike next-themes, nextjs-themes doesn't require wrapping everything in a provider, allowing you to take full advantage of React 18 Server Components. Additionally, it offers more features and control over your app's theming.

  • ✅ Perfect dark mode in 2 lines of code
  • ✅ Fully Treeshakable (import from nextjs-themes/client/component)
  • ✅ Designed for excellence
  • ✅ Full TypeScript Support
  • ✅ Unleash the full power of React 18 Server components
  • ✅ System setting with prefers-color-scheme
  • ✅ Themed browser UI with color-scheme
  • ✅ Support for Next.js 13 & Next.js 14 appDir
  • ✅ No flash on load (for all - SSG, SSR, ISG, Server Components)
  • ✅ Sync theme across tabs and windows
  • ✅ Disable flashing when changing themes
  • ✅ Force pages to specific themes
  • ✅ Class and data attribute selector
  • ✅ Manipulate theme via useTheme hook
  • ✅ Documented with Typedoc (Docs)
  • ✅ Use combinations of [data-th=""] and [data-color-scheme=""] for dark/light variants of themes
  • ✅ Use [data-csp=""] to style based on colorSchemePreference.
  • ✅ Compatible with Tailwind CSS, StyledComponents, emotion, Material UI, ...

Check out the live example.

Getting Started

See Getting Started

Want Lite Version? npm bundle size Version Downloads In case you are using r18gs in your project, you may use lite version which requires r18gs as a peerDependency.

With Tailwind

In tailwind.config.js, set the dark mode property to class:

// tailwind.config.js
module.exports = {
  darkMode: "class",
};

⚡🎉Ready to use dark mode in Tailwind!

Caution: Your class must be "dark", which is the default value used in this library. Tailwind requires the class name "dark" for dark-theme.

Use dark-mode specific classes:

<h1 className="text-black dark:text-white">

Migration

Refer to the migration guide.

Docs

Typedoc

🤩 Don't forget to star this repo!

Want a hands-on course for getting started with Turborepo? Check out React and Next.js with TypeScript

FAQ

Do I need to use CSS variables with this library?

No. You can hard code values for every class:

.my-class {
  color: #555;
}

[data-theme="dark"] .my-class {
  color: white;
}

Why is resolvedTheme and resolvedColorScheme necessary?

To reflect the System theme preference and forced theme/colorScheme pages in your UI. For instance, buttons or dropdowns indicating the current colorScheme should say "system" when the System colorScheme preference is active.

resolvedTheme is useful for modifying behavior or styles at runtime:

const { resolvedTheme, resolvedColorScheme } = useTheme();
const background = getBackground(resolvedTheme);

<div style={{ color: resolvedColorScheme === 'dark' ? white : black, background }}>

Without resolvedTheme, you would only know the theme is "system", not what it resolved to.

Repo stats

License

This library is licensed under the MPL-2.0 open-source license.

Please consider enrolling in our courses or sponsoring our work.