2026-08-11 11:59:18 +02:00
|
|
|
@* TimezoneAutocomplete.razor — sélecteur de fuseau horaire avec recherche + autocomplete.
|
|
|
|
|
La valeur échangée est l'Id IANA (ex: "Europe/Paris"), compatible avec la validation
|
|
|
|
|
backend TimeZoneInfo.FindSystemTimeZoneById (CreateSite/UpdateSite). *@
|
|
|
|
|
|
|
|
|
|
<MudAutocomplete T="TimeZoneInfo"
|
|
|
|
|
Value="_selected"
|
|
|
|
|
ValueChanged="OnSelectedChanged"
|
|
|
|
|
SearchFunc="SearchTimeZones"
|
|
|
|
|
ToStringFunc="@(tz => tz?.Id ?? "")"
|
2026-10-25 05:59:18 +01:00
|
|
|
Label="@EffectiveLabel"
|
|
|
|
|
Placeholder="@EffectivePlaceholder"
|
2026-08-11 11:59:18 +02:00
|
|
|
HelperText="@HelperText"
|
|
|
|
|
Variant="Variant.Outlined"
|
|
|
|
|
Class="@Class"
|
|
|
|
|
Clearable="true"
|
|
|
|
|
CoerceValue="true"
|
|
|
|
|
DebounceInterval="100" />
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
/// <summary>Id IANA du fuseau sélectionné (ex: Europe/Paris), null si vide.</summary>
|
|
|
|
|
[Parameter] public string? Value { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter] public EventCallback<string?> ValueChanged { get; set; }
|
|
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
[Parameter] public string Label { get; set; } = "";
|
2026-08-11 11:59:18 +02:00
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
[Parameter] public string Placeholder { get; set; } = "";
|
2026-08-11 11:59:18 +02:00
|
|
|
|
|
|
|
|
[Parameter] public string? HelperText { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter] public string? Class { get; set; }
|
|
|
|
|
|
|
|
|
|
private static readonly TimeZoneInfo[] AllTimeZones = TimeZoneInfo.GetSystemTimeZones().ToArray();
|
|
|
|
|
|
|
|
|
|
private TimeZoneInfo? _selected;
|
|
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
[Inject] private Heimdall.Web.Services.UiText Text { get; set; } = default!;
|
|
|
|
|
|
|
|
|
|
private string EffectiveLabel => string.IsNullOrEmpty(Label) ? Text["SharedTimezoneAutocomplete_Label"] : Label;
|
|
|
|
|
private string EffectivePlaceholder => string.IsNullOrEmpty(Placeholder) ? Text["SharedTimezoneAutocomplete_Placeholder"] : Placeholder;
|
|
|
|
|
|
2026-08-11 11:59:18 +02:00
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
if (_selected?.Id != Value)
|
|
|
|
|
_selected = string.IsNullOrEmpty(Value)
|
|
|
|
|
? null
|
|
|
|
|
: AllTimeZones.FirstOrDefault(tz => tz.Id == Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnSelectedChanged(TimeZoneInfo? tz)
|
|
|
|
|
{
|
|
|
|
|
_selected = tz;
|
|
|
|
|
await ValueChanged.InvokeAsync(tz?.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Task<IEnumerable<TimeZoneInfo>> SearchTimeZones(string? text, CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(text))
|
|
|
|
|
return Task.FromResult(AllTimeZones.Take(50));
|
|
|
|
|
|
|
|
|
|
var needle = text.Trim();
|
|
|
|
|
var matches = AllTimeZones
|
|
|
|
|
.Where(tz => tz.Id.Contains(needle, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|| tz.DisplayName.Contains(needle, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
.OrderBy(tz => tz.Id, StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
.Take(50);
|
|
|
|
|
return Task.FromResult(matches);
|
|
|
|
|
}
|
|
|
|
|
}
|