Adding a theme
This guide explains how to add support for a new theme to Cobalt.
Backend
Make sure you start from the project root.
Add the new theme to the
ThemeEnumin thecobalt/backend/domain/enums.pyfile:
python
class ThemeEnum(StrEnum):
"""
User theme enum.
"""
COBALT_DARK = "cobalt_dark"
COBALT_LIGHT = "cobalt_light"
NEW_THEME_DARK = "new_theme_dark"WARNING
Make sure to specify either dark or light in the key and value.
- Generate a new migration:
bash
make alembic-revision name="Add new dark theme"TIP
Short alias is also available: make a:r name="Add new dark theme".
- Since
alembicdoes not track changes to enum values, you need to manually update the new migration file in thecobalt/backend/infrastructure/databases/postgres/migrations/versionsfolder:
python
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.execute("ALTER TYPE themeenum ADD VALUE IF NOT EXISTS 'NEW_THEME_DARK'")
# ### end Alembic commands ###- Restart the backend container:
bash
docker restart cobalt-backendFrontend
Make sure you start from the project root.
Add the colors for the new theme to the
cobalt/frontend/src/assets/styles/variables/themes.scssfile:
scss
$new-theme-dark: (
primary: #3f85f1,
...
shadow-soft: 0 1px 6px rgba(0, 0, 0, 0.1),
);- In the same file, register a new theme:
scss
[data-theme="new_theme_dark"] {
@include generate-theme($new-theme-dark);
}- Add the new theme to the
ThemeEnumtype in thecobalt/frontend/src/types/enums/theme.tsfile:
typescript
export enum ThemeEnum {
COBALT_DARK = "cobalt_dark",
COBALT_LIGHT ="cobalt_light",
NEW_THEME_DARK = "new_theme_dark"
}WARNING
Don't forget to add the settings.general.theme.options.new_theme_dark translation key to all locale files.