Table of Contents

Class TwEncodedSymbolBase<TSymbol>

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

The shared behaviour of the scannable symbol components, TwQrCode and TwBarcode: encoding the Value only when it would change, drawing it as one SVG path, naming it for assistive technology and applying the shared theme colors.

public abstract class TwEncodedSymbolBase<TSymbol> : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent where TSymbol : class, IEncodedSymbol

Type Parameters

TSymbol

The kind of symbol the component draws.

Inheritance
TwEncodedSymbolBase<TSymbol>
Implements
Derived
Inherited Members

Constructors

TwEncodedSymbolBase()

protected TwEncodedSymbolBase()

Properties

QuietZone

Gets or sets the light margin around the symbol, in modules.

[Parameter]
public int? QuietZone { get; set; }

Property Value

int?

Remarks

Defaults to null, which uses the margin the symbology needs. Scanners struggle with less unless the symbol already sits on a plain background.

Value

Gets or sets the value to encode. Nothing is rendered while it is empty or cannot be encoded.

[Parameter]
public string? Value { get; set; }

Property Value

string

accessibleName

Gets the accessible name: AriaLabel, or the default name unless AriaLabelledBy names it instead.

protected string? accessibleName { get; }

Property Value

string

encodingSettings

Gets the component's other settings that change the encoding, so a change to any of them re-encodes.

protected virtual object? encodingSettings { get; }

Property Value

object

labelKey

Gets the resource key of the default accessible name, a format string taking labelText.

protected abstract string labelKey { get; }

Property Value

string

labelText

Gets the text the default accessible name describes. Defaults to Value.

protected virtual string labelText { get; }

Property Value

string

path

Gets the SVG path data for the dark modules.

protected string path { get; }

Property Value

string

symbol

Gets the encoded symbol, or null when there is nothing to draw.

protected TSymbol? symbol { get; }

Property Value

TSymbol

viewBox

Gets the SVG viewBox that fits the symbol and its quiet zone.

protected string viewBox { get; }

Property Value

string

Methods

BuildRootClasses(TwEncodedSymbolTheme, string)

Builds the classes for the root element: the theme's structure and colors, then rounding, shadow and Class.

protected string BuildRootClasses(TwEncodedSymbolTheme theme, string leading = "")

Parameters

theme TwEncodedSymbolTheme

The component's theme.

leading string

Extra classes to start with, such as the size.

Returns

string

The merged classes.

OnParametersSet()

Invoked when the component's parameters have been set. Ensures that the component has a unique identifier by generating one if none is provided.

protected override void OnParametersSet()

Remarks

If the component's identifier is not set, a unique ID is generated based on the component's type name (with a 'Tw' prefix removed if present) and a GUID. This helps ensure that each component instance can be uniquely identified, which is useful for scenarios such as associating labels with form elements or targeting elements in client-side scripts.

TryEncode(string, out TSymbol?)

Encodes a value.

protected abstract bool TryEncode(string value, out TSymbol? encoded)

Parameters

value string

The non-empty value to encode.

encoded TSymbol

The encoded symbol, or null when the value cannot be encoded.

Returns

bool

true when the value was encoded.