Customization

Styling

Get started with styling your extension.

To build the extension interface TurboStarter comes with Tailwind CSS and Radix UI pre-configured.

Why Tailwind CSS and Radix UI?

The combination of Tailwind CSS and Radix UI gives ready-to-use, accessible UI components that can be fully customized to match your brands design.

Tailwind configuration

In the tooling/tailwind/config directory you will find shared Tailwind CSS configuration files. To change some global styles you can edit the files in this folder.

Here is an example of a shared Tailwind configuration file:

tooling/tailwind/config/base.ts
import type { Config } from "tailwindcss";
 
export default {
  darkMode: "class",
  content: ["src/**/*.{ts,tsx}"],
  theme: {
    extend: {
      colors: {
        ...
        primary: {
          DEFAULT: colorVariable("--colors-primary", true),
          foreground: colorVariable("--colors-primary-foreground", true),
        },
        secondary: {
          DEFAULT: colorVariable("--colors-secondary", true),
          foreground: colorVariable("--colors-secondary-foreground", true),
        },
        success: {
          DEFAULT: colorVariable("--colors-success", true),
          foreground: colorVariable("--colors-success-foreground", true),
        },
        ...
      },
    },
  },
  plugins: [animate, containerQueries, typography],
} satisfies Config;

For the colors part, we bet stricly on CSS Variables in HSL format to allow for easy theme management without a need for any JavaScript.

Also, each app has its own tailwind.config.ts file which extends the shared config and allows you to override the global styles.

Here is an example of an app's tailwind.config.ts file:

apps/mobile/tailwind.config.ts
import type { Config } from "tailwindcss";
import { fontFamily } from "tailwindcss/defaultTheme";
 
import baseConfig from "@turbostarter/tailwind-config/web";
 
export default {
  // We need to append the path to the UI package to the content array so that
  // those classes are included correctly.
  content: [
    ...baseConfig.content,
    "../../packages/ui/{shared,web}/src/**/*.{ts,tsx}",
  ],
  presets: [baseConfig],
  theme: {
    extend: {
      fontFamily: {
        sans: ["DM Sans", ...fontFamily.sans],
        mono: ["DM Mono", ...fontFamily.mono],
      },
    },
  },
} satisfies Config;

That way we can have a separation of concerns and a clear structure for the Tailwind CSS configuration.

Themes

TurboStarter comes with 10+ predefined themes which you can use to quickly change the look and feel of your app.

They're defined in packages/ui/shared/src/styles/themes directory. Each theme is a set of variables that can be overridden:

packages/ui/shared/src/styles/themes/orange.ts
export const orange = {
  light: {
    background: [0, 0, 1],
    foreground: [240, 0.1, 0.039],
    card: [0, 0, 1],
    "card-foreground": [240, 0.1, 0.039],
    ...
  }
} satisfies ThemeColors;

Each variable is stored as a HSL array, which is then converted to a CSS variable. That way we can ensure full type-safety and reuse themes across parts of our apps (e.g. use the same theme in emails).

Feel free to add your own themes or override the existing ones to match your brand's identity.

To apply a theme to your app, you can use the data-theme attribute on your layout wrapper for each part of the extension:

components/layout/layout.tsx
export const Layout = ({ children }: { children: React.ReactNode }) => {
  const [config] = useStorage<ThemeConfig>(STORAGE_KEY.THEME);
 
  return (
    <div id="root" data-theme={config?.color}>
      {children}
    </div>
  );
};

In TurboStarter, we're using Storage API to persist the user's theme selection and then apply it to the root div element.

Dark mode

The starter kit comes with a built-in dark mode support.

Each theme has a corresponding dark mode variables which are used to change the theme to its dark mode counterpart.

packages/ui/shared/src/styles/themes/orange.ts
export const orange = {
  light: {},
  dark: {
    background: [0, 0, 1],
    foreground: [240, 0.1, 0.039],
    card: [0, 0, 1],
    "card-foreground": [240, 0.1, 0.039],
    ...
  }
} satisfies ThemeColors;

As we define the darkMode as class in the shared Tailwind configuration, we need to add the dark class to the root wrapper element to apply the dark mode styles.

The same as for the theme, we're using Storage API to persist the user's dark mode selection and then apply correct class name to the root div element:

components/layout/layout.tsx
export const Layout = ({ children }: { children: React.ReactNode }) => {
  const [config] = useStorage<ThemeConfig>(STORAGE_KEY.THEME);
 
  return (
    <div
      id="root"
      data-theme={config?.color}
      className={cn({
        dark:
          config?.mode === THEME_MODE.DARK ||
          (config?.mode === THEME_MODE.SYSTEM &&
            window.matchMedia("(prefers-color-scheme: dark)").matches),
      })}
    >
      {children}
    </div>
  );
};

We can define the default theme mode and color in app configuration.

Last updated on

On this page

Ship your startup everywhere. In minutes.Get TurboStarter