Theming and Customization
Relevant source files
The following files were used as context for generating this wiki page:
- packages/admin-web-angular/src/app/@theme/styles/themes.scss
- packages/admin-web-angular/src/app/@theme/styles/theme.everdark.ts
- packages/shop-mobile-ionic/src/theme/variables.scss
- packages/admin-web-angular/src/app/@theme/theme.module.ts
- packages/common-angular/src/scss/everbie.common.scss
- packages/shop-web-angular/src/styles/styles.scss
- packages/shop-mobile-ionic/src/global.scss
- packages/merchant-tablet-ionic/src/global.scss
- packages/carrier-mobile-ionic/src/global.scss
The Ever-Demand platform employs a multi-faceted approach to theming and customization, tailored to the specific framework of each client application. The Admin Web App utilizes the Nebular Theming engine, the various Ionic mobile apps use a shared SCSS variable system, and the Shop Web App leverages Angular Material's theming capabilities. This modular strategy allows for a consistent brand identity while accommodating the technical requirements of each frontend project.
A central piece of the theming architecture for mobile apps is the shared SCSS file, everbie.common.scss, which provides a common set of brand colors, variables, and utility mixins. This ensures that core branding elements are consistent across the shop-mobile-ionic, merchant-tablet-ionic, and carrier-mobile-ionic applications.
Admin Web Angular Theming (Nebular)
The admin application (admin-web-angular) is built with Angular and uses the ngx-admin template, which relies on the Nebular UI library for its components and theming system. Themes are defined as TypeScript objects and registered within an Angular module, which are then translated into CSS custom properties at runtime.
Theme Registration
Themes are registered in the ThemeModule using NbThemeModule.forRoot(). This method takes a configuration object specifying the available themes and the default theme name.
The following diagram illustrates the flow of how a theme is registered and applied in the Admin application.
The ThemeModule registers multiple themes, with everlight set as the default.
| Theme Name | Constant | Source File |
|---|---|---|
default | DEFAULT_THEME | theme.default.ts |
cosmic | COSMIC_THEME | theme.cosmic.ts |
corporate | CORPORATE_THEME | theme.corporate.ts |
everdark | EVERDARK_THEME | theme.everdark.ts |
everlight | EVERLIGHT_THEME | theme.everlight.ts |
dark | DARK_THEME | theme.dark.ts |
| Sources: packages/admin-web-angular/src/app/@theme/theme.module.ts:84-90 |
Theme Definition
Each theme is a TypeScript object that maps Nebular's abstract variable names to specific color values. For example, the EVERDARK_THEME defines a dark color palette.
// packages/admin-web-angular/src/app/@theme/styles/theme.everdark.ts
export const EVERDARK_THEME = {
name: 'everdark',
base: 'dark',
variables: {
// Brand colors
primary: '#4749a5',
success: '#00d68f',
info: '#0095ff',
warning: '#ffaa00',
danger: '#ff3d71',
// Other variables
'color-primary-100': '#33357f',
'color-primary-200': '#3e4090',
// ... more variables
}
}
Sources: packages/admin-web-angular/src/app/@theme/styles/theme.everdark.ts
Applying Themes with SCSS
The themes.scss file is the bridge between the TypeScript theme definitions and the final CSS. It uses the nb-install-global() mixin to set up the Nebular theming engine and the nb-theme() mixin to apply the theme variables to CSS properties for all registered themes.
// packages/admin-web-angular/src/app/@theme/styles/themes.scss
@import '~@nebular/theme/styles/theming';
@import '~@nebular/theme/styles/themes/default';
// ... other theme imports
@mixin nb-install-global() {
@include nb-theme-global();
}
// ...
@include nb-install-global();
// ...
// register the theme and its variables
@include nb-theme(
$default-theme,
'default'
);
// ... other theme registrations
Sources: packages/admin-web-angular/src/app/@theme/styles/themes.scss
Ionic Apps Theming (SCSS Variables)
The mobile applications for Shop, Merchant, and Carrier are built with Ionic/Angular. They share a common set of styles and variables defined in @ever-platform/common-angular/src/scss/everbie.common.scss. Each application's global.scss file imports this common file and adds its own specific styles.
Shared Styles and Variables
The everbie.common.scss file is the foundation for styling across Ionic apps. It defines key brand colors and utility mixins.
The diagram below shows how different Ionic apps share the common SCSS file.
Key Color Variables:
| Variable | Value | Description |
|---|---|---|
$brand | #2a2c39 | The main brand color. |
$brand-lighted | #353748 | A lighter shade of the brand color. |
$brand-darken | #1f212a | A darker shade of the brand color. |
$assertive | #bd4742 | A color used for warnings or destructive actions. |
$balanced | #33cd5f | A color used for success states. |
| Sources: packages/common-angular/src/scss/everbie.common.scss:5-12 |
Application-Specific Styles
Each Ionic app's global.scss file imports the common styles and then applies them. For example, the shop-mobile-ionic app sets the background color for all pages using a variable from the common file.
// packages/shop-mobile-ionic/src/global.scss
@import '~@ever-platform/common-angular/src/scss/everbie.common';
// ...
.ion-page {
background-color: $brand-darken;
}
Sources: packages/shop-mobile-ionic/src/global.scss:19,29-31
Shop Web Angular Theming (Angular Material)
The shop-web-angular application uses Angular Material and its Sass-based theming system. This approach is distinct from the Nebular system in the admin app.
Material Theme Definition
The theme is defined in packages/shop-web-angular/src/styles/styles.scss. It involves:
- Importing
@angular/material/theming. - Defining color palettes using
mat-palettewith custom color variables. - Creating a theme map with
mat-light-theme. - Applying the theme to all Angular Material components with the
angular-material-thememixin.
// packages/shop-web-angular/src/styles/styles.scss
@import 'variables';
@import '@angular/material/theming';
@import '~bootstrap/dist/css/bootstrap.min.css';
// ...
@include mat-core();
// Define the palettes for your theme
$app-primary: mat-palette($ever-md-primary);
$app-accent: mat-palette($ever-md-accent);
// The warn palette is optional (defaults to red).
$app-warn: mat-palette($ever-md-accent);
// Create the theme object
$app-theme: mat-light-theme($app-primary, $app-accent, $app-warn);
// Include theme styles for core and each component used in your app.
@include angular-material-theme($app-theme);
Sources: packages/shop-web-angular/src/styles/styles.scss:2-23
Summary
The Ever-Demand platform demonstrates a flexible and robust theming architecture by selecting the best tool for each frontend application. Nebular provides a powerful, JavaScript-configurable system for the complex admin dashboard. A shared SCSS variable file offers a simple and effective way to maintain brand consistency across multiple Ionic mobile apps. Finally, Angular Material's theming system is used for the customer-facing web shop. This separation of concerns ensures that each application's look and feel can be managed independently while adhering to a common brand identity where necessary.