Styling
Get started with styling your app.
To build the user web interface TurboStarter comes with Nativewind pre-configured.
Why Nativewind?
Nativewind is basically a Tailwind CSS for mobile apps. It gives you a way to style your app with Tailwind CSS utilities and classes.
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:
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:
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:
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, we're declaring a theme provider, which is a wrapper around the app that passes the correct variables to the styles that will be used in the components and screens. It's located at providers/theme.tsx
:
Dark mode
TurboStarter 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.
Nativewind takes care of adding the dark
class to the root of our app as well as reading the user's preferences via useColorScheme
hook. That way you can put full focus on the features and just change the colors if you need to customize the theme.
Also, you can define the default theme mode and color in app configuration.
Last updated on