๐ŸŽจThemes

How to change the branding of your project from a list of 20+ options by changing one word.

Tailwind CSS 4 Setup ๐Ÿ†•

LightningRails uses Tailwind CSS 4 with the tailwindcss-rails gem for optimal performance and a better development experience. The configuration is located in app/assets/tailwind/application.css.Key benefits of this setup:

  • Faster build times

  • Better integration with Rails asset pipeline

  • More flexibility for custom configurations

  • Automatic purging of unused CSS

Changing Themes with DaisyUI

DaisyUI offers a variety of themes that you can easily apply to your Ruby on Rails application. To change the theme, you need to modify the data-theme attribute in the <body> tag of your application.html.erb layout file.

Steps to Change the Theme

  1. Open your config/meta.yml file.

  2. Locate the LIGHT_THEME and DARK_THEME meta's

  3. Update value with the desired theme name. For example:

# config/meta.yml
LIGHT_THEME: "cupcake"
DARK_THEME: "forest"

You can replace "cupcake" with any theme name provided by DaisyUI.

Don't forget to restart your server for every change you do int the meta.yml ๐Ÿ’ก

Available Themes

To see the different themes you can choose from, check the DaisyUI documentation or their themes page below:

Check DaisyUI Themes

All the themes available from DaisyUI and therefore LighningRails

How do we change the theme?

In application.html.erb by changing the data-theme attribute in the <body> tag, you can quickly switch between these themes, allowing for a customizable look and feel for your application!

Can we change other Tailwind libraries?

Most definitely! DaisyUi has a lot of components but frankly lacks pre-designed sections, for us developers who don't want to spend hours creating for scratch. You can easily find more Tailwind components in the HyperUI library.

HyperUI library with many components

Find a component you like? Just copy/paste it into your LightningRails project.

Pro Tip: Avoid hard-coded color classes in non-DaisyUI components (like HyperUI). For example, using a class like bg-white wonโ€™t adapt to theme changes. This can result in a dark theme with a mismatched white backgroundโ€”definitely not ideal. ๐Ÿ˜…

Custom Theme

If you wish to add a custom theme or modify an existing one. We won't be able to do it on the tailwind config file. However, Lightning Rails now uses Tailwind CSS 4 with the tailwindcss-rails gem, which provides better performance and more flexibility than the CDN approach. DaisyUI is integrated via CDN import in the Tailwind configuration.

Here is how to create your custom theme:

Custom Theme Colors

In app/assets/tailwind/application.css, create a custom theme using the new Tailwind CSS 4 syntax:

/* tailwind/application.css */

@import "tailwindcss" source(none);
@source "../../../public/*.html";
@source "../../../app/helpers/**/*.rb";
@source "../../../app/javascript/**/*.js";
@source "../../../app/views/**/*";

@plugin "./daisyui.js";

/* Optional for custom themes โ€“ Docs: https://daisyui.com/docs/themes/#how-to-add-a-new-custom-theme */
@plugin "./daisyui-theme.js"{
  /* custom theme here */
  name: "lightning-theme";
  default: true; /* set as default */
  prefersdark: false; /* set as default dark mode (prefers-color-scheme:dark) */
  color-scheme: light; /* color of browser-provided UI */

  --color-base-100: oklch(98% 0.02 240);
  --color-base-200: oklch(95% 0.03 240);
  --color-base-300: oklch(92% 0.04 240);
  --color-base-content: oklch(20% 0.05 240);
  --color-primary: oklch(55% 0.3 240);
  --color-primary-content: oklch(98% 0.01 240);
  --color-secondary: oklch(70% 0.25 200);
  --color-secondary-content: oklch(98% 0.01 200);
  --color-accent: oklch(65% 0.25 160);
  --color-accent-content: oklch(98% 0.01 160);
  --color-neutral: oklch(50% 0.05 240);
  --color-neutral-content: oklch(98% 0.01 240);
  --color-info: oklch(70% 0.2 220);
  --color-info-content: oklch(98% 0.01 220);
  --color-success: oklch(65% 0.25 140);
  --color-success-content: oklch(98% 0.01 140);
  --color-warning: oklch(80% 0.25 80);
  --color-warning-content: oklch(20% 0.05 80);
  --color-error: oklch(65% 0.3 30);
  --color-error-content: oklch(98% 0.01 30);

  /* border radius */
  --radius-selector: 1rem;
  --radius-field: 0.25rem;
  --radius-box: 0.5rem;

  /* base sizes */
  --size-selector: 0.25rem;
  --size-field: 0.25rem;

  /* border size */
  --border: 1px;

  /* effects */
  --depth: 1;
  --noise: 0;
}

Then call the new theme in your meta.yml

/* config/meta.yml */

LIGHT_THEME: "lightning-theme"
DARK_THEME: "forest"

See all the DaisyUI variables you can customize in your custom theme here.

Customize fonts

To customize the default fonts of your projects, import the custom fonts in tailwind/application.css and assign them to your headers and paragraphs in the same file.

/* tailwind/application.css */

@import url('https://fonts.googleapis.com/css2?family=Jersey+15&family=Open+Sans:ital,wght@0,300..800;1,300..800&family=Pacifico&display=swap');

h1, h2, h3 {
  font-family: "Pacifico", serif;
  font-weight: 400;
  font-style: normal;
}

Last updated

Was this helpful?