Skip to content

mayank1513/nextjs-themes

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Next.js Themes

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

Version 3 Short Notes: Version 3.0 brings minor API changes along with major performance improvements and fixes. We have minimized changes to existing APIs.

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

Exampand following to see more features.

Motivation and Key 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.

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.

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.


with πŸ’– by Mayank Kumar Chaudhari

About

🀟 πŸ‘‰ Theme with confidence and [Unleash the Power of React Server Components](https://medium.com/javascript-in-plain-english/unleash-the-power-of-react-server-components-eb3fe7201231)

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 52.8%
  • JavaScript 32.4%
  • SCSS 12.6%
  • Handlebars 2.2%