BlazorPro.BlazorSize
3.2.1
See the version list below for details.
dotnet add package BlazorPro.BlazorSize --version 3.2.1
NuGet\Install-Package BlazorPro.BlazorSize -Version 3.2.1
<PackageReference Include="BlazorPro.BlazorSize" Version="3.2.1" />
paket add BlazorPro.BlazorSize --version 3.2.1
#r "nuget: BlazorPro.BlazorSize, 3.2.1"
// Install BlazorPro.BlazorSize as a Cake Addin #addin nuget:?package=BlazorPro.BlazorSize&version=3.2.1 // Install BlazorPro.BlazorSize as a Cake Tool #tool nuget:?package=BlazorPro.BlazorSize&version=3.2.1
BlazorSize is a JavaScript interop library for Blazor that is used to detect the Browser's current size, change in size, and test media queries.
BlazorSize was designed to allow Razor Components to implement adaptive rendering. Handle mobile/desktop rendering changes at runtime with ease and complement your apps CSS media queries with programmatic work flows.
Add the NuGet package
Package Manager
Install-Package BlazorPro.BlazorSize
CLI
dotnet add package BlazorPro.BlazorSize
.csproj
<PackageReference Include="BlazorPro.BlazorSize" Version="3.*" />
Import the namespace
Add a reference to the namespace in your _Imports.razor or at the top of a page.
@using BlazorPro.BlazorSize
Add the MediaQueryList
Add a MediaQueryList to your application's main layout or root. The MediaQueryList is responsible for communicating with all MediaQuery components in your app. The MediaQueryList component will consolidate redundant media queries and manage resources so that unused event listeners are disposed of properly.
<MediaQueryList>
<div class="sidebar">
<NavMenu />
</div>
<div class="main">
<div class="top-row px-4">
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
</div>
<div class="content px-4">
@Body
</div>
</div>
</MediaQueryList>
Add a MediaQuery and bind
Using the @bind-Matches directive we can easily bind to a browser's media query and respond to it.
@if (IsSmall)
{
<WeatherCards Data="forecasts"></WeatherCards>
}
else
{
<WeatherGrid Data="forecasts"></WeatherGrid>
}
@if (IsMedium)
{
<span>Medium</span>
}
<MediaQuery Media="@Breakpoints.OnlyMedium" @bind-Matches="IsMedium" />
<MediaQuery Media="@Breakpoints.SmallDown" @bind-Matches="IsSmall" />
@code {
WeatherForecast[] forecasts;
bool IsMedium = false;
bool IsSmall = false;
protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}
}
No-Code Templates
The MediaQuery component can also use templates instead of the @bind directive. Templates are useful for swapping out UI bits when the screen size changes.
<MediaQuery Media="@Breakpoints.SmallDown">
<Matched>
<WeatherCards Data="forecasts"></WeatherCards>
</Matched>
<Unmatched>
<WeatherGrid Data="forecasts"></WeatherGrid>
</Unmatched>
</MediaQuery>
Helpers
Common media queries are already included as helpers to keep you out of the Bootstrap docs. Stay in your code longer and write cleaner statements too!
/// @media(min-width: 576px) { ... }
/// Small devices (landscape phones, 576px and up)
IsSmallUpMedia = await listener.MatchMedia(Breakpoints.SmallUp);
/// @media(min-width: 768px) { ... }
/// Medium devices (tablets, 768px and up)
IsMediumUpMedia = await listener.MatchMedia(Breakpoints.MediumUp);
// Large devices (desktops, 992px and up)
/// @media(min-width: 992px) { ... }
IsLargeUpMedia = await listener.MatchMedia(Breakpoints.LargeUp);
/// Extra large devices (large desktops, 1200px and up)
/// @media(min-width: 1200px) { ... }
IsXLargeUpMedia = await listener.MatchMedia(Breakpoints.XLargeUp);
/// Extra small devices (portrait phones, less than 576px)
/// @media(max-width: 575.98px) { ... }
IsXSmallDown = await listener.MatchMedia(Breakpoints.XSmallDown);
/// Small devices (landscape phones, less than 768px)
/// @media(max-width: 767.98px) { ... }
IsSmallDown = = await listener.MatchMedia(Breakpoints.SmallDown);
/// Medium devices (tablets, less than 992px)
/// @media(max-width: 991.98px) { ... }
IsMediumDown = = await listener.MatchMedia(Breakpoints.MediumDown);
/// Large devices (desktops, less than 1200px)
/// @media(max-width: 1199.98px) { ... }
LargeDown = = await listener.MatchMedia(Breakpoints.LargeDown);
/// Small devices (landscape phones, 576px and up)
/// @media(min-width: 576px) and(max-width: 767.98px) { ... }
IsSmallOnly = = await listener.MatchMedia(Breakpoints.OnlySmall);
/// Medium devices (tablets, 768px and up)
/// @media(min-width: 768px) and(max-width: 991.98px) { ... }
IsMediumOnly = = await listener.MatchMedia(Breakpoints.OnlyMedium);
/// Large devices (desktops, 992px and up)
/// @media(min-width: 992px) and(max-width: 1199.98px) { ... }
IsOnlyLarge = = await listener.MatchMedia(Breakpoints.OnlyLarge);
/// <summary>
/// Combines two media queries with the `and` keyword.
/// Values must include parenthesis.
/// Ex: (min-width: 992px) and (max-width: 1199.98px)
Breakpoints.Between(string min, string max)
Example:
string BetweenMediumAndLargeOnly => Breakpoints.Between(Breakpoints.MediumUp, Breakpoints.LargeDown);
// out: "(min-width: 768px) and (max-width: 1199.98px)"
IsBetweenMediumAndLargeOnly = await listener.MatchMedia(BetweenMediumAndLargeOnly);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Components (>= 3.1.1)
- Microsoft.AspNetCore.Components.Web (>= 3.1.1)
- Microsoft.Extensions.DependencyInjection (>= 3.1.6)
-
net5.0
- Microsoft.AspNetCore.Components (>= 5.0.0)
- Microsoft.AspNetCore.Components.Web (>= 5.0.0)
- Microsoft.Extensions.DependencyInjection (>= 5.0.0)
NuGet packages (10)
Showing the top 5 NuGet packages that depend on BlazorPro.BlazorSize:
Package | Downloads |
---|---|
DataJuggler.BlazorGallery
A project template for creating a Blazor Image Gallery project that uses SQL Server for a backend. You will need SQL Server or SQL Server Express to run this project. See the Read Me for more info. Watch this video to see a demo https://youtu.be/yQz1dqYiy2g. |
|
Egea.Extensions.Razor
Package Description |
|
Blazm.Components
A collection of Blazor components |
|
BlazorPro.BlazorSize.UnitTesting
A testing library to provide helper extensions for BlazorSize. |
|
Jakar.Extensions.Blazor
Extensions to aid in development. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on BlazorPro.BlazorSize:
Repository | Stars |
---|---|
telerik/blazor-ui
A collection of examples related to Telerik UI for Blazor Components: https://www.telerik.com/blazor-ui
|
Version | Downloads | Last updated |
---|---|---|
9.0.0 | 3,206 | 11/15/2024 |
8.0.0 | 96,519 | 4/22/2024 |
8.0.0-preview | 135 | 4/15/2024 |
6.2.2 | 134,074 | 8/30/2023 |
6.2.1 | 96,164 | 4/25/2023 |
6.2.0 | 46,632 | 1/6/2023 |
6.1.2 | 148,968 | 2/12/2022 |
6.1.1 | 8,263 | 1/28/2022 |
6.1.0 | 24,029 | 12/1/2021 |
6.0.0 | 34,083 | 11/10/2021 |
6.0.0-pre2 | 2,608 | 10/5/2021 |
6.0.0-pre | 272 | 8/23/2021 |
5.0.0 | 61,975 | 5/27/2021 |
5.0.0-pre | 1,141 | 5/25/2021 |
3.2.1 | 19,734 | 3/9/2021 |
3.2.0 | 2,330 | 3/5/2021 |
3.1.0 | 62,890 | 11/30/2020 |
3.0.0 | 1,789 | 11/23/2020 |
2.3.0 | 45,365 | 8/11/2020 |
2.0.2 | 22,340 | 4/21/2020 |
1.2.2 | 10,384 | 1/26/2020 |
1.2.1 | 1,130 | 1/23/2020 |
1.2.0 | 1,296 | 1/22/2020 |
3.2.1
Fixed bug where JavaScript resources were not disposed at the correct time.
Fixed an issue where JavaScript log statements were released with final build.
3.2.0
Added service interfaces, IMediaQueryService, IResizeListener to support unit testing scenarios
Added end-to-end testing on source for QA
3.1.0
Added .NET 5 module loading for BlazorSize Resize Listener.
Fixed casing on JS modules, fixes deployment issues on Linux.
3.0.0
Added .NET 5 module loading for BlazorSize Media Queries.
2.3.0
Fixed additional regressions from 2.2.0, update recommended.
2.2.0
Fixed possible regressions, update recommended.
Updated Blazor dependencies.
2.1.1
Fixed MSBuild including *.json files breaking NuGet pkg.
2.0.0
Added MediaQueryList & MediaQuery components.
1.2.2
Fixes initalization issues with Client-Side Blazor
1.2.0
Full-release