Astro Themes

screenshot of Astro Themes
astro

Astro Themes

Easy dark mode for Astro websites

Overview:

Astro-themes is a dark mode theme component for Astro websites. It allows users to easily add themes to their websites in just two lines of code. The theme component has zero dependencies and supports server-side rendering (SSR). It can be used with any framework or UI.

Features:

  • Easy dark mode implementation: Astro-themes makes it simple to implement dark mode on websites.
  • Zero dependencies: This theme component has no external dependencies, ensuring lightweight and efficient performance.
  • SSR support: Astro-themes supports server-side rendering, allowing the theme to be rendered on the server before being sent to the client.
  • Framework compatibility: The theme component can be used with any framework or UI, making it highly flexible and adaptable.

Installation:

To install astro-themes, follow these steps:

  1. Add the Themes component in your Astro app. It is recommended to add it in a centralized layout component, so it is shared across all pages.

    // Example code adding Themes component in document head
    <astro-document>
      <head>
        <Themes />
      </head>
    </astro-document>
    
  2. Use the Themes component to get and set the theme in your app. This can be done using the provided methods:

    • To set the theme:

      document.dispatchEvent(new CustomEvent('set-theme', { detail: 'dark' }));
      
    • To get the current theme:

      document.documentElement.attributes.getNamedItem('data-theme')?.value;
      
    • To set a default theme (applied if the browser doesn't specify a preference for dark mode):

      // Example: set default theme as 'light'
      Theme.defaultTheme = 'light';
      

    If using Tailwind CSS, make sure to configure the dark mode selector as described in the documentation to ensure compatibility.

Summary:

Astro-themes is a lightweight and easy-to-use dark mode theme component for Astro websites. It offers simple implementation, zero dependencies, SSR support, and compatibility with any framework or UI. By adding just two lines of code, users can enable dark mode on their websites effortlessly. The component also synchronizes the theme setting across tabs and responds to changes in the OS preference.

astro
Astro

Astro is the all-in-one web framework designed for speed. Pull your content from anywhere and deploy everywhere, all powered by your favorite UI components and libraries.

template
Templates & Themes

A template or theme refers to a pre-designed layout or structure that provides a basic framework for building a specific type of application or website. It typically includes good design, placeholder content and functional features, allowing developers to customize and fill in the details according to their specific needs.

Dark Mode

Dark mode is a user interface option that uses a dark color scheme instead of light. It reduces eye strain and improves visibility in low-light conditions. Implementing dark mode in a website or application involves updating the styles and color palette to support both light and dark modes.

Stylelint

Stylelint is a modern linter for CSS that helps you avoid errors and enforce consistent styling conventions. It provides rules for detecting errors and warnings, and can be configured to match your specific project's requirements.

typescript
Typescript

TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.