# SbThemeProvider The root theming component that provides theme context to all child SufiBlazor components. Manages dark/light mode and text direction (LTR/RTL). ## Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | Theme | SbTheme? | null | Theme configuration to apply | | IsDark | bool | false | Enables dark mode (overrides Theme.IsDark) | | Direction | SbDirection | Ltr | Text and layout direction (Ltr, Rtl) | | Class | string? | null | Additional CSS classes | | AdditionalAttributes | Dictionary? | null | Additional HTML attributes | ## Templates / Slots | Slot | Type | Description | |------|------|-------------| | ChildContent | RenderFragment? | Application content wrapped by the provider | ## Theme Presets | Value | Description | |-------|-------------| | SbTheme.Light | Light theme preset | | SbTheme.Dark | Dark theme preset | ## Direction Options | Value | Description | |-------|-------------| | SbDirection.Ltr | Left-to-right (default) | | SbDirection.Rtl | Right-to-left | ## Cascading Value The component cascades an `SbThemeContext` object containing: - `Theme` - Current theme settings - `IsDark` - Whether dark mode is active - `Direction` - Current text direction - `DirectionAttribute` - "ltr" or "rtl" string ## CSS Classes Applied - `sb-theme-root` - Always applied - `sb-theme-light` - Light mode - `sb-theme-dark` - Dark mode - `sb-rtl` - RTL direction ## HTML Attributes - `dir="ltr"` or `dir="rtl"` - Direction attribute ## Examples ### Basic Setup Place `SbThemeProvider` at the root of your application: ```razor @* App.razor or MainLayout.razor *@ ``` ### Dark Mode ```razor @* All components will use dark theme *@

This card uses dark theme

``` ### Toggle Dark Mode ```razor

Theme-aware content

@code { private bool isDarkMode = false; } ``` ### RTL Support ```razor

محتوای راست به چپ

``` ### Using Theme Preset ```razor

Using dark theme preset

``` ### Full Application Setup App shell and top bar are provided by the **Wish theme** (e.g. `WishAppShell`, `WishTopBar`). For a minimal layout using only SufiBlazor primitives: ```razor @* Minimal layout using design system only *@ @inherits LayoutComponentBase LTR RTL @Body @code { private bool _isDarkMode = false; private string _directionValue = "ltr"; private SbDirection _direction => _directionValue == "rtl" ? SbDirection.Rtl : SbDirection.Ltr; private void ToggleTheme() { _isDarkMode = !_isDarkMode; } } ``` ### Accessing Theme Context Child components can access the theme context via cascading parameter: ```razor @code { [CascadingParameter] public SbThemeContext? ThemeContext { get; set; } protected override void OnParametersSet() { if (ThemeContext?.IsDark == true) { // Adjust component for dark mode } } } ``` ### Nested Theme Providers You can nest providers for local theme overrides: ```razor

Light theme card

This card is dark themed

``` ### Persisting Theme Preference ```razor @inject IJSRuntime JS @code { private bool _isDarkMode; protected override async Task OnInitializedAsync() { var stored = await JS.InvokeAsync("localStorage.getItem", "theme"); _isDarkMode = stored == "dark"; } private async Task SetDarkMode(bool value) { _isDarkMode = value; await JS.InvokeVoidAsync("localStorage.setItem", "theme", value ? "dark" : "light"); } } ```