Skip to content

Commit

Permalink
🆕 feat(compact-date-time-picker): switch to time picker automatically…
Browse files Browse the repository at this point in the history
… when selecting a date
  • Loading branch information
capdiem committed Jun 18, 2024
1 parent df2739f commit 2b30e3d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@inherits PDateDigitalClockPickerViewBase<TValue>
@typeparam TValue

<div class="@ViewModifierBuilder.Build()">
<div class="@ViewModifier">
<MTabs @bind-Value="_tabValue" FixedTabs>
<MTab Value="@DATE" Ripple="false">
@if (InternalDate.HasValue)
Expand Down Expand Up @@ -73,6 +73,7 @@
YearIcon="@YearIcon"
Dark="@Dark"
Light="@Light"
OnDateClick="@HandleOnDateClick"
@ref="_datePicker">
</MDatePicker>
</MWindowItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ public partial class PDateDigitalClockCompactPickerView<TValue> : PDateDigitalCl

[Parameter] public string? Transition { get; set; }

/// <summary>
/// Switch to time picker automatically when selecting a date
/// </summary>
[Parameter] [MasaApiParameter(defaultValue: true, releasedOn: "v1.6.0")]
public bool AutoSwitchToTime { get; set; } = true;

private const string DATE = "date";
private const string TIME = "time";

Expand Down Expand Up @@ -84,4 +90,15 @@ private void OnNextClick()
{
_timeActivePicker = (TimePickerType)(((int)_timeActivePicker) + 1);
}

private void HandleOnDateClick()
{
if (!AutoSwitchToTime)
{
return;
}

_tabValue = TIME;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@inherits PDateTimePickerViewBase<TValue>
@typeparam TValue

<div class="@ViewModifierBuilder.Build()">
<div class="@ViewModifier">
<MTabs @bind-Value="_tabValue" FixedTabs>
<MTab Value="@DATE" Ripple="false">
@if (InternalDate.HasValue)
Expand Down Expand Up @@ -73,6 +73,7 @@
YearIcon="@YearIcon"
Dark="@Dark"
Light="@Light"
OnDateClick="@HandleOnDateClick"
@ref="_datePicker">
</MDatePicker>
</MTabItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public partial class PDateTimeCompactPickerView<TValue> : PDateTimePickerViewBas
[Parameter]
public string? Transition { get; set; }

/// <summary>
/// Switch to time picker automatically when selecting a date
/// </summary>
[Parameter] [MasaApiParameter(defaultValue: true, releasedOn: "v1.6.0")]
public bool AutoSwitchToTime { get; set; } = true;

private const string DATE = "date";
private const string TIME = "time";

Expand Down Expand Up @@ -88,4 +94,14 @@ private void OnNextClick()
{
_timeActivePicker = (TimePickerType)(((int)_timeActivePicker) + 1);
}

private void HandleOnDateClick(DateOnly dateOnly)
{
if (!AutoSwitchToTime)
{
return;
}

_tabValue = TIME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public DateTime? Max

protected static Block BasePickerBlock = new Block("m-date-time-picker");
protected ModifierBuilder BasePickerModifierBuilder = BasePickerBlock.CreateModifierBuilder();
protected ModifierBuilder ViewModifierBuilder =
BasePickerBlock.Element("view").CreateModifierBuilder().Add("compact");
protected string ViewModifier =
BasePickerBlock.Element("view").CreateModifierBuilder().Add("compact").Build();

public bool IsDark
{
Expand Down

0 comments on commit 2b30e3d

Please sign in to comment.