-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DateSelector component to story book
- Loading branch information
Showing
10 changed files
with
91 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Inc.TeamAssistant.Stories/Components/DateSelector.stories.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
@attribute [Stories("Components/DateSelector")] | ||
|
||
<Stories TComponent="DateSelector" Layout="typeof(LightLayout)"> | ||
<Story Name="Dates"> | ||
<Template> | ||
<DateSelector Date="_date" Items="_dates" OnSelected="SelectDate"/> | ||
</Template> | ||
</Story> | ||
<Story Name="Weeks"> | ||
<Template> | ||
<DateSelector Date="_week" Items="_weeks" OnSelected="SelectWeek"/> | ||
</Template> | ||
</Story> | ||
<Story Name="Months"> | ||
<Template> | ||
<DateSelector Date="_month" Items="_months" OnSelected="SelectMonth"/> | ||
</Template> | ||
</Story> | ||
</Stories> | ||
|
||
@code { | ||
private DateOnly? _date = new(2024, 09, 25); | ||
private DateOnly? _week = DateOnly.FromDateTime(DateTimeOffset.UtcNow.AddDays(-28).Date); | ||
private DateOnly? _month = DateOnly.FromDateTime(DateTimeOffset.UtcNow.AddMonths(-6).Date); | ||
|
||
private readonly IReadOnlyDictionary<string, DateOnly> _dates = new Dictionary<string, DateOnly> | ||
{ | ||
["24-09-25"] = new(2024, 09, 25), | ||
["24-09-11"] = new(2024, 09, 11), | ||
["24-08-28"] = new(2024, 08, 28) | ||
}; | ||
|
||
private readonly IReadOnlyDictionary<string, DateOnly> _weeks = new Dictionary<string, DateOnly> | ||
{ | ||
["2 week"] = DateOnly.FromDateTime(DateTimeOffset.UtcNow.AddDays(-14).Date), | ||
["4 weeks"] = DateOnly.FromDateTime(DateTimeOffset.UtcNow.AddDays(-28).Date), | ||
["12 weeks"] = DateOnly.FromDateTime(DateTimeOffset.UtcNow.AddDays(-84).Date) | ||
}; | ||
|
||
private readonly IReadOnlyDictionary<string, DateOnly> _months = new Dictionary<string, DateOnly> | ||
{ | ||
["1 month"] = DateOnly.FromDateTime(DateTimeOffset.UtcNow.AddMonths(-1).Date), | ||
["3 month"] = DateOnly.FromDateTime(DateTimeOffset.UtcNow.AddMonths(-3).Date), | ||
["6 month"] = DateOnly.FromDateTime(DateTimeOffset.UtcNow.AddMonths(-6).Date) | ||
}; | ||
|
||
private void SelectDate(DateOnly date) => _date = date; | ||
private void SelectWeek(DateOnly date) => _week = date; | ||
private void SelectMonth(DateOnly date) => _month = date; | ||
} |
3 changes: 0 additions & 3 deletions
3
src/Inc.TeamAssistant.Stories/Inc.TeamAssistant.Stories.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
<div class="date-selector"> | ||
@foreach (var item in Items) | ||
{ | ||
<span class="date-selector__item @CssClass(item)" @onclick="() => Selected(item)"> | ||
@item.Title | ||
<span class="date-selector__item @CssClass(item.Value)" @onclick="() => Selected(item.Value)"> | ||
@item.Key | ||
</span> | ||
} | ||
</div> | ||
|
||
@code { | ||
/// <summary> | ||
/// Available for select dates. | ||
/// </summary> | ||
[Parameter, EditorRequired] | ||
public IReadOnlyCollection<SelectItem<DateOnly>> Items { get; set; } = Array.Empty<SelectItem<DateOnly>>(); | ||
public IReadOnlyDictionary<string, DateOnly> Items { get; set; } = new Dictionary<string, DateOnly>(); | ||
|
||
/// <summary> | ||
/// Selected date | ||
/// </summary> | ||
[Parameter, EditorRequired] | ||
public DateOnly? Date { get; set; } | ||
|
||
/// <summary> | ||
/// On selected event | ||
/// </summary> | ||
[Parameter, EditorRequired] | ||
public EventCallback<DateOnly> OnSelected { get; set; } | ||
|
||
private string CssClass(SelectItem<DateOnly> item) => Date == item.Value | ||
private string CssClass(DateOnly value) => Date == value | ||
? "date-selector__item_selected" | ||
: string.Empty; | ||
|
||
private void Selected(SelectItem<DateOnly> item) => OnSelected.InvokeAsync(item.Value); | ||
private void Selected(DateOnly value) => OnSelected.InvokeAsync(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters