Giter Club home page Giter Club logo

next-theme-kit's Introduction

๐ŸŽจ Next Theme Kit - Theme Management for Next.js

next-theme-kit is a powerful and easy-to-use wrapper for handling dark and light themes in your Next.js applications. Elevate your user experience with stunning themes and effortless style!

Features ๐ŸŽจ

  • ๐ŸŒ— Dark and Light Themes: Switch between dark and light themes effortlessly.
  • ๐ŸŽจ Custom Themes: Define your own custom themes.
  • ๐ŸŒˆ System Color Scheme Priority: Prioritize system color scheme for automatic theme switching.
  • ๐Ÿ’พ LocalStorage Support: Remember user's theme preference across sessions.
  • โšก๏ธ SSR and SSG Compatibility: Works seamlessly with server-side rendering (SSR) and static site generation (SSG).
  • ๐Ÿ“ท Flash Free: No theme flashing tanks to a custom script to prevent this issue.

๐Ÿš€ Live Preview

You can check out the Live Preview of Next Theme Kit to see it in action!

Pages Router

You can check out the Live Preview with Pages Router of Next Theme Kit to see it in action!

App Router

You can also explore the Live Preview with App Router of Next Theme Kit to see it in action!

Attribute Mode

You can check out the Live Preview with the Attribute Mode of Next Theme kit in action!.

๐Ÿ“ฆ Installation

To install next-theme-kit, simply use npm:

npm install next-theme-kit

Or with yarn:

yarn add next-theme-kit

๐Ÿงช Usage

With App Router

To integrate next-theme-kit onto a NextJS project that uses the app router, we need to use a workaround for adding React Context onto the layout.tsx of our project. To do this we need to create a providers.tsx file in our app directory as follows:

// app/providers.tsx
'use client';

import React from 'react';
import { ThemeProvider } from 'next-theme-kit';

type ProvidersProps = {
  children: React.ReactNode;
};

export const Providers: React.FC<ProvidersProps> = (props) => {
  const { children } = props;

  return <ThemeProvider>{children}</ThemeProvider>;
};

Once we have created this file we can use it to wrap our children in the app layout file.

// app/layout.tsx
import React from 'react';
import { Providers } from './providers';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang='en'>
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}

With Pages Router

To integrate next-theme-kit onto a NextJS project that uses the pages router, simply wrap your _app.tsx with the ThemeProvider.

// pages/_app.tsx
import React from 'react';

import type { AppProps } from 'next/app';

import { ThemeProvider } from 'next-theme-kit';

export default function App({ Component, pageProps }: AppProps) {
  return (
    <ThemeProvider>
      <Component {...pageProps} />
    </ThemeProvider>
  );
}

๐Ÿช Theme Hook

The following code shows an example of using the useTheme hook in a NextJs application:

'use client';

import React, { useEffect, useState } from 'react';

import { useTheme } from 'next-theme-kit';

export default function ThemeToggler() {
  const { theme, setTheme } = useTheme();
  const [isMounted, setIsMounted] = useState<boolean>(false);

  useEffect(() => {
    setIsMounted(true);
  }, []);

  if (!isMounted) return null;

  return (
    <div className='flex flex-col items-center justify-center'>
      Theme: {theme}
      <button
        type='button'
        onClick={() => {
          setTheme(theme === 'dark' ? 'light' : 'dark');
        }}
      >
        Toggle theme
      </button>
    </div>
  );
}

๐ŸŽ† Examples

Check out the examples directory to see how you can implement next-theme-kit in your Next.js projects!

โฒ๏ธ API

ThemeProvider

Below is the api description of both the ThemeProvider and the useTheme hook.

  • defaultTheme?: string: Optional - The default theme to be used if no theme is specified. Defaults to 'light'.
  • mode?: 'class' | 'attribute': Optional - Theme mode, can be set to 'class' or 'attribute'. If attribute is enabled, the attribute is 'data-theme'. Defaults to 'class'.
  • storageKey?: string: Optional - The key used for storing the theme in local storage. Defaults to theme.
  • themes?: string[]: Optional - An array of available themes for the application. Defaults to ['dark', 'light'].
  • useColorScheme?: boolean: Optional - Whether to use the color scheme for the theme. Defaults to true.
  • useLocalStorage?: boolean: Optional - Whether to use local storage to save the theme. Defaults to false.
  • useSystem?: boolean: Optional - Whether to use the system's preferred color scheme. Defaults to true.

useTheme

  • setTheme(theme: string): void: A function that allows you to update the current theme of the application.
  • theme: string | undefined: Represents the current theme of the application.
  • themes: string[]: An array containing the available themes that can be used in the application.

๐Ÿค Contributing

We welcome contributions and feedback! Feel free to open issues and submit pull requests.

๐Ÿ“„ License

This project is licensed under the MIT License.

next-theme-kit's People

Contributors

faustinozanetto avatar

Watchers

 avatar

next-theme-kit's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency jsdom to v24
  • chore(deps): update dependency lint-staged to v15
  • chore(deps): update dependency release-it to v17
  • chore(deps): update dependency tsup to v8
  • chore(deps): update testing-library monorepo (major) (@testing-library/jest-dom, @testing-library/react)
  • chore(deps): update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • chore(deps): update vitest monorepo to v1 (major) (@vitest/coverage-v8, vitest)
  • chore(deps): update wagoid/commitlint-github-action action to v6

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/main.yml
  • actions/checkout v3
  • actions/setup-node v3
  • wagoid/commitlint-github-action v5
.github/workflows/publish.yml
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • @babel/core 7.22.5
  • @babel/preset-env 7.22.5
  • @babel/preset-react 7.22.5
  • @babel/preset-typescript 7.22.5
  • @commitlint/cli ^17.6.6
  • @commitlint/config-conventional ^17.6.6
  • @types/node 18.16.19
  • @types/react 18.2.14
  • @types/react-dom 18.2.6
  • @typescript-eslint/eslint-plugin ^6.1.0
  • @typescript-eslint/parser ^6.1.0
  • @testing-library/jest-dom ^5.16.5
  • @testing-library/react ^14.0.0
  • @vitejs/plugin-react ^4.0.3
  • @vitest/coverage-v8 ^0.33.0
  • babel-loader 9.1.2
  • dotenv-cli 7.2.1
  • concurrently 8.2.0
  • eslint 8.44.0
  • eslint-config-airbnb 19.0.4
  • eslint-config-prettier 8.8.0
  • eslint-plugin-import 2.27.5
  • eslint-plugin-jsx-a11y 6.7.1
  • eslint-plugin-prefer-arrow 1.2.3
  • eslint-plugin-prettier 5.0.0
  • eslint-plugin-react 7.32.2
  • eslint-plugin-react-hooks 4.6.0
  • eslint-plugin-storybook 0.6.12
  • eslint-plugin-typescript-sort-keys 2.3.0
  • eslint-plugin-unused-imports 2.0.0
  • husky 8.0.3
  • jsdom ^22.1.0
  • lint-staged ^13.2.3
  • prettier ^3.0.0
  • release-it 15.11.0
  • tsup 7.1.0
  • react 18.2.0
  • react-test-renderer 18.2.0
  • react-dom 18.2.0
  • yalc 1.0.0-pre.53
  • vitest ^0.33.0
  • typescript ^5.1.6
  • react >=17
  • react-dom >=17
  • node >=14.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.