You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`Media`|`string`| the <ahref="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries"target="_blank">media query string</a> that will be matched. |
72
-
|`OnChange`|`EventCallback<bool>`| This event indicates whether the media query string provided to the `Media` parameter matches the current browser size. It fires when it matches, and when it stops matching. See the [Events]({%slug mediaquery-events%}) article for more information. |
73
-
74
-
75
-
## Reuse Multiple Breakpoints
76
-
77
-
The example below shows a few common CSS breakpoints and how you can easily extract them to a static class so you can reuse them throughout the entire application.
78
-
79
-
You can find more examples of common breakpoints from established design systems in the following links:
In this simplistic example, we just switch the background of an element, in a real case you would replace entire components or change their parameters.
121
-
122
-
>caption Use a few common media queries and breakpoints to execute sample logic in the C# side
123
-
124
-
````CSHTML
125
-
@* sample of a few common breakpoints and how you can use them. Unlike the previous example, many of these can match at the same time *@
126
-
127
-
@code{
128
-
// you can move this static class to a common place in your app to reuse across the board
129
-
// this is a sample list of a few of the most common media queries this example uses to create some sample logic
130
-
public static class WindowBreakPoints
131
-
{
132
-
public static string ExtraSmall => "(max-width: 480px)";
133
-
public static string Small => "(max-width: 767px)";
134
-
public static string Medium => "(max-width: 1023px)";
135
-
public static string Large => "(max-width: 1199px)";
136
-
public static string ExtraLarge => "(min-width: 1200px)";
NOTE: this simple logic is best suited for plain CSS
148
-
the power of the TelerkMediaQuery component is to let you employ more complex C# logic
149
-
that cannot be done with CSS alone.
150
-
The TelerikMediaQuery component is not a replacement for responsive CSS and design.
151
-
*@
152
-
153
-
<div class="@GetClassFromWindowSize()">
154
-
Resize your browser and look at the background of this element - red for large screens, yellow for medium, green for small devices.
155
-
<br />
156
-
@isExtraSmall <br />
157
-
@isSmall <br />
158
-
@isMedium <br />
159
-
@isLarge <br />
160
-
@isExtraLarge
161
-
</div>
162
-
163
-
@code{
164
-
bool isExtraSmall { get; set; }
165
-
bool isSmall { get; set; }
166
-
bool isMedium { get; set; }
167
-
bool isLarge { get; set; }
168
-
bool isExtraLarge { get; set; }
169
-
170
-
string GetClassFromWindowSize()
171
-
{
172
-
if (isExtraSmall || isSmall) return "small";
173
-
if (isMedium) return "medium";
174
-
if (isLarge || isExtraLarge) return "large";
175
-
return "";
176
-
}
177
-
}
178
-
179
-
@* sample styles for this example *@
180
-
<style>
181
-
.small {
182
-
background-color: green;
183
-
}
184
-
185
-
.medium {
186
-
background-color: yellow;
187
-
}
188
-
189
-
.large {
190
-
background-color: red;
191
-
}
192
-
</style>
193
-
````
194
72
195
73
## Notes
196
74
@@ -202,10 +80,13 @@ The MediaQuery component facilitates the usage of CSS media queries in your C# c
202
80
203
81
* You should have default values for the flags in your application that define the preferred state or layout. Depending on the browser and the media query setup, it is possible that no `OnChange` event will fire when the app initializes, so the app should have a reasonable default state.
204
82
83
+
## Next Steps
84
+
85
+
*[Explore the MediaQuery events]({%slug mediaquery-events%})
86
+
*[Integrate the MediaQuery with other Telerik Blazor components]({%slug mediaquery-integration%})
0 commit comments