Table of Contents

Class ColorBuilder

Namespace
TwBlazor.Builders
Assembly
TwBlazor.dll

Provides utility methods for generating CSS class strings based on color values for various UI elements.

public class ColorBuilder
Inheritance
ColorBuilder
Inherited Members

Remarks

The ColorBuilder class includes methods to retrieve CSS class names for text, backgrounds, checkboxes, switches, alerts, and sliders according to a specified color. These methods are intended to standardize the application of color styles in UI components by mapping a Color enumeration value to the appropriate CSS classes. If a null color is provided, the methods return an empty string or a default value, depending on the method. This class is typically used in UI frameworks where consistent color theming is required.

Constructors

ColorBuilder(TwBlazorOptions)

Provides utility methods for generating CSS class strings based on color values for various UI elements.

public ColorBuilder(TwBlazorOptions options)

Parameters

options TwBlazorOptions

Remarks

The ColorBuilder class includes methods to retrieve CSS class names for text, backgrounds, checkboxes, switches, alerts, and sliders according to a specified color. These methods are intended to standardize the application of color styles in UI components by mapping a Color enumeration value to the appropriate CSS classes. If a null color is provided, the methods return an empty string or a default value, depending on the method. This class is typically used in UI frameworks where consistent color theming is required.

Methods

GetBorderColor(Color?)

Gets the border color classes associated with the specified color.

public string GetBorderColor(Color? color)

Parameters

color Color?

The color for which to retrieve the border color. If null or an unsupported color, the default (blue) border color is returned.

Returns

string

A string representing the border color classes for the specified color.

GetFilledVariantColor(Color?)

Gets the filled variant color associated with the specified color.

public string GetFilledVariantColor(Color? color)

Parameters

color Color?

The color for which to retrieve the filled variant. If null or an unsupported color, an empty string is returned.

Returns

string

A string representing the filled variant color corresponding to the specified color. Returns an empty string if the color is not recognized.

Remarks

This method uses a switch expression to map predefined colors to their corresponding filled variant colors in the theme.

GetFocusRing(Color?)

Generates a focus ring style string based on the specified color.

public string GetFocusRing(Color? color)

Parameters

color Color?

The color used to determine the focus ring style. If null or not recognized, the default (blue) focus ring is used.

Returns

string

A string representing the focus ring style for the specified color. Falls back to the blue focus ring if the color is null or not supported.

Remarks

This method maps specific colors to their corresponding focus ring styles as defined in the theme. Buttons in this theme remove the native outline (focus:outline-none), so this ring is the only visible focus indicator - if a null or unrecognized color is passed, the blue focus ring is used as a fallback rather than omitting the ring entirely, to avoid keyboard focus becoming invisible.

GetOutlinedVariantColor(Color?)

Gets the outlined variant color associated with the specified color.

public string GetOutlinedVariantColor(Color? color)

Parameters

color Color?

The color for which to retrieve the outlined variant. If null or an unsupported color, the default (primary) outlined variant is returned.

Returns

string

A string representing the outlined variant color corresponding to the specified color. Falls back to the primary outlined variant if the color is null or not recognized.

Remarks

This method uses a switch expression to map predefined colors to their corresponding outlined variant colors in the theme.

GetPaletteColor(Color?, TwBlazorPalette, string)

Resolves a Color against a component's own TwBlazorPalette (e.g. a theme's Colors property), falling back to fallback when color is null or not recognized.

public static string GetPaletteColor(Color? color, TwBlazorPalette palette, string fallback)

Parameters

color Color?

The color to resolve.

palette TwBlazorPalette

The component theme's color palette to resolve against.

fallback string

The value to return when color is null or unrecognized - typically palette.Primary or Empty, matching the calling component's existing default.

Returns

string

GetTextColor(Color?)

public string GetTextColor(Color? color)

Parameters

color Color?

Returns

string

GetTextVariantColor(Color?)

Gets the text variant color associated with the specified color.

public string GetTextVariantColor(Color? color)

Parameters

color Color?

The color for which to retrieve the text variant. If null or an unsupported color, an empty string is returned.

Returns

string

A string representing the text variant color corresponding to the specified color. Returns an empty string if the color is not recognized.

Remarks

This method uses a switch expression to map predefined colors to their corresponding text variant colors in the theme.