Skip to content

Commit

Permalink
Merge branch 'master' into feature/InternalTypeLinksFix
Browse files Browse the repository at this point in the history
  • Loading branch information
Harvey1214 committed Nov 29, 2023
2 parents a17d2b8 + 61d1048 commit 7fa1aab
Show file tree
Hide file tree
Showing 95 changed files with 696 additions and 268 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Setup .NET 7
uses: actions/setup-dotnet@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion BlazorAppTest/BlazorAppTest.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
13 changes: 13 additions & 0 deletions BlazorAppTest/Pages/HxCalendarComponents/ZonedTimeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BlazorAppTest.Pages.HxCalendarComponents;

public class ZonedTimeProvider : TimeProvider
{
private TimeZoneInfo zoneInfo;

public ZonedTimeProvider(TimeZoneInfo zoneInfo)
{
this.zoneInfo = zoneInfo;
}

public override TimeZoneInfo LocalTimeZone { get => zoneInfo; }
}
44 changes: 44 additions & 0 deletions BlazorAppTest/Pages/HxCalendar_Issue597_Test.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@page "/HxCalendar_Issue597_Test"
@using BlazorAppTest.Pages.HxCalendarComponents;
@inject TimeProvider SystemTimeProvider
<h1>HxCalendar</h1>
<fieldset class="m-2 p-2">
<label>From DI: @(SystemTimeProvider.LocalTimeZone.Id)</label>
<div>
<HxCalendar />
</div>
</fieldset>

<fieldset class="m-2 p-2">
<label>From Settings: @(AppCalendarSettings.AmericanSamoa.TimeProvider.LocalTimeZone.Id)</label>
<div><HxCalendar Settings="AppCalendarSettings.AmericanSamoa" /></div>
</fieldset>

<fieldset class="m-2 p-2">
<label>From Settings: @(AppCalendarSettings.Samoa.TimeProvider.LocalTimeZone.Id)</label>
<div><HxCalendar Settings="AppCalendarSettings.Samoa" /></div>
</fieldset>

<fieldset class="m-2 p-2">
<label>From Settings: @(timeProviderUtc.LocalTimeZone.Id)</label>
<div><HxCalendar TimeProvider="timeProviderUtc" /></div>
</fieldset>

@code {
private static TimeProvider timeProviderUtc = new ZonedTimeProvider(TimeZoneInfo.Utc);

private class AppCalendarSettings
{
private static TimeProvider timeProviderUtc11 = new ZonedTimeProvider(TimeZoneInfo.FindSystemTimeZoneById("UTC-11"));
private static TimeProvider timeProviderUtc13 = new ZonedTimeProvider(TimeZoneInfo.FindSystemTimeZoneById("Samoa Standard Time"));
public static CalendarSettings AmericanSamoa => new()
{
TimeProvider = timeProviderUtc11,
};
public static CalendarSettings Samoa => new()
{
TimeProvider = timeProviderUtc13,
};
}

}
4 changes: 4 additions & 0 deletions BlazorAppTest/Pages/HxScrollspyTest.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@page "/HxScrollspyTest"
@inject NavigationManager NavigationManager
@{
#pragma warning disable 0618 // HxAnchorFragmentNavigation
}

<h1>Scrollspy Tests</h1>

Expand Down Expand Up @@ -100,4 +103,5 @@
await anchorFragmentNavigationComponent.ScrollToCurrentUriFragmentAsync();
}
}
#pragma warning restore 0618
}
14 changes: 13 additions & 1 deletion BlazorAppTest/Pages/HxSearchBoxTest.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
@page "/HxSearchBoxTest"

<HxSearchBox DataProvider="ProvideSearchResults" Label="Search" ItemTitleSelector="(i) => i.Title" ItemSubtitleSelector="(i) => i.Subtitle" ItemIconSelector="(i) => i.Icon" TItem="SearchBoxItem" >
<HxSearchBox DataProvider="ProvideSearchResults" Label="Search needle in a haystack" InputSize="InputSize.Small" ItemTitleSelector="(i) => i.Title" ItemSubtitleSelector="(i) => i.Subtitle" ItemIconSelector="(i) => i.Icon" TItem="SearchBoxItem">
<DefaultContentTemplate>
<div class="small py-2 px-3 text-muted">Search for Mouse, Table or Door...</div>
</DefaultContentTemplate>
</HxSearchBox>

<HxSearchBox DataProvider="ProvideSearchResults" Label="Search regular stuff" InputSize="InputSize.Regular" ItemTitleSelector="(i) => i.Title" ItemSubtitleSelector="(i) => i.Subtitle" ItemIconSelector="(i) => i.Icon" TItem="SearchBoxItem">
<DefaultContentTemplate>
<div class="small py-2 px-3 text-muted">Search for Mouse, Table or Door...</div>
</DefaultContentTemplate>
</HxSearchBox>

<HxSearchBox DataProvider="ProvideSearchResults" Label="Search huge things" InputSize="InputSize.Large" ItemTitleSelector="(i) => i.Title" ItemSubtitleSelector="(i) => i.Subtitle" ItemIconSelector="(i) => i.Icon" TItem="SearchBoxItem">
<DefaultContentTemplate>
<div class="small py-2 px-3 text-muted">Search for Mouse, Table or Door...</div>
</DefaultContentTemplate>
Expand Down
1 change: 1 addition & 0 deletions BlazorAppTest/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddRazorPages();
services.AddServerSideBlazor();

services.AddHxServices();
services.AddHxMessenger();
services.AddHxMessageBoxHost();
services.AddHxGoogleTagManager(options =>
Expand Down
2 changes: 1 addition & 1 deletion BlazorRTLAppTest/BlazorRTLAppTest.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<LangVersion>latest</LangVersion>

<!-- aligned NuGet PackageVersion for package-bundles -->
<ComponentsPackagesVersion>4.2.6</ComponentsPackagesVersion>
<GrpcPackagesVersion>1.4.4</GrpcPackagesVersion>
<ComponentsPackagesVersion>4.3.4</ComponentsPackagesVersion>
<GrpcPackagesVersion>1.5.0</GrpcPackagesVersion>
</PropertyGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" Condition="Exists($([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../')))"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bunit.web" Version="1.24.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="bunit.web" Version="1.25.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override void OnParametersSet()
{
base.OnParametersSet();

Contract.Requires<InvalidOperationException>(Color != ThemeColor.None, $"Parameter {nameof(Color)} of {nameof(HxBadge)} is required.");
Contract.Requires<InvalidOperationException>(Color != ThemeColor.None, $"Parameter {nameof(Color)} of {nameof(HxAlert)} is required.");
}

public string GetColorCss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ public record CalendarSettings
/// Allows customization of the dates in dropdown calendars.
/// </summary>
public CalendarDateCustomizationProviderDelegate DateCustomizationProvider { get; set; }

/// <summary>
/// TimeProvider to customize the today date
/// </summary>
public TimeProvider TimeProvider { get; set; }

}
21 changes: 18 additions & 3 deletions Havit.Blazor.Components.Web.Bootstrap/Calendar/HxCalendar.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using Microsoft.Extensions.DependencyInjection;

namespace Havit.Blazor.Components.Web.Bootstrap;

Expand Down Expand Up @@ -28,7 +29,7 @@ static HxCalendar()
Defaults = new CalendarSettings()
{
MinDate = DefaultMinDate,
MaxDate = DefaultMaxDate
MaxDate = DefaultMaxDate,
};
}

Expand Down Expand Up @@ -105,6 +106,20 @@ static HxCalendar()
/// </summary>
[Parameter] public bool KeyboardNavigation { get; set; } = true;

// Set during SetParameterSetAsync to make it optional
[Inject] protected TimeProvider TimeProviderFromServices { get; set; }

/// <summary>
/// TimeProvider is resolved in the following order:<br />
/// 1. TimeProvider from this parameter <br />
/// 2. Settings TimeProvider (configurable from <see cref="HxCalendar.Settings"/>)<br />
/// 3. Defaults TimeProvider (configurable from <see cref="HxCalendar.Defaults"/>)<br />
/// 4. TimeProvider from DependencyInjection<br />
/// </summary>
[Parameter] public TimeProvider TimeProvider { get; set; } = null;

protected TimeProvider TimeProviderEffective => TimeProvider ?? GetSettings()?.TimeProvider ?? GetDefaults()?.TimeProvider ?? TimeProviderFromServices;

private CultureInfo Culture => CultureInfo.CurrentUICulture;
private DayOfWeek FirstDayOfWeek => Culture.DateTimeFormat.FirstDayOfWeek;
protected DateTime DisplayMonthFirstDay => new DateTime(DisplayMonth.Year, DisplayMonth.Month, 1);
Expand Down Expand Up @@ -138,7 +153,7 @@ protected override async Task OnParametersSetAsync()

if (DisplayMonth == default)
{
await SetDisplayMonthAsync(Value ?? DateTime.Today);
await SetDisplayMonthAsync(Value ?? TimeProviderEffective.GetLocalNow().Date);
}
else if ((Value != null) && lastKnownValueChanged && ((DisplayMonth.Year != Value.Value.Year) || (DisplayMonth.Month != Value.Value.Month)))
{
Expand Down Expand Up @@ -191,7 +206,7 @@ private void UpdateRenderData()

DateTime currentDay = FirstDayToDisplay;
DateTime valueDay = Value?.Date ?? default;
DateTime today = DateTime.Today;
DateTime today = TimeProviderEffective.GetLocalNow().Date;

for (var week = 0; week < 6; week++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ protected virtual async ValueTask DisposeAsyncCore()
{
// NOOP
}
catch (TaskCanceledException)
{
// NOOP
}
}

dotnetObjectReference?.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ protected virtual async ValueTask DisposeAsyncCore()
{
// NOOP
}
catch (TaskCanceledException)
{
// NOOP
}
}

dotnetObjectReference?.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ protected virtual async ValueTask DisposeAsyncCore()
{
// NOOP
}
catch (TaskCanceledException)
{
// NOOP
}
}

dotnetObjectReference.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ protected virtual async ValueTask DisposeAsyncCore()
{
// NOOP
}
catch (TaskCanceledException)
{
// NOOP
}
}

dotnetObjectReference.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ protected override void BuildRenderInput(RenderTreeBuilder builder)
builder.AddAttribute(1023, nameof(HxAutosuggestInternal<TItem, TValue>.InputGroupStartTemplate), this.InputGroupStartTemplate);
builder.AddAttribute(1024, nameof(HxAutosuggestInternal<TItem, TValue>.InputGroupEndText), this.InputGroupEndText);
builder.AddAttribute(1025, nameof(HxAutosuggestInternal<TItem, TValue>.InputGroupEndTemplate), this.InputGroupEndTemplate);
#if NET8_0_OR_GREATER
builder.AddAttribute(1026, nameof(HxAutosuggestInternal<TItem, TValue>.NameAttributeValue), NameAttributeValue);
#endif

builder.AddMultipleAttributes(2000, this.AdditionalAttributes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<input @ref="InputElement"
id="@InputId"
name="@(String.IsNullOrEmpty(NameAttributeValue) ? null : NameAttributeValue)"
type="text"
class="@CssClass hx-autosuggest-input"
disabled="@(!EnabledEffective)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public partial class HxAutosuggestInputInternal
/// </summary>
[Parameter] public (int Skidding, int Distance) DropdownOffset { get; set; }

[Parameter] public string NameAttributeValue { get; set; }

/// <summary>
/// Additional attributes to be splatted onto an underlying HTML element.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div class="@CssClassHelper.Combine("hx-autosuggest-input-wrapper", (LabelTypeEffective == Havit.Blazor.Components.Web.Bootstrap.LabelType.Floating) ? "form-floating" : null)">
<HxAutosuggestInputInternal @ref="autosuggestInput"
InputId="@InputId"
NameAttributeValue="@NameAttributeValue"
EnabledEffective="@EnabledEffective"
Value="@userInput"
OnInput="HandleInputInput"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public partial class HxAutosuggestInternal<TItem, TValue> : IAsyncDisposable
/// </summary>
[Parameter] public RenderFragment InputGroupEndTemplate { get; set; }

[Parameter] public string NameAttributeValue { get; set; }

/// <summary>
/// Additional attributes to be splatted onto an underlying HTML element.
/// </summary>
Expand Down Expand Up @@ -489,6 +491,10 @@ protected virtual async ValueTask DisposeAsyncCore()
{
// NOOP
}
catch (TaskCanceledException)
{
// NOOP
}
}

dotnetObjectReference?.Dispose();
Expand Down
21 changes: 16 additions & 5 deletions Havit.Blazor.Components.Web.Bootstrap/Forms/HxInputBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,22 @@ private protected virtual void BuildRenderInput_AddCommonAttributes(RenderTreeBu
{
builder.AddMultipleAttributes(1, AdditionalAttributes);
builder.AddAttribute(2, "id", InputId);
builder.AddAttribute(3, "type", typeValue);
builder.AddAttribute(4, "class", GetInputCssClassToRender());
builder.AddAttribute(5, "disabled", !EnabledEffective);
#if NET8_0_OR_GREATER
if (!String.IsNullOrEmpty(this.NameAttributeValue))
{
builder.AddAttribute(3, "name", NameAttributeValue);
}
#endif
builder.AddAttribute(4, "type", typeValue);
builder.AddAttribute(5, "class", GetInputCssClassToRender());
builder.AddAttribute(6, "disabled", !EnabledEffective);
if ((this is IInputWithLabelType inputWithLabelType) && (inputWithLabelType.LabelTypeEffective == LabelType.Floating))
{
builder.AddAttribute(6, "placeholder", "placeholder"); // there must be a nonempty value (which is not visible)
builder.AddAttribute(7, "placeholder", "placeholder"); // there must be a nonempty value (which is not visible)
}
else if (this is IInputWithPlaceholder inputWithPlaceholder)
{
builder.AddAttribute(7, "placeholder", inputWithPlaceholder.Placeholder);
builder.AddAttribute(8, "placeholder", inputWithPlaceholder.Placeholder);
}

}
Expand Down Expand Up @@ -352,6 +358,11 @@ protected virtual void RenderChipGenerator(RenderTreeBuilder builder)
/// </remarks>
protected virtual bool ShouldRenderChipGenerator()
{
if (CurrentValue is string currentValueString)
{
// fixes #659 [HxInputText] Generates chip for String.Empty value
return !String.IsNullOrEmpty(currentValueString);
}
return !EqualityComparer<TValue>.Default.Equals(CurrentValue, default(TValue));
}

Expand Down
Loading

0 comments on commit 7fa1aab

Please sign in to comment.