-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathMudBarcode.razor.cs
More file actions
147 lines (126 loc) · 4.15 KB
/
MudBarcode.razor.cs
File metadata and controls
147 lines (126 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using Microsoft.AspNetCore.Components;
using MudBlazor;
using MudBlazor.Utilities;
using ZXing;
namespace MudExtensions
{
/// <summary>
///
/// </summary>
public partial class MudBarcode : MudComponentBase
{
/// <summary>
///
/// </summary>
protected string? OuterStylename =>
new StyleBuilder()
.AddStyle("height", Height + "px")
.AddStyle("width", Width + "px")
.AddStyle(OuterStyle)
.Build();
private static readonly Writer Encoder = new MultiFormatWriter();
/// <summary>
/// Determines which barcode format will shown. Default is QR Code.
/// </summary>
[Parameter]
public BarcodeFormat BarcodeFormat { get; set; } = BarcodeFormat.QR_CODE;
/// <summary>
/// The outer div classname.
/// </summary>
[Parameter]
public string? OuterClass { get; set; }
/// <summary>
/// The outer div classname.
/// </summary>
[Parameter]
public string? OuterStyle { get; set; }
/// <summary>
/// The image source shows when the value is null.
/// </summary>
[Parameter]
public string? EmptySrc { get; set; }
/// <summary>
/// If true, it goes to specified href when click.
/// </summary>
[Parameter]
public bool Clickable { get; set; }
/// <summary>
/// The error content.
/// </summary>
[Parameter]
public string? ErrorText { get; set; }
/// <summary>
/// The width value as integer.
/// </summary>
[Parameter]
public int Width { get; set; } = 200;
/// <summary>
/// The height value as integer.
/// </summary>
[Parameter]
public int Height { get; set; } = 200;
/// <summary>
/// Use this value on not square sized barcode formats like UPC_A and UPC_E.
/// </summary>
[Parameter]
public int ForceHeight { get; set; } = 1;
/// <summary>
/// Increase the stroke width if readers can not read the barcode easily.
/// </summary>
[Parameter]
public double StrokeWidth { get; set; }
/// <summary>
/// Determines how user go to href content. Default is open in a new tab.
/// </summary>
[Parameter]
public string? Target { get; set; } = "_blank";
/// <summary>
/// The value of the barcode format.
/// </summary>
[Parameter]
public string? Value { get; set; }
/// <summary>
/// The color of the barcode as string. Accepts all kinds of CSS property values. (ex. #123456) Default is "black".
/// </summary>
[Parameter]
public string? Color { get; set; } = "black";
/// <summary>
/// The background color of the barcode as string. Accepts all kinds of CSS property values. (ex. #123456) Default is "white".
/// </summary>
[Parameter]
public string? BackgroundColor { get; set; } = "white";
/// <summary>
/// Fires when value changed.
/// </summary>
[Parameter]
public EventCallback<string> ValueChanged { get; set; }
/// <summary>
/// Shows a component inside the barcode.
/// </summary>
[Parameter]
public RenderFragment? ChildContent { get; set; }
/// <summary>
/// Barcode process that returns BarcodeResult. Returns null if value is also null or empty.
/// </summary>
/// <returns></returns>
protected BarcodeResult? GetCode()
{
if (string.IsNullOrEmpty(Value))
{
return null;
}
try
{
var matrix = Encoder.encode(Value, BarcodeFormat, 0, 0);
var result = new BarcodeResult(matrix, 1, ForceHeight);
ErrorText = null;
return result;
}
catch (Exception ex)
{
ErrorText = ex.Message;
return null;
}
}
}
}