Skip to content

Commit d51d5d4

Browse files
authored
Barcode: Add Color, BackgroundColor and StrokeWidth parameters (#194)
* Barcode Color * Remove unnecessary expression
1 parent d55b2e8 commit d51d5d4

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

CodeBeam.MudBlazor.Extensions/Components/Barcode/MudBarcode.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
}
88
@if (content != null)
99
{
10-
<svg width="@Width" height="@Height">
10+
<svg width="@Width" height="@Height" style="background-color:@BackgroundColor">
1111
@for (int y = 0; y < content.Rows; y++)
1212
{
1313
@for(int x = 0; x < content.Columns; x++)
1414
{
1515
@if(content[x,y])
1616
{
17-
<rect width="@content.ModuleSizeX" height="@content.ModuleSizeY" style="fill:black; stroke-width:1px; stroke:black"
17+
<rect class="d-flex align-center justify-center" width="@content.ModuleSizeX" height="@content.ModuleSizeY" style="@($"fill:{Color}; stroke-width:{StrokeWidth}px; stroke:{Color}")"
1818
x="@(x * content.ModuleSizeX)" y="@(y * content.ModuleSizeY)" />
1919
}
2020
}

CodeBeam.MudBlazor.Extensions/Components/Barcode/MudBarcode.razor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public partial class MudBarcode : MudComponentBase
2424
[Parameter]
2525
public int Width { get; set; } = 200;
2626

27+
/// <summary>
28+
/// Increase the stroke width if readers can not read the barcode easily.
29+
/// </summary>
30+
[Parameter]
31+
public int StrokeWidth { get; set; }
32+
2733
[Parameter]
2834
public int Height { get; set; } = 200;
2935

@@ -33,6 +39,12 @@ public partial class MudBarcode : MudComponentBase
3339
[Parameter]
3440
public string Value { get; set; }
3541

42+
[Parameter]
43+
public string Color { get; set; } = "black";
44+
45+
[Parameter]
46+
public string BackgroundColor { get; set; } = "white";
47+
3648
[Parameter]
3749
public EventCallback<string> ValueChanged { get; set; }
3850

ComponentViewer.Docs/Pages/Components/QrCodePage.razor renamed to ComponentViewer.Docs/Pages/Components/BarcodePage.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
@using ComponentViewer.Docs.Pages.Examples
33

44
<ExamplePage Title="MudBarcode">
5+
<ExampleCard ExampleName="BarcodeExampleIntro" Title="Intro & Tips" Description="" ShowCodeSection="false">
6+
<BarcodeExampleIntro />
7+
</ExampleCard>
8+
59
<ExampleCard ExampleName="BarcodeExample1" Title="Usage" Description="Barcode shows different bar codes like QR code with defined value.">
610
<BarcodeExample1 />
711
</ExampleCard>

ComponentViewer.Docs/Pages/Examples/BarcodeExample1.razor

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<MudGrid>
44
<MudItem xs="12" sm="8" Class="d-flex justify-center">
5-
<MudBarcode @ref="_barcode" @bind-Value="_qrValue" Width="_width" Height="_height" BarcodeFormat="_barcodeFormat" Clickable="_clickable" />
5+
<MudBarcode @ref="_barcode" @bind-Value="_qrValue" Width="_width" Height="_height" BarcodeFormat="_barcodeFormat" Clickable="_clickable" Color="@_color" BackgroundColor="@_backgroundColor" StrokeWidth="_strokeWidth" />
66
</MudItem>
77

88
<MudItem xs="12" sm="4">
@@ -13,6 +13,9 @@
1313
<MudSelectExtended ItemCollection="@(Enum.GetValues<BarcodeFormat>())" @bind-Value="_barcodeFormat" Label="Barcode Format" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" />
1414
<MudText Color="Color.Error">@(_barcode.ErrorText == null ? null : "Error: " + _barcode.ErrorText)</MudText>
1515
<MudSwitchM3 @bind-Checked="_clickable" Color="Color.Secondary" Label="Clickable" />
16+
<MudTextField T="string" @bind-Value="_color" Label="Color" Variant="Variant.Outlined" Immediate="true" Margin="Margin.Dense" />
17+
<MudTextField T="string" @bind-Value="_backgroundColor" Label="BackgroundColor" Variant="Variant.Outlined" Immediate="true" Margin="Margin.Dense" />
18+
<MudNumericField @bind-Value="_strokeWidth" Label="StrokeWidth" Min="0" Max="10" Variant="Variant.Outlined" Margin="Margin.Dense" />
1619
</MudStack>
1720
</MudItem>
1821
</MudGrid>
@@ -24,4 +27,7 @@
2427
int _height = 200;
2528
BarcodeFormat _barcodeFormat = BarcodeFormat.QR_CODE;
2629
bool _clickable = false;
30+
string _color = "black";
31+
string _backgroundColor = "white";
32+
int _strokeWidth = 0;
2733
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@using Microsoft.AspNetCore.Components
2+
@using MudBlazor.Extensions
3+
4+
<MudGrid>
5+
<MudAlert Class="mud-width-full" Severity="Severity.Success"><b>If you feel barcode readers response slowly, increase the <CodeBlock>StrokeWidth</CodeBlock> value for a better read performance.</b></MudAlert>
6+
<MudAlert Class="mud-width-full" Severity="Severity.Success"><b>You can independently set height and width, but for some barcode formats like QR, the component have to has same width and height (square sized).</b></MudAlert>
7+
<MudAlert Class="mud-width-full" Severity="Severity.Success"><b>Remember that although you can freely specify colors, can get the best results with the highest contrast.</b></MudAlert>
8+
</MudGrid>

0 commit comments

Comments
 (0)