Git Product home page Git Product logo

light-dark's Introduction

๐Ÿ”ฆ light-dark

light-dark is a light-dark theme management library, especially with shadcn/ui.

The library sets the initial theme with local storage if an entry exists or uses the default theme light. Then, listeners are set up for changes in theme preference, local storage, and manual theme changes.

Getting Started

You can install the library with your preferred package manager:

npm install light-dark
# Or pnpm
pnpm add light-dark
# Or Yarn
yarn add light-dark
# Or Bun
bun add light-dark

Then you can use the setupTheme function for initial setup:

setupTheme();

This function must be only called once in a project. Multiple calls can cause unstable behavior.

Then you can use the getTheme function to get the current theme in your application. It returns either light or dark.

setupTheme();
const theme = getTheme();

console.log(theme); // light or dark

Or you can use the setTheme function to set the theme with a value. The value can be either light or dark.

setupTheme();
const theme = getTheme();

console.log(theme); // let's assume light is logged

setTheme("dark");
const newTheme = getTheme();
console.log(newTheme); // dark

Or you can use the toggleTheme function to toggle the theme without any specified value. It toggles between light and dark values.

setupTheme();
const theme = getTheme();

console.log(theme); // let's assume dark is logged

toggleTheme();
const newTheme = getTheme();
console.log(newTheme); // light

License

This repository is licensed under the MIT license.

light-dark's People

Contributors

femincan avatar

Watchers

 avatar

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.