Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 6, 2023. It is now read-only.

Random72IsTaken/good-night

Repository files navigation

bsm llh lrHmn lrHym

Good Night

Switch the dark-mode of your TALL Stack application with ease.

Description

The concept of dark-mode in TailwindCSS with class strategy is simply about adding dark class to the html element in the page, which activates the Tailwind classes that are prefixed with the dark: psuedo-element...

Therefore, we can utilize an Alpine.js custom bind to either add a dark-mode switcher in a configurable corner of the page, or apply a different bind to a clickable element which will hook the necessary logic to it on its own.

Installation

This is a TALL Stack supportive package, so... -you know the drill!

Requirements

Steps

  1. Install the package via Composer:

    composer require goodm4ven/good-night
  2. Publish the package configuration and view files:

    php artisan vendor:publish --provider="GoodM4ven\GoodNight\GoodNightServiceProvider"
    • If you're updating the package, please add --force option to override the old assets.
  3. Open the published config/good-night.php file, and determine the default mode as well as whether the corner switcher is on or not.

    • Here are the default configurations of the file.
      env('GOOD_NIGHT_DEFAULT', 'light'), /* |----------------------------------------------------------- --------------- | Switcher Enabled |----------------------------------------------------------- --------------- | | Decide whether to show or hide the corner dark-mode switcher in the page. | | Either way, the package won't work without `@goodNight` directive. | */ 'switcher-enabled' => env('GOOD_NIGHT_ENABLED', true), /* |----------------------------------------------------------- --------------- | Switcher Position |----------------------------------------------------------- --------------- | | Determine the position of the corner switcher button when shown in the page. | | Available positions are: top-right, top-left, bottom-left, bottom-right. | */ 'switcher-position' => env('GOOD_NIGHT_POSITION', 'top-right'),">/*
      |--------------------------------------------------------------------------
      | Default Mode
      |--------------------------------------------------------------------------
      |
      | Determine the default dark/light mode that the app will start with.
      |
      | The default is `light` and is stored in `$store.goodNightMode`.
      |
      */

      'default-mode' => env('GOOD_NIGHT_DEFAULT', 'light'),


      /*
      |--------------------------------------------------------------------------
      | Switcher Enabled
      |--------------------------------------------------------------------------
      |
      | Decide whether to show or hide the corner dark-mode switcher in the page.
      |
      | Either way, the package won't work without `@goodNight` directive.
      |
      */

      'switcher-enabled' => env('GOOD_NIGHT_ENABLED', true),


      /*
      |--------------------------------------------------------------------------
      | Switcher Position
      |--------------------------------------------------------------------------
      |
      | Determine the position of the corner switcher button when shown in the page.
      |
      | Available positions are: top-right, top-left, bottom-left, bottom-right.
      |
      */

      'switcher-position' => env('GOOD_NIGHT_POSITION', 'top-right'),
  4. Add the following Blade directive to your master layout or view:

    <body>
    @goodNight
    ...
    body>
  5. Modify the darkMode and the content of your tailwind.config.js file:

    module.exports = {
    content: [
    ...
    './resources/views/**/*.blade.php', // or to './resources/views/vendor/good-night/**' specifically...
    ],

    darkMode: 'class',
    ...
    }
  6. Compile your views with dark Tailwind classes into app.css, and Alpine in your app.js.

Usage

There are 2 different ways to use this package:

  1. Enable the corner switcher in configuration and it will be displayed by default.

    • You can customize the published view at resources/views/vendor/good-night/partials/good-night-switcher.blade.php.
  2. Disable the corner switcher in configuration and then add the following to a clickable element:

    <button
    x-data="goodNight()"
    x-bind="custom"
    >
    Theme Changer
    button>

And yes, in both cases, the package will not work without having @goodNight Blade directive in the page!

Cases

  • How does this switching happen smoothly?

  • What if I want to add extra logic upon theme switching?

    • You can pass a callback to goodNight(), like so:

      "><button
      x-data="goodNight(() => { console.log('it\'s still 8, Mom!') })"
      x-bind="custom"
      >

      button>

Development

Pull-requests are free around here. A special package privilage, you know.

  • There's an available and automated CHANGELOG of all the updates.

TODOs

  • Abstract the binding in a custom Alpine.js directive, somehow; maybe.

    Switcher "><button
    x-data {{-- Or on a parent somewhere, so it's optional --}}
    x-good-night="optionalCallback()" {{-- It does writes "good-night" only once! --}}
    >
    Switcher
    button>
  • Write Pest and Cypress tests!

Remarks

Please do all the packages you rely on, but NOT this one.


wlHmd llh rb l`lmyn

About

Switch the dark-mode of your TALL Stack application with ease.

Topics

Resources

Readme

License

MIT license

Stars

Watchers

Forks

Contributors