true-perfect-code
Version: 1.1.69

P11MonoMode (Mono-Theme Switcher)

The P11MonoMode component provides essential accessibility features by allowing users to toggle a high-contrast monochromatic theme. Users can select custom **Primary** (foreground) and **Secondary** (background) colors, which are dynamically applied to specific CSS variables (`--light` and `--dark`) across the application to enhance readability.
This component is best used with the **Two-Way-Binding** feature (@bind-ValueSwitch, @bind-ValuePrimary, @bind-ValueSecondary) to manage the state (on/off and selected colors) from a parent component.

Application example and live preview

Below is a demonstration of the P11MonoMode component. Note how the Mono-Mode requires the application to utilize CSS variables (like --tpc-color-light and --tpc-color-dark) in its general styling for the effect to work.

#ffffff
#000000
Current status:

Mono mode active: False

Primary color: #ffffff

Secondary color: #000000


Implementation

<P11MonoMode @bind-ValueSwitch="_valueSwitch"
             LabelSwitch="Enable Monomode"
             LabelPrimary="Primary color (Background)"
             @bind-ValuePrimary="_valuePrimary"
             LabelSecondary="Secondary color (Foreground)"
             @bind-ValueSecondary="_valueSecondary"
             CssCustomerDefault="@_cssDefault"
             CssCustomerMono="@_cssMono"
             ButtonOrientation="ButtonOrientation.Vertical"
             GapSize="3" />

<div class="mt-4 p-3 border rounded">
    <strong>Current status:</strong>
    <p>Mono mode active: <code>@_valueSwitch</code></p>
    <p>Primary color: <code>@_valuePrimary</code></p>
    <p>Secondary color: <code>@_valueSecondary</code></p>
</div>              
@code {
    private bool _valueSwitch = false;
    private string _valuePrimary = "#ffffff";
    private string _valueSecondary = "#000000";

    private readonly string _cssDefault = CssColorThemeBootstrapAndMono.CssBootstrapColor;
    private readonly string _cssMono = CssColorThemeBootstrapAndMono.CssMonoColor;
}               


Custom CSS Variables and Fallbacks

When providing custom CSS strings via CssCustomerDefault and CssCustomerMono, it is crucial to also specify the names of the CSS variables that the component should update with the user-selected colors. This is done using the CssVariableLight and CssVariableDark parameters.

Example CSS Variable Definition (In your custom .css files)
:root {
    /* Set by ValuePrimary (Light/Background) */
    --my-primary-color: #FFFFFF;
    --my-primary-color-rgb: 255, 255, 255;
    
    /* Set by ValueSecondary (Dark/Foreground) */
    --my-secondary-color: #0A0A0A;
    --my-secondary-color-rgb: 10, 10, 10;
}
.my-mono-theme {
    color: var(--my-secondary-color);
    background-color: var(--my-primary-color);
}


Component API (P11MonoMode)

Parameter Type Default Description
ValueSwitch / @bind-ValueSwitch bool false The Two-Way-Bound state of the Mono-Mode switch. true activates the mono theme.
ValuePrimary / @bind-ValuePrimary string string.Empty (Defaults to #FFFFFF internally) The Two-Way-Bound color string for the **Primary** color selection (e.g., **Light/Background**). Must be a valid HEX color string.
ValueSecondary / @bind-ValueSecondary string string.Empty (Defaults to #000000 internally) The Two-Way-Bound color string for the **Secondary** color selection (e.g., **Dark/Foreground**). Must be a valid HEX color string.
UseCssDefault bool false When set to true, forces the use of internal default Bootstrap CSS settings instead of custom CSS.
CssCustomerDefault string? null Optional string containing the custom CSS definitions to be applied when the Mono-Mode switch is **OFF** (default theme).
CssCustomerMono string? null Optional string containing the custom CSS definitions to be applied when the Mono-Mode switch is **ON** (mono theme).
CssVariableLight string? null The CSS variable name (e.g., --tpc-color-light) that should be updated with the value of ValuePrimary.
CssVariableLightRGB string? null The CSS variable name (e.g., --tpc-color-light-rgb) that should be updated with the RGB value corresponding to ValuePrimary.
CssVariableDark string? null The CSS variable name (e.g., --tpc-color-dark) that should be updated with the value of ValueSecondary.
CssVariableDarkRGB string? null The CSS variable name (e.g., --tpc-color-dark-rgb) that should be updated with the RGB value corresponding to ValueSecondary.
LabelSwitch string? null Optional label for the main toggle switch.
LabelPrimary string? null Optional label displayed above the primary color selection control.
LabelSecondary string? null Optional label displayed above the secondary color selection control.
IsSwitch bool true If set to false, the toggle switch control will be hidden.
ShowHexValuePrimary bool true Controls the visibility of the HEX color code next to the primary color selector.
ShowHexValueSecondary bool true Controls the visibility of the HEX color code next to the secondary color selector.
DescriptionPrimary string? null Optional helper text displayed below the primary color selector.
DescriptionSecondary string? null Optional helper text displayed below the secondary color selector.
ButtonOrientation ButtonOrientation Horizontal Defines the layout of the color pickers and switch (Horizontal or Vertical).
GapSize int 2 Controls the spacing (gap) between controls, based on Bootstrap's g-* utility classes (0-5).
CssClassContainer string? null Optional CSS class to be applied to the main wrapper div of the component.
CssClassPrimary string? null Optional CSS class for the primary color selector input.
CssClassSecondary string? null Optional CSS class for the secondary color selector input.
AriaLabelPrimary string "Select primary color" ARIA label for accessibility of the primary color selector.
AriaLabelSecondary string "Select Secondary color" ARIA label for accessibility of the secondary color selector.
Inherited Parameters
Id string? null The optional unique ID for the component's root element.
IsDisabled bool false When set to true, the component will be displayed in a disabled state, preventing user interaction.
An unhandled error has occurred. Reload 🗙