Skip to content

Commit d6b62af

Browse files
committed
Merge branch 'refactor-otp' into doc-authenticator
# Conflicts: # src/BootstrapBlazor/Components/Input/OtpInput.razor # src/BootstrapBlazor/Components/Input/OtpInput.razor.cs # src/BootstrapBlazor/Components/Input/OtpInput.razor.scss
2 parents 57db277 + f618846 commit d6b62af

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

src/BootstrapBlazor/Components/Input/OtpInput.razor

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66
{
77
if (index < _values.Length)
88
{
9-
<span class="@SpanClassString">@_values[index]</span>
9+
@if (IsReadonly || IsDisabled)
10+
{
11+
<span class="@ItemClassString">@_values[index]</span>
12+
}
13+
else
14+
{
15+
<span class="@ItemClassString">
16+
@{
17+
var charIndex = index;
18+
}
19+
<input type="@TypeString" @bind="@_values[charIndex]" />
20+
</span>
21+
}
1022
}
1123
}
1224
</div>

src/BootstrapBlazor/Components/Input/OtpInput.razor.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ public partial class OtpInput
1717
public int Digits { get; set; } = 6;
1818

1919
/// <summary>
20-
///
20+
/// Gets or sets whether the OTP input is readonly. Default is false.
21+
/// </summary>
22+
[Parameter]
23+
public bool IsReadonly { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the value type of the OTP input. Default is <see cref="OtpInputType.Number"/>.
2127
/// </summary>
2228
[Parameter]
2329
public OtpInputType Type { get; set; }
@@ -26,10 +32,18 @@ public partial class OtpInput
2632
.AddClassFromAttributes(AdditionalAttributes)
2733
.Build();
2834

29-
private string? SpanClassString => CssBuilder.Default("bb-opt-span")
35+
private string? ItemClassString => CssBuilder.Default("bb-opt-item")
36+
.AddClass("disabled", IsDisabled)
3037
.AddClass(ValidCss)
3138
.Build();
3239

40+
private string TypeString => Type switch
41+
{
42+
OtpInputType.Number => "number",
43+
OtpInputType.Password => "password",
44+
_ => "text"
45+
};
46+
3347
private char[] _values = [];
3448

3549
/// <summary>
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
.bb-opt-span {
1+
.bb-opt-item {
2+
--bb-opt-item-padding: #{$bb-opt-item-padding};
3+
--bb-opt-item-margin: #{$bb-opt-item-margin};
4+
--bb-opt-font-size: #{$bb-opt-font-size};
5+
--bb-opt-border-width: #{$bb-opt-border-width};
26
display: inline-block;
3-
border: 1px solid var(--bs-border-color);
4-
font-size: 3em;
5-
padding: 0 .5em;
7+
border: var(--bb-opt-border-width) solid var(--bs-border-color);
8+
font-size: var(--bb-opt-font-size);
9+
padding: var(--bb-opt-item-padding);
610
border-radius: var(--bs-border-radius);
711

812
&:not(:last-child) {
9-
margin-right: .5rem;
13+
margin-right: var(--bb-opt-item-margin);
14+
}
15+
16+
&.disabled {
17+
cursor: not-allowed;
18+
}
19+
20+
> input {
1021
}
1122
}

src/BootstrapBlazor/wwwroot/scss/theme/bootstrapblazor.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ $bb-viewer-border-radius: 50%;
314314
// Ip Address
315315
$bb-ip-cell-max-width: 30px;
316316

317+
// OptInput
318+
$bb-opt-item-padding: 0 .5rem;
319+
$bb-opt-item-margin: .5rem;
320+
$bb-opt-font-size: 3em;
321+
$bb-opt-border-width: 1px;
322+
317323
// Layout
318324
$bb-layout-header-height: 50px;
319325
$bb-layout-header-background: #0078d4;

0 commit comments

Comments
 (0)