Skip to content

Commit 656c341

Browse files
authored
MudDateWheelPicker (#31)
* DateWheelPicker Initialize * Other parameters * Some fixes * API & Cleanup
1 parent f9ecb4e commit 656c341

14 files changed

Lines changed: 664 additions & 40 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
@namespace MudExtensions
2+
@inherits MudBaseInput<DateTime?>
3+
4+
<CascadingValue Name="SubscribeToParentForm" Value="false" IsFixed="true">
5+
<div>
6+
<MudInputControl Label="@Label" Variant="@Variant" HelperText="@HelperText" HelperTextOnFocus="@HelperTextOnFocus" FullWidth="@FullWidth" Margin="@Margin" Class="@Classname" Style="@Style"
7+
Error="@Error" ErrorText="@ErrorText" ErrorId="@ErrorId" Disabled="@Disabled" @onclick="@(Editable ? null : ToggleMenu)" Required="@Required" ForId="@FieldId">
8+
<InputContent>
9+
<MudInput
10+
@ref="InputReference" Margin="@Margin" Placeholder="@Placeholder"
11+
Variant="@Variant" InputType="InputType.Text"
12+
TextUpdateSuppression="false"
13+
Value="@(Text)" DisableUnderLine="@DisableUnderLine"
14+
Disabled="@Disabled" ReadOnly="!Editable" Error="@Error" ErrorId="@ErrorId"
15+
OnAdornmentClick="HandleAdornmentClick" AdornmentIcon="@_currentIcon" Adornment="Adornment.End"
16+
AdornmentColor="@AdornmentColor" IconSize="@IconSize" OnBlur="HandleOnBlur"
17+
Clearable="@Clearable" OnClearButtonClick="HandleClearButtonClick"
18+
@attributes="UserAttributes" />
19+
<MudPopover Class="" Open=@(_isOpen) MaxHeight="@MaxHeight" AnchorOrigin="@AnchorOrigin" TransformOrigin="@TransformOrigin" RelativeWidth="true">
20+
@if (ShowToolbar || SubmitOnClose == false)
21+
{
22+
<div class="d-flex">
23+
@if (SubmitOnClose == false)
24+
{
25+
<MudIconButton Icon="@Icons.Filled.Done" Color="@Color" OnClick="@(() => CloseMenu(true))" />
26+
}
27+
<MudSpacer />
28+
@if (ShowToolbar)
29+
{
30+
<MudIconButton Icon="@Icons.Filled.Sync" Color="@Color" Disabled="@(DateView == DateView.Both)" OnClick="@(() => ToggleDateView())" />
31+
<MudIconButton Icon="@(DateView == DateView.Both ? Icons.Filled.ChevronLeft : Icons.Filled.ChevronRight)" Color="@Color" OnClick="@(() => ExpandDateView())" />
32+
}
33+
</div>
34+
}
35+
36+
<div class="d-flex">
37+
@if (DateView == DateView.Date || DateView == DateView.Both)
38+
{
39+
int yearIndex = DateFormat.IndexOf('y');
40+
int monthIndex = DateFormat.IndexOf('M');
41+
int dayIndex = DateFormat.IndexOf('d');
42+
@if (yearIndex < dayIndex)
43+
{
44+
<MudWheel Class="mud-width-full" @bind-Value="_year" ItemCollection="Years" Label="@(ShowHeader ? LocalizedStrings.Year : null)" Dense="@Dense" Color="@Color" Disabled="FixYear" />
45+
<MudWheel Class="mud-width-full" @bind-Value="_month" ItemCollection="Months" Label="@(ShowHeader ? LocalizedStrings.Month : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixMonth" />
46+
<MudWheel Class="mud-width-full" @bind-Value="_day" ItemCollection="Days" Label="@(ShowHeader ? LocalizedStrings.Day : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixDay" />
47+
}
48+
else if (monthIndex < dayIndex && dayIndex < yearIndex )
49+
{
50+
<MudWheel Class="mud-width-full" @bind-Value="_month" ItemCollection="Months" Label="@(ShowHeader ? LocalizedStrings.Month : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixMonth" />
51+
<MudWheel Class="mud-width-full" @bind-Value="_day" ItemCollection="Days" Label="@(ShowHeader ? LocalizedStrings.Day : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixDay" />
52+
<MudWheel Class="mud-width-full" @bind-Value="_year" ItemCollection="Years" Label="@(ShowHeader ? LocalizedStrings.Year : null)" Dense="@Dense" Color="@Color" Disabled="FixYear" />
53+
}
54+
else
55+
{
56+
<MudWheel Class="mud-width-full" @bind-Value="_day" ItemCollection="Days" Label="@(ShowHeader ? LocalizedStrings.Day : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixDay" />
57+
<MudWheel Class="mud-width-full" @bind-Value="_month" ItemCollection="Months" Label="@(ShowHeader ? LocalizedStrings.Month : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@Color" Disabled="FixMonth" />
58+
<MudWheel Class="mud-width-full" @bind-Value="_year" ItemCollection="Years" Label="@(ShowHeader ? LocalizedStrings.Year : null)" Dense="@Dense" Color="@Color" Disabled="FixYear" />
59+
}
60+
}
61+
@if (DateView == DateView.Time || DateView == DateView.Both)
62+
{
63+
<MudWheel Class="mud-width-full" @bind-Value="_hour" ItemCollection="Hours" Label="@(ShowHeader ? LocalizedStrings.Hour : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@(ColorTime == Color.Inherit ? Color : ColorTime)" Disabled="FixHour" />
64+
<MudWheel Class="mud-width-full" @bind-Value="_minute" ItemCollection="Minutes" Label="@(ShowHeader ? LocalizedStrings.Minute : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@(ColorTime == Color.Inherit ? Color : ColorTime)" Disabled="FixMinute" />
65+
@if (HasSeconds())
66+
{
67+
<MudWheel Class="mud-width-full" @bind-Value="_second" ItemCollection="Seconds" Label="@(ShowHeader ? LocalizedStrings.Second : null)" ToStringFunc="new Func<int, string>(NumberToString)" Dense="@Dense" Color="@(ColorTime == Color.Inherit ? Color : ColorTime)" Disabled="FixSecond" />
68+
}
69+
}
70+
</div>
71+
</MudPopover>
72+
</InputContent>
73+
</MudInputControl>
74+
</div>
75+
76+
</CascadingValue>
77+
<!-- mousedown instead of click needed to close the menu before OnLostFocus runs -->
78+
<MudOverlay Visible="_isOpen" @onmousedown="@(() => CloseMenu(SubmitOnClose))" LockScroll="@LockScroll" />

0 commit comments

Comments
 (0)