Skip to content

Commit 6a4ec8f

Browse files
authored
Watch Days Initialize (#71)
1 parent e3cc91b commit 6a4ec8f

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

CodeBeam.MudExtensions/Components/Watch/MudWatch.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<div class="@Classname" style="@Style">
66
@if (Wheel)
77
{
8+
@if (ShowDay)
9+
{
10+
<MudWheel @ref="_wheelDay" Class="mud-width-full" @bind-Value="_day" ItemCollection="Days" WheelLevel="0" Dense="@Dense" Color="@Color" ToStringFunc="new Func<int, string>(NumberToString)" />
11+
}
812
@if (ShowHour)
913
{
1014
<MudWheel @ref="_wheelHour" Class="mud-width-full" @bind-Value="_hour" ItemCollection="Hours" WheelLevel="0" Dense="@Dense" Color="@Color" ToStringFunc="new Func<int, string>(NumberToString)" />

CodeBeam.MudExtensions/Components/Watch/MudWatch.razor.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public partial class MudWatch : MudComponentBase
1717
.AddClass(Class)
1818
.Build();
1919

20+
MudWheel<int> _wheelDay;
2021
MudWheel<int> _wheelHour;
2122
MudWheel<int> _wheelMinute;
2223
MudWheel<int> _wheelSecond;
@@ -42,7 +43,7 @@ protected override void OnInitialized()
4243

4344
if (Mode == WatchMode.Watch)
4445
{
45-
SetWatchMode(Mode);
46+
SetWatchMode(Mode).AndForget();
4647
Start();
4748
}
4849
}
@@ -93,7 +94,7 @@ public WatchMode Mode
9394
return;
9495
}
9596
_watchMode = value;
96-
SetWatchMode(_watchMode);
97+
SetWatchMode(_watchMode).AndForget();
9798
}
9899
}
99100

@@ -108,6 +109,13 @@ public WatchMode Mode
108109
[Category(CategoryTypes.FormComponent.Appearance)]
109110
public string Delimiter { get; set; } = ":";
110111

112+
/// <summary>
113+
/// If true, components shows days. Default is false.
114+
/// </summary>
115+
[Parameter]
116+
[Category(CategoryTypes.FormComponent.Appearance)]
117+
public bool ShowDay { get; set; } = false;
118+
111119
/// <summary>
112120
/// If true, components shows hours. Default is true.
113121
/// </summary>
@@ -185,6 +193,8 @@ public WatchMode Mode
185193
[Category(CategoryTypes.FormComponent.Appearance)]
186194
public Color Color { get; set; }
187195

196+
int _day = 0;
197+
internal List<int> Days { get; set; } = Enumerable.Range(0, 3600).ToList();
188198

189199
int _hour = 0;
190200
internal List<int> Hours { get; set; } = Enumerable.Range(0, 24).ToList();
@@ -282,7 +292,7 @@ public async Task Stop()
282292
await InvokeAsync(StateHasChanged);
283293
}
284294

285-
public async void Reset()
295+
public async Task Reset()
286296
{
287297
if (Mode == WatchMode.Watch)
288298
{
@@ -296,10 +306,13 @@ public async void Reset()
296306
await LapRecordsChanged.InvokeAsync();
297307
return;
298308
}
299-
_stopwatch.Reset();
300-
Value = TimeSpan.Zero;
301-
LapRecords.Clear();
302-
await LapRecordsChanged.InvokeAsync();
309+
else
310+
{
311+
_stopwatch.Reset();
312+
Value = TimeSpan.Zero;
313+
LapRecords.Clear();
314+
await LapRecordsChanged.InvokeAsync();
315+
}
303316
}
304317

305318
public void Start()
@@ -323,7 +336,7 @@ public async void Lap()
323336
await LapRecordsChanged.InvokeAsync();
324337
}
325338

326-
protected void SetWatchMode(WatchMode mode)
339+
protected async Task SetWatchMode(WatchMode mode)
327340
{
328341
if (mode == WatchMode.Watch)
329342
{
@@ -338,7 +351,7 @@ protected void SetWatchMode(WatchMode mode)
338351
{
339352
Interval = TimeSpan.FromMilliseconds(1);
340353
Value = TimeSpan.Zero;
341-
Reset();
354+
await Reset();
342355
ShowHour = true;
343356
ShowMinute = true;
344357
ShowSecond = true;
@@ -347,16 +360,18 @@ protected void SetWatchMode(WatchMode mode)
347360
else if (mode == WatchMode.CountDown)
348361
{
349362
Interval = TimeSpan.FromMilliseconds(1);
350-
Reset();
363+
await Reset();
351364
ShowHour = true;
352365
ShowMinute = true;
353366
ShowSecond = true;
354367
ShowMillisecond = true;
355368
}
369+
StateHasChanged();
356370
}
357371

358372
protected void SetInternalValues()
359373
{
374+
_day = Value.Days;
360375
_hour = Value.Hours;
361376
_minute = Value.Minutes;
362377
_second = Value.Seconds;
@@ -366,6 +381,10 @@ protected void SetInternalValues()
366381
protected string GetWatchText()
367382
{
368383
List<string> ls = new();
384+
if (ShowDay)
385+
{
386+
ls.Add(_day.ToString("D2"));
387+
}
369388
if (ShowHour)
370389
{
371390
ls.Add(_hour.ToString("D2"));

ComponentViewer.Docs/Pages/Examples/WatchExample1.razor

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
<MudSelectItem Value="item">@item.ToDescriptionString()</MudSelectItem>
3232
}
3333
</MudSelect>
34-
<MudSwitch @bind-Checked="_wheel" Color="Color.Primary" Label="Wheel" />
35-
<div class="d-flex flex-wrap">
36-
<MudSwitch @bind-Checked="_showHour" Color="Color.Primary" Label="Show Hour" />
37-
<MudSwitch @bind-Checked="_showMinute" Color="Color.Primary" Label="Show Minute" />
38-
<MudSwitch @bind-Checked="_showSecond" Color="Color.Primary" Label="Show Second" />
39-
<MudSwitch @bind-Checked="_showMillisecond" Color="Color.Primary" Label="Show Millisecond" />
34+
<MudSwitchM3 @bind-Checked="_wheel" Color="Color.Primary" Label="Wheel" />
35+
<div class="d-flex flex-wrap gap-4">
36+
<MudSwitchM3 @bind-Checked="_showHour" Color="Color.Primary" Label="Show Hour" />
37+
<MudSwitchM3 @bind-Checked="_showMinute" Color="Color.Primary" Label="Show Minute" />
38+
<MudSwitchM3 @bind-Checked="_showSecond" Color="Color.Primary" Label="Show Second" />
39+
<MudSwitchM3 @bind-Checked="_showMillisecond" Color="Color.Primary" Label="Show Millisecond" />
4040
</div>
4141
<MudTextField @bind-Value="_delimiter" Variant="Variant.Outlined" Label="Delimiter" />
4242
<MudSelect @bind-Value="_typo" Variant="Variant.Outlined" Label="Typo">

0 commit comments

Comments
 (0)