-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7743b38
commit 6878d13
Showing
138 changed files
with
6,446 additions
and
5,657 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
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,19 +1,19 @@ | ||
@inject IJSInProcessRuntime JavaScript | ||
|
||
<div id="map" style="width: 100%; height: 45vh;"></div> | ||
|
||
@code { | ||
@inject IJSInProcessRuntime JavaScript | ||
|
||
<div id="map" style="width: 100%; height: 45vh;"></div> | ||
|
||
@code { | ||
[Parameter, EditorRequired] | ||
public GeolocationPosition Position { get; set; } = null!; | ||
|
||
protected override void OnParametersSet() | ||
{ | ||
if (Position is null or { Coords: null }) | ||
{ | ||
return; | ||
} | ||
|
||
JavaScript.InvokeVoid( | ||
"app.loadMap", "map", Position.Coords.Latitude, Position.Coords.Longitude); | ||
} | ||
} | ||
public GeolocationPosition Position { get; set; } = null!; | ||
|
||
protected override void OnParametersSet() | ||
{ | ||
if (Position is null or { Coords: null }) | ||
{ | ||
return; | ||
} | ||
|
||
JavaScript.InvokeVoid( | ||
"app.loadMap", "map", Position.Coords.Latitude, Position.Coords.Longitude); | ||
} | ||
} |
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,28 +1,28 @@ | ||
@typeparam T where T : class | ||
|
||
@if (Value is not null) | ||
{ | ||
<pre class="bg-dark @(_textClass) fs-4 p-4"> | ||
<code> | ||
@{ | ||
var opts = new JsonSerializerOptions() | ||
{ | ||
WriteIndented = true, | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull | ||
}; | ||
} | ||
@Value?.ToJson(opts) | ||
</code> | ||
</pre> | ||
} | ||
|
||
@code { | ||
[Parameter, EditorRequired] | ||
public T? Value { get; set; } = default!; | ||
|
||
[Parameter] | ||
public bool IsError { get; set; } | ||
|
||
string _textClass => IsError ? "text-warning" : "text-info"; | ||
} | ||
@typeparam T where T : class | ||
|
||
@if (Value is not null) | ||
{ | ||
<pre class="bg-dark @(_textClass) fs-4 p-4"> | ||
<code> | ||
@{ | ||
var opts = new JsonSerializerOptions() | ||
{ | ||
WriteIndented = true, | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull | ||
}; | ||
} | ||
@Value?.ToJson(opts) | ||
</code> | ||
</pre> | ||
} | ||
|
||
@code { | ||
[Parameter, EditorRequired] | ||
public T? Value { get; set; } = default!; | ||
|
||
[Parameter] | ||
public bool IsError { get; set; } | ||
|
||
string _textClass => IsError ? "text-warning" : "text-info"; | ||
} |
64 changes: 32 additions & 32 deletions
64
samples/Blazor.ExampleConsumer/Components/StorageCheckbox.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 |
---|---|---|
@@ -1,41 +1,41 @@ | ||
@inject ILocalStorageService LocalStorage | ||
|
||
<label class="ps-2 fs-5 selectable flex-fill" for="@Item.Id"> | ||
<input type="checkbox" class="form-check-input" | ||
value=@Item.IsCompleted | ||
checked=@Item.IsCompleted | ||
id="@Item.Id" @onchange=@OnIsCompletedChanged /> | ||
<span class="ps-3">@Item.Task</span> | ||
</label> | ||
@if (EndContent is not null) | ||
{ | ||
@EndContent | ||
} | ||
|
||
@code { | ||
@inject ILocalStorageService LocalStorage | ||
|
||
<label class="ps-2 fs-5 selectable flex-fill" for="@Item.Id"> | ||
<input type="checkbox" class="form-check-input" | ||
value=@Item.IsCompleted | ||
checked=@Item.IsCompleted | ||
id="@Item.Id" @onchange=@OnIsCompletedChanged /> | ||
<span class="ps-3">@Item.Task</span> | ||
</label> | ||
@if (EndContent is not null) | ||
{ | ||
@EndContent | ||
} | ||
|
||
@code { | ||
[Parameter, EditorRequired] | ||
public TodoItem Item { get; set; } = null!; | ||
|
||
[Parameter] | ||
[Parameter] | ||
public RenderFragment EndContent { get; set; } = null!; | ||
|
||
[Parameter] | ||
public EventCallback<TodoItem> ItemChanged { get; set; } | ||
|
||
Task OnIsCompletedChanged(ChangeEventArgs args) | ||
{ | ||
if (bool.TryParse(args?.Value?.ToString(), out var isCompleted)) | ||
{ | ||
LocalStorage.SetItem( | ||
Item.Id, | ||
Item = Item with { IsCompleted = isCompleted }); | ||
|
||
if (ItemChanged.HasDelegate) | ||
{ | ||
return ItemChanged.InvokeAsync(Item); | ||
} | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
Task OnIsCompletedChanged(ChangeEventArgs args) | ||
{ | ||
if (bool.TryParse(args?.Value?.ToString(), out var isCompleted)) | ||
{ | ||
LocalStorage.SetItem( | ||
Item.Id, | ||
Item = Item with { IsCompleted = isCompleted }); | ||
|
||
if (ItemChanged.HasDelegate) | ||
{ | ||
return ItemChanged.InvokeAsync(Item); | ||
} | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
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,8 +1,8 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
global using System.Text.Json; | ||
global using System.Text.Json.Serialization; | ||
global using Microsoft.JSInterop; | ||
global using Microsoft.AspNetCore.Components; | ||
global using static System.Globalization.CultureInfo; | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
global using System.Text.Json; | ||
global using System.Text.Json.Serialization; | ||
global using Microsoft.JSInterop; | ||
global using Microsoft.AspNetCore.Components; | ||
global using static System.Globalization.CultureInfo; |
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,20 +1,20 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text.RegularExpressions; | ||
|
||
namespace Blazor.ExampleConsumer.Models; | ||
|
||
public partial record class TodoItem( | ||
string Task, | ||
bool IsCompleted) | ||
{ | ||
internal const string IdPrefix = "todo"; | ||
|
||
[JsonIgnore] | ||
public string Id => | ||
$"{IdPrefix}{AlphabetOrDigitRegex().Replace(Task, "")}"; | ||
|
||
[GeneratedRegex("[^a-zA-Z0-9]")] | ||
private static partial Regex AlphabetOrDigitRegex(); | ||
} | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text.RegularExpressions; | ||
|
||
namespace Blazor.ExampleConsumer.Models; | ||
|
||
public partial record class TodoItem( | ||
string Task, | ||
bool IsCompleted) | ||
{ | ||
internal const string IdPrefix = "todo"; | ||
|
||
[JsonIgnore] | ||
public string Id => | ||
$"{IdPrefix}{AlphabetOrDigitRegex().Replace(Task, "")}"; | ||
|
||
[GeneratedRegex("[^a-zA-Z0-9]")] | ||
private static partial Regex AlphabetOrDigitRegex(); | ||
} |
74 changes: 37 additions & 37 deletions
74
samples/Blazor.ExampleConsumer/Pages/ClientPosition.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 |
---|---|---|
@@ -1,38 +1,38 @@ | ||
@page "/geolocation" | ||
|
||
@inject IGeolocationService Geolocation | ||
|
||
<PageTitle>Geolocation</PageTitle> | ||
<h1> | ||
Geolocation | ||
@if (_isLoading) | ||
{ | ||
<span class="spinner-border text-primary" style="border-width: .12em;" role="status"> | ||
<span class="visually-hidden">Loading...</span> | ||
</span> | ||
} | ||
@if (_position is not null) | ||
{ | ||
<span class="pe-1">: | ||
<code> | ||
@(_position.TimestampAsUtcDateTime.ToLocalTime().ToString()) | ||
</code> | ||
</span> | ||
<a href="https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly" target="_blank" | ||
rel="noopener noreferrer nofollow"> | ||
<span class="oi oi-external-link"></span> | ||
</a> | ||
} | ||
</h1> | ||
|
||
@if (_isLoading) | ||
{ | ||
<p>This page demonstrates the source generated <code>Blazor.Geolocation.WebAssembly</code> package.</p> | ||
} | ||
|
||
@{ | ||
<Code Value=@_position T=GeolocationPosition IsError=false /> | ||
<Code Value=@_positionError T=GeolocationPositionError IsError=true /> | ||
|
||
<BingMap Position=@_position /> | ||
@page "/geolocation" | ||
|
||
@inject IGeolocationService Geolocation | ||
|
||
<PageTitle>Geolocation</PageTitle> | ||
<h1> | ||
Geolocation | ||
@if (_isLoading) | ||
{ | ||
<span class="spinner-border text-primary" style="border-width: .12em;" role="status"> | ||
<span class="visually-hidden">Loading...</span> | ||
</span> | ||
} | ||
@if (_position is not null) | ||
{ | ||
<span class="pe-1">: | ||
<code> | ||
@(_position.TimestampAsUtcDateTime.ToLocalTime().ToString()) | ||
</code> | ||
</span> | ||
<a href="https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly" target="_blank" | ||
rel="noopener noreferrer nofollow"> | ||
<span class="oi oi-external-link"></span> | ||
</a> | ||
} | ||
</h1> | ||
|
||
@if (_isLoading) | ||
{ | ||
<p>This page demonstrates the source generated <code>Blazor.Geolocation.WebAssembly</code> package.</p> | ||
} | ||
|
||
@{ | ||
<Code Value=@_position T=GeolocationPosition IsError=false /> | ||
<Code Value=@_positionError T=GeolocationPositionError IsError=true /> | ||
|
||
<BingMap Position=@_position /> | ||
} |
Oops, something went wrong.